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

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

2 Answers 93 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
mirang
Top achievements
Rank 1
mirang asked on 20 Feb 2012, 12:42 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 22 Feb 2012, 02:19 PM
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 >>
0
mirang
Top achievements
Rank 1
answered on 22 Feb 2012, 02:43 PM
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.
Tags
TreeView
Asked by
mirang
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
mirang
Top achievements
Rank 1
Share this question
or