Treeview check all

6 posts, 2 answers
  1. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    40 posts
    Member since:
    Mar 2008

    Posted 16 Apr 2009 Link to this post

    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!
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 16 Apr 2009 Link to this post

    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.
  3. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    40 posts
    Member since:
    Mar 2008

    Posted 16 Apr 2009 Link to this post

    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?
  4. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Apr 2009 Link to this post

    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.
  5. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 16 Apr 2009 Link to this post

    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.
  6. Marc Plaxton-Harrison
    Marc Plaxton-Harrison avatar
    40 posts
    Member since:
    Mar 2008

    Posted 16 Apr 2009 Link to this post

    Hi Princy and Veselin Vasilev,

    Thanks alot for all the help, both of the queries were very successful
Back to Top