Get child nodes of child in rad tree view

6 posts, 0 answers
  1. Arockia J
    Arockia J avatar
    13 posts
    Member since:
    Mar 2010

    Posted 17 Jun 2013 Link to this post

    Dear Team,

    I have a rad tree view placed inside rad combo box. I need to retrieve the child node of the node inside the rad tree view dynamically. The rad tree view inside the rad combo box uses web services call for load on demand.

    For example, if the tree node structure inside the rad combo box is as follows:

             Node 1
                 Level 1
                      Level 2
     
            Node 2
                 Level 1
                       Level 2

    Initially, the combo box will display upon drop down Node 1 & Node 2. However, if we click Node 1 or Node 2, this will populate the child nodes.

    My requirement is that I should be able to traverse from Node 1 through the deepest level via JavaScript API so that I can compare if this is the node or level that needs to remain selected on the rad combo box.

    Kindly assist through me on achieving this.

    Thanks in advance.


  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Jun 2013 Link to this post

    Hello,

    An easy and convenient way of traversing all child nodes to a specific node would be to use RadTreeView node client-object method get_allNodes as shown in the code snippet below:
    //markup code
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientNodeClicked="ClientNodeClicked">
               ....
           </telerik:RadTreeView>

    //JavaScript

    function ClientNodeClicked(sender, args) {
        var currentNode = args.get_node();
        var allNodes = currentNode.get_allNodes();
        var allNodesCount = allNodes.length;
        for (var i = 0; i < allNodesCount; i++) {
            var node = allNodes[i];
            //here you may check what is the current node level or child nodes count
        }
     
         
    }


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Arockia J
    Arockia J avatar
    13 posts
    Member since:
    Mar 2010

    Posted 24 Jun 2013 Link to this post

    Dear Team,

    Thank you for your reply.

    We need further clarification.

    if the variable 'node' refers to Node 1 that as two children Level 1 & Level 2, then there should be method to get these levels. Let us know how to achieve this.

    Thanks in advance.

    function ClientNodeClicked(sender, args) {
        var currentNode = args.get_node();
        var allNodes = currentNode.get_allNodes();
        var allNodesCount = allNodes.length;
        for (var i = 0; i < allNodesCount; i++) {
            var node = allNodes[i];
            //here you may check what is the current node level or child nodes count
               //here we need to iterate through the children of node - for example,
               if the variable node refers to Node 1 that as two children Level 1 & Level 2, then
               there should be method to get these levels. Let us know how to achieve this.

        }
     
         
    }
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 27 Jun 2013 Link to this post

    Hello,

    I would like to clarify that get_allNodes() will return all child nodes and their child nodes and so on for a specific node. This method traverses down the hierarchy of that node to the bottom where the node does not have child items. In contrast the method .get_nodes() will return only the direct child nodes of that specific node and will not traverse down the hierarchy.

    In other words if the clicked node is "Node 1" so currentNode.get_allNodes() will return level 1 and level 2 and their children and their children and so on if any.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Vivek
    Vivek avatar
    1 posts
    Member since:
    Aug 2014

    Posted 19 Aug 2014 Link to this post

    Hi,
    In the same question if i have another Node3 where i have only one level Level1
    and now i want to display Level1 from Node3 & level2 from Node2 how to do that?
    Actually in my project i am facing a problem when i clicke on Level1 of Node3 where it has only one child it is not displaying Level1 it displays Node3 which is parent node.While in Node1 & Node2 it's working fine because they have more then one child.
    i hope i am clear  to ask my doubt.
    Thanks
     
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Aug 2014 in reply to Vivek Link to this post

    Hi Vivek,

    Such an issue is not expected and the provided information is not enough to replicate the issue. Please have a look into this online demo and try to replicate the issue there or provide a sample code snippet for further help.

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017