How to check if node has child items

4 posts, 0 answers
  1. Rizwan Ansari
    Rizwan Ansari avatar
    26 posts
    Member since:
    Nov 2009

    Posted 09 Nov 2014 Link to this post

     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
  2. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 12 Nov 2014 Link to this post

    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.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ricardo
    Ricardo avatar
    2 posts
    Member since:
    Nov 2013

    Posted 08 Dec 2014 Link to this post

    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());
            }
        }
  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 10 Dec 2014 Link to this post

    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.

     
Back to Top