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

After clearing all selectiion with jquery a parent click does not auto select the children

3 Answers 81 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Voss
Top achievements
Rank 1
Voss asked on 11 Nov 2013, 03:44 PM
Exmaple has Parent node with a checkbox and "x" child nodes.
When selecting the parent node all children are selected.

After executing code to uncheck all checkboxes:
$('input.checkbox-strategy:checkbox').prop('checked', false);
$('input.checkbox:checkbox').prop('checked', false);

After the code above executes when clicking on the Parent the children checkboxes are not checked. After unchecking and rechecking the Parent then the child nodes are selected as expected.

Is there a better way to "uncheck" the checkboxes so it behaves as expected?

thanks.

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Nov 2013, 11:39 AM
Hello,

The treeview uses the node checked field to determine the current state so the item values should also be changed in order to avoid this behavior e.g.
$('input.checkbox-strategy:checkbox').each(function(){ 
   var item = treeview.dataItem(this);
   item.checked = false;
   this.checked = false;
});



Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Voss
Top achievements
Rank 1
answered on 13 Nov 2013, 01:43 PM
What is treeview in your example?

Is there a better way to going about clearing on checkboxes (including children) of a treeview control?
0
Daniel
Telerik team
answered on 15 Nov 2013, 09:50 AM
Hello again,

"treeview" is the TreeView widget object. The recommended approach to change the state is to use the set method to change the checked value e.g.

var treeview = $("#myTreeView").data("kendoTreeView");
$('input.checkbox-strategy:checkbox').each(function(){
   var item = treeview.dataItem(this);
   item.set("checked", false);  
});
This will also update the checkbox indeterminate state. For unchecking/checking all checkboxes however, it would be more efficient to set the value without the set method and then call the updateIndeterminate method.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Voss
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Voss
Top achievements
Rank 1
Share this question
or