I have a Kendo TreeView where I need to programmatically reload the items via dataSource.read(), then after that, automatically expand down to and select the item that was selected before the read(). I have tried everything I can find via Google, and I just can't seem to make it work (neither the expand nor the select works).
Here's what I have so far:
var componentTreeView = $("#componentTreeView").data("kendoTreeView");var selectedNodeElement = componentTreeView.select();var selectedNode = componentTreeView.dataItem(selectedNodeElement);var id = selectedNode.id;componentTreeView.dataSource.read();// get DataSourceItem by given idvar nodeDataItem = componentTreeView.dataSource.get(id);//get node within treeview widget by uidvar node = componentTreeView.findByUid(nodeDataItem.uid);var dataItem = componentTreeView.dataItem(node);componentTreeView.expandTo(dataItem);componentTreeView.select(dataItem);
I have tried every combination I can think of of using the nodeDataItem, the node, and hte dataItem (I think nodeDataItem and dataItem are the same thing, right? But I got the code from several different examples and was just trying to be thorough).
Also, I have a feeling I need to use expandPath(), but literally every example code I could find for expandPath just provides a hard-coded list of ids (like "[1, 4, 5]" which is completely useless to me. How do I get the ids for each parent I need, in order to use expandPath? Or is that even what I need to do?
I also saw one example that did the following:
var item = $("#componentTreeView").find("li[data-id='" + id + "']").find(".k-in");// expand all parent nodes$(item).parentsUntil('.k-treeview').filter('.k-item').each( function (index, element) { $("#componentTreeView").data('kendoTreeView').expand($(this)); });
But this did not work either.
