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

[Solved] In treeview, how to know if parent checkbox is checked from child node

1 Answer 33 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jon
Top achievements
Rank 1
Jon asked on 01 Oct 2010, 08:39 PM
Hi,

I have a question in MVC Treeview checkbox.
My tree looks like this:

root
        level 1
                level 11
                level 12
                level 13


In my program, I check the "level 11" node, and would like to know if its parent node "level 1" is check or not. I use the following logic in my code (onCheck method) but it deos not work. Please help. Thanks.

var

 

 

childrenChecked = $('#NoteTreeView > ul.t-group > li.t-item > ul.t-group > li.t-item:has(ul.t-group)').find("*:checkbox:checked").length;

 


if ($(this).parent().checked) {

   childrenChecked = childrenChecked - 1;
}


1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 04 Oct 2010, 09:30 AM
Hi Jon,

Here is how to check if the parent node is checked:

function onChecked(e) {
    var parentItem = $(e.item).parent().closest('.t-item');
    var isParentChecked = parentItem.find(':checkbox:first').is(':checked');
 
    alert(isParentChecked ? 'parent is checked!' : 'parent is not checked!');
}

Best wishes,
Alex Gyoshev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Jon
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or