I've got an existing tree we're looking to replace w/ the Kendo TreeView. I've got most of it working, but I'm having issues w/ one particular use case.
Referring to the attached image, we load a tree view by default when the page is loaded. Then the user can choose to change the context of the tree - for example, showing items w/ various statuses, as shown in the filter button dropdown. In our current solution we remove the tree (the entire div) completely and re-create it from scratch by appending on a new, empty div and calling the tree init again.
I'm hoping we won't need to do this w/ the Kendo version, but I can't figure out how to refresh the tree while modifying the parameters passed to the datasource. I was able to get the general refresh button (bottom left) working by doing a read on the datasource, but it keeps the original parameters. We have similar functionaly tied to the dropdown above the tree (Users [by surname]), where they can change the whole tree, rather than just the parameters. For example, they could switch it to Users [by organization] or Users [by given name].
My current init for the TreeView:
function
getTree(type, status) {
var
url = page_init[type].tree_data;
//if status is passed in, append it to the url
if
(
typeof
(status) !=
'undefined'
) {
url += status;
}
//set up the tree
var
tree_datasource =
new
kendo.data.HierarchicalDataSource({
transport: {
read: {
url: url,
dataType:
"json"
}
},
schema: {
type:
"json"
,
data:
"Entries"
,
model: {
id:
"ID"
}
}
});
$(
"#nav_tree"
).kendoTreeView({
loadOnDemand:
false
,
dataSource: tree_datasource,
dataTextField:
"Text"
});
}
And the existing function calls for changing the full tree (dropdown, #tree_select) and filter (button, #tree_filter)
$(
"#tree_select"
).on(
"change"
,
function
(event) {
event.preventDefault();
getTree(
this
.value,
'active'
);
});
<
ul
id
=
"tree_filter"
class
=
"dropdown-menu dropdown-menu-filter"
>
<
li
onclick
=
"getTree($('##tree_select').val(), 'active')"
>Active</
li
>
<
li
onclick
=
"getTree($('##tree_select').val(), 'inactive')"
>Inactive</
li
>
<
li
onclick
=
"getTree($('##tree_select').val(), 'all')"
>All</
li
>
</
ul
>