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

Client side check if node has children

1 Answer 123 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Moon
Top achievements
Rank 2
Moon asked on 19 Jul 2009, 09:10 PM
In your example:

http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/contextmenu/defaultcs.aspx

On Deletion, you delete the node. I want to first check if there are any children for that node, and if so send a alert. How do I check if the selected TreeNode has children? The below treeNode.Nodes.length doesn't work. thanks!

 

case "Delete":

 

 

 

if (treeNode.Nodes.length > 0) {

 

alert(

 

"Please remove content of this directory prior to deletion.");

 

}

 

 

else {

 

 

 

var result = confirm("Are you sure you want to delete the item: " + treeNode.get_text());

 

args.set_cancel(!result);

}

 

 

break;

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jul 2009, 06:11 AM
Hi Moon,

You could use ' treeNode.get_nodes().get_count() ' in order to get the count of child nodes from client side. See the example shown below.

JavaScript:
 
<script type="text/javascript"
function onClientContextMenuItemClicking(sender, args) 
    var menuItem = args.get_menuItem(); 
    var treeNode = args.get_node(); 
    switch(menuItem.get_value()) 
    { 
         . . .  
        case "Delete"
        if (treeNode.get_nodes().get_count() > 0) 
        {                 
            alert("Please remove content of this directory prior to deletion."); 
        } 
        else 
        { 
            var result = confirm("Are you sure you want to delete the item: " + treeNode.get_text()); 
            args.set_cancel(!result); 
        } 
        break
    } 
</script> 
You can also checkout the following links which describes the most important functions of the client-side RadTreeNodeCollection object.
RadTreeNodeCollection

-Shinu.
Tags
TreeView
Asked by
Moon
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or