Adding children nodes to a RadTreeNodeCollection of a RadTreeNode in JavaScript

3 posts, 0 answers
  1. Justin
    Justin avatar
    3 posts
    Member since:
    May 2009

    Posted 27 Aug 2009 Link to this post

    I have to add in children nodes to a RadTreeNode in JavaScript. The Node currently doesn't have any children. We cannot post back or do an AJAX call to get the additonal data (performance isn't good enough, and besides, we have the data locally in JavaScript anyway). However, when there isn't already some children nodes in a RadTreeNode, we get a JavaScript error "get_childListElement(...) is null or undefined" when calling the following code:

    radNode.get_nodes().add(childrenNode); 

    The following conditions are true:

    1. radNode is a RadTreeNode that has been created
    2. It has been added to a RadTreeView already
    3. set_expanded(true) has already been called on it
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 28 Aug 2009 Link to this post

    Hi Justin,

    I tried the scenario and found it is working fine in my end. Here is the code that I tried.

    ASPX:
     
    <telerik:RadTreeView ID="RadTreeView1" runat="server"
        <Nodes> 
            <telerik:RadTreeNode runat="server" Text="New Node" Expanded="true">                        
            </telerik:RadTreeNode> 
        </Nodes> 
    </telerik:RadTreeView> 

    JavaScript:
     
    <script type="text/javascript"
    function addNodes() 
       var tree= $find("<%= RadTreeView1.ClientID %>");      
       tree.trackChanges(); 
       var radNode = tree.findNodeByText("New Node"); 
       var childrenNode = new Telerik.Web.UI.RadTreeNode(); 
       childrenNode.set_text("New Node1"); 
       radNode.get_nodes().add(childrenNode); 
       tree.commitChanges(); 
    </script> 
    Hope this example help you to rectify the issue that you are facing when adding nodes from client side.

    -Shinu.
  3. Justin
    Justin avatar
    3 posts
    Member since:
    May 2009

    Posted 28 Aug 2009 Link to this post

    The problem was that I was attempting to add a node that was no longer on the tree back to the tree. Creating a new node from the old node's values worked however.
Back to Top