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

How can I determine if a parent node has any 'checked' descendants

1 Answer 66 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 02 Jan 2016, 06:44 PM

I have a treeview which currently shows a hierarchy of items that are different at each level.  The TreeView is configured to use checkboxes and to check the children whenever the parent is checked.  An example (without checkboxes) of the item types is illustrated as follows:

TypeA
    TypeB
    TypeB
    TypeB
        TypeC
        TypeC
    TypeB
TypeA
    TypeB

Since the items vary by level, I want to write some javascript that retrieves the corresponding values by level.  That is, I want to retrieve the values of all checked items at level 1, or all checked items at level 2, or all checked items for level 3.  That said, I modified the code, provided by the example at: http://www.telerik.com/blogs/how-to-get-the-checked-items-from-a-treeview-with-checkboxes which recursively loops through all nodes in the treeview.  Basically, the code examines each node and evaluates the 'checked' property to determine if the node has been checked.  Unfortunately, the 'checked' property is undefined when only a subset of the descendants are checked.  It would be nice if the node had a property indicating that at least one descendant was checked.  I know that I can examine the 'hasChildren' property and recursively loop to determine if any descendant is checked, but I'm hoping that someone has a better approach.  In lieu of a simple property, what is the most efficient way to determine if a node has any 'checked' descendants? 

Thanks.

Mike

1 Answer, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 05 Jan 2016, 01:51 PM
Hello Mike,

I am afraid that there is no inbuilt method or property in order to acquire the checked items value in such specific hierarchical scenario. The proper approach is the one that you use - manually iterate trough the collection of items and acquire the checked ones.

Regards,
Nencho
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
Mike
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or