Results 1 to 3 of 3

Thread: [CLOSED] Dynamically adding a node does not work

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    32

    [CLOSED] Dynamically adding a node does not work

    Hi,

    I create a TreePanel like you can see in the code below, then right after that, I try to add a node dynamically.

    However, it doesn't work.
    Am I doing anything wrong?

    Code:
    @(Html.X().Viewport()            
                .Layout(LayoutType.Border)            
                .Items(items =>
                {
    
                    items.Add(Html.X().TreePanel()
                                .ID("MainMenu")
                                .Title("Main Menu")
                                .RootVisible(false)
                                .Root(Html.X().Node()
                                            .NodeID("Root")
                                            .Text("Root")
                                            .Children(Html.X().Node()
                                                                .NodeID("MyTasks")
                                                                .Text("My Tasks")
                                                                .Icon(Icon.Application)
                                                                .Expandable(false),
                                                        Html.X().Node()
                                                                .NodeID("PendingTasks")
                                                                .Text("Pending Tasks")
                                                                .Icon(Icon.ApplicationGo)
                                                                .Expandable(false),
                                                        Html.X().Node()
                                                                .NodeID("ClosedTasks")
                                                                .Text("Closed Tasks")
                                                                .Icon(Icon.ApplicationStop)
                                                                .Expandable(false),
                                                        Html.X().Node()
                                                                .NodeID("Search")
                                                                .Text("Search")
                                                                .Icon(Icon.Magnifier)
                                                                .Expandable(false),
                                                        Html.X().Node()
                                                                .NodeID("OpenTasks")
                                                                .Text("Open Tasks")
                                                                .Icon(Icon.ApplicationCascade)
                                            )
                                )
                    );
    
                    if (Model.IsSwitchUser)
                    {
                        Ext.Net.Node switchUserNode = new Ext.Net.Node();
                        switchUserNode.NodeID = "SwitchUser";
                        switchUserNode.Text = "Switch User";
                        switchUserNode.Leaf = true;
                        switchUserNode.Icon = Icon.Group;
    
                        X.GetCmp<TreePanel>("MainMenu").GetNodeById("Root").AppendChild(switchUserNode);
                        //also tried
                        //X.GetCmp<TreePanel>("MainMenu").GetRootNode().AppendChild(switchUserNode);
                    }
                }                                                                                                                                        
                )
    )
    Last edited by Daniil; May 27, 2013 at 10:55 AM. Reason: [CLOSED]

  2. #2
    Ext.NET - Support Team
    Join Date
    Mar 2011
    Location
    Toronto
    Posts
    2,490
    Hello!

    Try the following:

    Code:
    .Root(
    	X.Node()
    	 .Text("Composers")
    	 .Expanded(true)
    	 .Children(Html.X().Node()
    		.NodeID("MyTasks")
    		.Text("My Tasks")
    		.Icon(Icon.Application)
    		.Expandable(false),
    	Html.X().Node()
    		.NodeID("PendingTasks")
    		.Text("Pending Tasks")
    		.Icon(Icon.ApplicationGo)
    		.Expandable(false),
    	Html.X().Node()
    		.NodeID("ClosedTasks")
    		.Text("Closed Tasks")
    		.Icon(Icon.ApplicationStop)
    		.Expandable(false),
    	Html.X().Node()
    		.NodeID("Search")
    		.Text("Search")
    		.Icon(Icon.Magnifier)
    		.Expandable(false),
    	Html.X().Node()
    		.NodeID("OpenTasks")
    		.Text("Open Tasks")
    		.Icon(Icon.ApplicationCascade)
    	)
    	.Children(c => {
    		if (true)
    		{
    			c.Add(new Node()
    			{
    				NodeID = "SwitchUser",
    				Text = "Switch User",
    				Icon = Icon.Group,
    				Leaf = true
    			});
    		}
    	})
    )
    Daulet Urazalinov

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    32
    Thank you,
    you can mark this as closed.

Similar Threads

  1. [CLOSED] Raw property is null when adding a node
    By RCN in forum 2.x Premium Help
    Replies: 4
    Last Post: Jun 22, 2012, 9:50 PM
  2. Replies: 6
    Last Post: Nov 22, 2011, 3:06 PM
  3. [CLOSED] Adding node dynamicaly to treegrid on client side
    By bakardi in forum 1.x Premium Help
    Replies: 8
    Last Post: Oct 22, 2011, 6:38 AM
  4. Replies: 4
    Last Post: Dec 27, 2010, 10:48 AM
  5. [CLOSED] Problem when adding a Tree Node from Javascript
    By speedstepmem3 in forum 1.x Premium Help
    Replies: 3
    Last Post: Dec 15, 2010, 9:45 AM

Tags for this Thread

Posting Permissions