This is a migrated thread and some comments may be shown as answers.

Get child nodes of child in rad tree view

5 Answers 691 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Arockia J
Top achievements
Rank 1
Arockia J asked on 17 Jun 2013, 01:03 PM
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.


5 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 20 Jun 2013, 01:47 PM
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.
0
Arockia J
Top achievements
Rank 1
answered on 24 Jun 2013, 07:38 AM
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.

    }
 
     
}
0
Boyan Dimitrov
Telerik team
answered on 27 Jun 2013, 10:13 AM
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.
0
Vivek
Top achievements
Rank 1
answered on 19 Aug 2014, 08:59 PM
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
 
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2014, 12:27 PM
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.
Tags
TreeView
Asked by
Arockia J
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Arockia J
Top achievements
Rank 1
Vivek
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or