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

Treeview check all

5 Answers 157 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Marc Plaxton-Harrison
Top achievements
Rank 1
Marc Plaxton-Harrison asked on 16 Apr 2009, 07:01 AM
Hi all, i was wondering if there is a way to make the treeview check all items when i check a certain node on the treeview eg:

i have a treeview with 60 nodes in it, the top node is called "Select All", when i click on select all i want every other node in the treeview to bo selected.

is this possible and how?

thanks in advance!

5 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 16 Apr 2009, 08:44 AM
Hello Marc Plaxton-Harrison,

One of the options is to set the CheckChildNodes property of the treeview to True.

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 16 Apr 2009, 09:53 AM
Hi Veselin Vasilev,

Thanks for the reply, the problem is that the "Select All" node aswell as the other nodes will be parent nodes eg:

Select All
Parent Node
    - Child Node
    - Child Node
Parent Node
    - Child Node

so the check all process needs to be written in client-side,

is there a way for this to happen?
0
Accepted
Princy
Top achievements
Rank 2
answered on 16 Apr 2009, 11:11 AM
Hello Marc,

I tried following client side code for achieving the functionality. Give a try with this.

[JavaScript]
 
<script type="text/javascript">  
function OnClientNodeChecked(sender, args)  
{  
    if(args.get_node().get_text()=="Select All")  
    {          
        var RootNodeCount = sender._getChildren().get_count();  
        if(args.get_node().get_checked())  
        {  
            for (i = 0; i < RootNodeCount; i++)  
            {  
                sender._getChildren().getNode(i).set_checked(true);  
            }  
        }  
        else 
        {  
            for (i = 0; i < RootNodeCount; i++)  
            {  
                sender._getChildren().getNode(i).set_checked(false);  
            }  
        }  
    }  
}  
</script> 

Thanks,
Princy.
0
Accepted
Veselin Vasilev
Telerik team
answered on 16 Apr 2009, 11:38 AM
Hello guys,

Princy, I would not recommend using private methods especially when they have a public counterpart.

Mark, as far as I understood you want to check all nodes in the tree when you check the Select All node.
Here is how you can do it:

<script type="text/javascript"
function onClientNodeChecked(sender, e) 
    var node = e.get_node(); 
    if (node.get_text() == "Check All"
    { 
        var checked = node.get_checked(); 
        $telerik.$.each(sender.get_allNodes(), function(i, nod){ 
            nod.set_checked(checked); 
        }); 
    } 
</script>  

The above code uses jQuery (integrated in RadTreeView in Q3 2008) to iterate through all nodes and set their checked state depending on the checked state of the Check All node.

Best wishes,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 16 Apr 2009, 11:57 AM
Hi Princy and Veselin Vasilev,

Thanks alot for all the help, both of the queries were very successful
Tags
TreeView
Asked by
Marc Plaxton-Harrison
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Marc Plaxton-Harrison
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or