The official release of Ext.NET Mobile is now available. Ext.NET Mobile is an ASP.NET component framework for building Phone and Tablet specific mobile web applications. Read More

[CLOSED] Dynamically adding a node does not work

  1. #1

    [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?

    @(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 11:55 AM. Reason: [CLOSED]
  2. #2
    Hello!

    Try the following:

    .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
    			});
    		}
    	})
    )
  3. #3
    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, 10:50 PM
  2. Replies: 6
    Last Post: Nov 22, 2011, 4: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, 7:38 AM
  4. Replies: 4
    Last Post: Dec 27, 2010, 11: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, 10:45 AM

Tags for this Thread

Posting Permissions

Subscribe now to get the latest Ext.NET happenings in our newsletter.