fastest way to get the checked nodes of a given node client side

3 posts, 1 answers
  1. mirang
    mirang avatar
    115 posts
    Member since:
    Aug 2010

    Posted 20 Feb 2012 Link to this post

    Is there any way to get the count of checked nodes under a given node. The reason is because, i dont want to loop through all nodes and get the checked nodes on the client side. My entire operations are based on the client 
            I was just wondering if i can use the json string in _clientState.checkedNodes to find the count? 
  2. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    1189 posts

    Posted 22 Feb 2012 Link to this post

    Hello Mirang,

    Yes, this is possible. Every node has a hierarchical index, which shows which are its parent nodes. These indexes are also stored in the _checkedIndexes property of the treeview, so you can easily use them to determine if a checked node is a child of another node.

    Here's what your function should look like:
    function getCheckedCountUnderNode(node) {
        var index = node._getHierarchicalIndex();
        var tree = node.get_treeView();
        var checkedIndexes = tree._checkedIndexes;
        var count = 0;
     
        for (var i = 0; i < checkedIndexes.length; i++) {
            if (checkedIndexes[i].startsWith(index)) {
                count++;
            }
        }
    }


    Kind regards,
    Bozhidar
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. mirang
    mirang avatar
    115 posts
    Member since:
    Aug 2010

    Posted 22 Feb 2012 Link to this post

    Thanks for your reply. I was also thinking of using the _checkedNodesJson to find the string to determine the checked nodes of a given node. Anyways, that solution looks quite faster, will try to implement the same.
    Thanks again.
Back to Top