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

How to check if node has child items

3 Answers 493 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rizwan Ansari
Top achievements
Rank 1
Rizwan Ansari asked on 09 Nov 2014, 08:57 AM
 Dear Telerik Support,

I have a radtree bind with dataset. i use context menu to delete selected node, now i want to disable the context menu item if it has child items.
so that user should delete the child items before deleting parent.

Please help

Thanks
Rizwan Ansari

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 12 Nov 2014, 08:53 AM
Hello Rizwan,

In order to verify if certain RadTreeNode has child nodes, you could use the Client API of the control and check the count of the child nodes in the following manner :

  var node1 = $find("RadTreeView1").findNodeByText("Node1");
  var childNodesCount = node1.get_nodes().get_count();
 // if childNodesCount is 0, there are no child nodes


Regards,
Nencho
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ricardo
Top achievements
Rank 1
answered on 08 Dec 2014, 07:34 AM
hi, i tried to set nodes as checked via code below. 
1) it only iterates level 0 nodes, does not iterate the child nodes
2) i tried to force set_check to false for all nodes, however the checkbox on each node is checkable
3) i executed the script OnClientLoad 

please advise?

    function UpdateNodes() {
        var tree = $find("<%= rtvCategory.ClientID %>");
        for (var i = 0; i < tree.get_nodes().get_count() ; i++) {
            var node = tree.get_nodes().getNode(i);
            node.set_checked(false);
            //if (node.get_nodes().get_count() > 0) {
            //    node.set_checked(false);
            //}
            alert(node.get_text());
        }
    }
0
Boyan Dimitrov
Telerik team
answered on 10 Dec 2014, 05:10 PM
Hello,

Straight to your questions:

    1. In order to get all nodes please use the RadTreeView client-side object method get_allNodes().
    2. You can get the check box DOM element for each node using the RadTreeNode client-side object method get_checkBoxElement(). You can disable this check box so the user will not be able to change its state.
 


Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeView
Asked by
Rizwan Ansari
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Ricardo
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or