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

Getting selected Item when checkboxes is set to true

1 Answer 268 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Bshara
Top achievements
Rank 1
Bshara asked on 04 Apr 2019, 06:02 PM
Is there a way to get the selected Item in a dropdowntree when using checkboxes? the select method does not work when checkboxes are enabled. The change function returns all the values selected, and what I'm exactly looking for is to run some code on the select of the Item. Also, how can I disable children?

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 08 Apr 2019, 09:46 AM
Hello Bshara,

Normally, the select event of the DropDownTree fires when the item itself is selected. However, that will not occur if you click on the checkboxes. Please take a look at this Dojo example. You can see that if you check the Furniture checkbox, the item will be selected. Also, the inner nodes (or the children) will be disabled. That goes the other way around - if you uncheck the checkbox, the children will be enabled again.

In the Dojo example, I am getting the reference to the TreeView widget using the field of the DropDownTree. Then, I am binding a check event handler to it. Then, in the check event handler, I am able to find out if a checkbox is checked or not. If it is, I am using the enable method to disable / enable the children:
var ddt = $("#dropdowntree").getKendoDropDownTree();
var treeView = ddt.treeview;
 
treeView.bind('check', function(e) {
  var tv = e.sender;
  var dataItem = tv.dataItem(e.node);
  var innerNodes = $(e.node).find('li[role="treeitem"]');
 
  if (innerNodes.length === 0) {
    return;
  }
 
  if (dataItem.checked) {
    tv.enable(innerNodes, false);  
  } else {
    tv.enable(innerNodes, true);   
  }
});

I hope that answers your questions. Please get back to us if you have further questions

Regards,
Martin
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
DropDownTree
Asked by
Bshara
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or