[CLOSED] How to appendchild to leaf node from server

  1. #1

    [CLOSED] How to appendchild to leaf node from server

    Hi,
    I need to appendchild to a leaf node from code behind,
    see my example: if I click btnAppendChild1 the node is added without problem,
    but if I click btnAppendChild2 the node is not added because node "C2" is a leaf.
    Please help me
    Thank you

    Jimmy

    <%@ Page Language="C#" %>
    
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <!DOCTYPE html>
    
    
    <script runat="server">
    
    
    
    
      protected void btnAppendChild1_click(object sender, DirectEventArgs e)
      {
    
    
        Ext.Net.Node newNode = new Ext.Net.Node();
        newNode.NodeID = "Child1_1";
        newNode.Text = "Child 1_1";
        newNode.Icon = Icon.Table;
        newNode.Leaf = true;
        newNode.AllowDrop = false;
        newNode.AllowDrag = true;
    
    
        this.tree.GetNodeById("C1").AppendChild(newNode);
        
      }
    
    
      protected void btnAppendChild2_click(object sender, DirectEventArgs e)
      {
    
    
        Ext.Net.Node newNode = new Ext.Net.Node();
        newNode.NodeID = "Child2_1";
        newNode.Text = "Child 2_1";
        newNode.Icon = Icon.Table;
        newNode.Leaf = true;
        newNode.AllowDrop = false;
        newNode.AllowDrag = true;
    
    
        this.tree.GetNodeById("C2").AppendChild(newNode);
        
      }
    
    
      
      
    </script>
    
    
    <html>
    <head runat="server">
        <title>Basic TreePanel - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
    
        <ext:TreeStore ID="TreeStore1" runat="server">
            <Root>
              <ext:Node Expanded="true" Text="Root">
                  <Children>
                        <ext:Node Text="Child 1" NodeID="C1" Expanded="true">
                            <Children>
                                <ext:Node Text="Child A" Leaf="true" />
                            </Children>
                        </ext:Node>
                        <ext:Node Text="Child 2" NodeID="C2" Leaf="true" >
                        </ext:Node>
                    </Children>
                </ext:Node>
            </Root>
        </ext:TreeStore>
       
        <ext:TreePanel
          id="tree"
          runat="server"
          UseArrows="false"
          Animate="true"
          Mode="Remote"
          RootVisible="true"
          ContainerScroll="true"
          Height="300"
          Width="300"
          StoreID="TreeStore1"
          >
        
        </ext:TreePanel>
    
    
        <ext:Button ID="btnAppendChild1" runat="server" Text="Append child to child 1" >
          <DirectEvents>
            <Click OnEvent="btnAppendChild1_click" />
          </DirectEvents>
        </ext:Button>
    
    
      <ext:Button ID="btnAppendChild2" runat="server" Text="Append child to child 2" >
          <DirectEvents>
            <Click OnEvent="btnAppendChild2_click" />
          </DirectEvents>
        </ext:Button>
    
    
    </body>
    </html>
    Last edited by Daniil; Dec 04, 2014 at 10:32 AM. Reason: [CLOSED]
  2. #2
    Hi Jimmy,

    It appears .AppendChild() doesn't support appending a child to a leaf node on ExtJS level.

    Though, with a few additional actions it is possible.
    NodeProxy node = this.tree.GetNodeById("C2");
    node.AppendChild(newNode);
    node.Set("leaf", false);
    node.Set("loaded", true);
    node.Expand(false);
  3. #3
    Hi Daniil,
    it works fine.
    Thank you

    Jimmy

Similar Threads

  1. [CLOSED] How to get Leaf ID from TreePanel Node.
    By extnetuser in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 25, 2013, 4:19 PM
  2. [CLOSED] Not able to drag drop leaf to leaf in TreeGrid
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 15, 2011, 1:47 PM
  3. Tree Node leaf
    By Richardt in forum 1.x Help
    Replies: 3
    Last Post: Sep 24, 2009, 11:06 AM
  4. add node dynamic on server side
    By simbal in forum 1.x Help
    Replies: 1
    Last Post: Apr 27, 2009, 5:44 PM

Posting Permissions