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

Get count of Checked child node at Parent node in TreeView

1 Answer 815 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Prashant
Top achievements
Rank 1
Prashant asked on 27 Aug 2015, 07:27 AM

hiii,
i am using treelist and treeview both.
and i am having checkbox inside it.
i am fetching checked items database.
i have binded it correctly but not able to display count of checked node at parentnode.
i want to display the count of checked item count at parent level in treelist

parent1 (1)

--Child1(1)

------checked childchild(1)

------notchecked childchild

like this

Plz help me.

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 31 Aug 2015, 03:53 PM
Hello,

If you are loading the TreeView nodes from a database you can subscribe to the TreeView's OnClientLoad client-side event and use the following code in its handler, in order to show the number of checked child items (x):
function OnClientLoad(sender) {
    var allNodes = sender.get_allNodes()
 
    for (var i = 0; i < allNodes.length; i++) {
        var childNodes = allNodes[i].get_allNodes();
        var checkedCount = 0;
 
        for (var j = 0; j < childNodes.length; j++) {
            if (childNodes[j].get_checked()) {
                checkedCount++;
            }
        }
 
        var newText = " (" + checkedCount + ")";
        allNodes[i].set_text(allNodes[i].get_text() + newText);
    }
}


Regards,
Ivan Danchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
TreeView
Asked by
Prashant
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or