I have 2 Kendo Treeview; 1 without checkbox, another 1 is with checkboxes like example here. Lets say I want to disable certain nodes on the second treeview, treeview with the checkboxes when I select a certain nodes on the first one (eg. I want to disable nodes that are not furniture when I select furniture). The process is kinda the same like example here but without the button, only from selecting the node on the first treeview. How do I achieve this?
TreeList has an event called select
which can handle that behaviour for you:
select: function(e) {
let tv = $("#treeview-right").data("kendoTreeView"), // Gets the 2dn treeview reference
text = e.sender.dataItem(e.node).text; // Gets the 1st treeview selected text
// Iterates over the 2nd treeview items
tv.items().toArray().forEach(item => {
let dataItem = tv.dataItem(item), // Get the item related dataItem
disabled = (dataItem.type !== text); // Figures out if the current item is of selected type
// Gets the current item's checkbox
$(item).find('input[type="checkbox"]')
.prop('checked', false) // Uncheck it by default
.prop('disabled', disabled); // Disable/enable based on above condition
});
}
Alternative: You can do like below to filter the second TreeView:
select: function(e) {
let tv = $("#treeview-right").data("kendoTreeView"),
text = e.sender.dataItem(e.node).text;
tv.dataSource.filter({ field: "type", operator: "eq", value: text });
}