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

2 posts, 0 answers
  1. Mike
    Mike avatar
    10 posts
    Member since:
    Jan 2014

    Posted 02 Jan Link to this post

    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

  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 05 Jan Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top