Matt
Matt

Reputation: 26971

Reading kendoUI treeview datasource and keeping tree state

I have a Kendo treeview that is bound to a remote hierarchical datasource. The problem is that when I try to get the updated value of the by doing a $('#treeview').getKendoTreeView.dataSource.read(), while the data is successfully updated, any expanded nodes are set back to their initial state.

Is there any way to do tell the tree to keep its state? Right now I'm parsing all the node states and re-applying them programatically after the bind if they still exist. It seems like there should be a better way to do this. (i.e built in way to do this)

Upvotes: 2

Views: 729

Answers (1)

Gaugeforever
Gaugeforever

Reputation: 223

There is no way to do this. I have seen this done by having your model store whether the node is expanded or not and then resetting all the values before you leave the page.

This makes sense, as if you reload the datasource the nodes positions could have changed, for the treeview to try to match the new datasource to the old one would be unreasonable.

I do wish you luck though.

Personally, I just edit the datasource of the treeview locally so I don't have to deal with this issue. It involves a lot of hacking up the treeview, but it works.

For future readers, if you call append, insert before and insert after, this also affects the treeview datasource. Calling remove on the treeview node does not. In order to do a remove you have to do it on the treeview datasource, which will also update the treeview. It's odd they did it this way, I assume this is because they want you to be able to remove a node from the treeview and then cancel your removals or something?

Anyways, with these 4 methods you can do virtually anything you want to with the treeview locally without redrawing or reloading the datasource.

Upvotes: 1

Related Questions