I have a situation where I would need to update the displayed name of a treeview node after it has been updated to the database in an edit window. I would obviously like to do this without having to do a full refresh of the data. Haven't been able to find a way to do this though. What I have tried so far:
var treeView = $('#koulutuspuu').data('kendoTreeView');
// Get the data item.
var getitem = treeView.dataSource.get('Tehtävä' + $('#tehtavaID').val());
// Change the name
getitem.nimi = $("#otsikko").val();
// The above works in that the data item "nimi" (the display field) is changed, but this change is not reflected in the treeview.
/* Adding the following code will change the entire text of the tree node, throwing away the icon and also the "treeview-template" formatting */
var treeItem = treeView.findByUid(getitem.uid);
So what I would need is a refresh function on the tree (or even better on the node itself) that will cause it to redraw according to the treeview-template, and retaining the icon also. Is this possible?
6 Answers, 1 is accepted
Basically your approach to refresh the tree node looks valid. Currently the Text method of the TreeView replaces the HTML inside the k-item element with the passed string, however in the upcoming KendoUI Q3 release (expected to the end of next week) the Text method will redraw the node using the current treeview template as you expect.
the Telerik team
I'm not sure if this is also related with what you are going to solve in Q3 release. But I'm having problems with current beta release with the following code:
Basically there are three anchors:
1. push: once selected a node in the tree, it uses dataItem to get current data item and pushes one additional node into it (child node).
2. append: once selected a node in the tree, it uses append to introduce one additional node into it (child node).
3. show: shows the data item of the first element of the tree.
The question / problem is:
1. If I use append the tree is update (visually) but the dataItem is not updated.
2. If I use push then dataItem is update but not the tree.
3. If I select a node, then press append and then push, the tree is visually updated and the model too.
It seems that the first time that I introduce a child 'append' updates some internal structure and from there the tree 'observes' the observable hierarchy put if I directly push it then the tree does not observe the observable hierarchy.
Does it make any sense?
Please note that the KendoUI Q3 2012 is already released and you should upgrade to the final version where the Append method is working as expected - updating both the TreeView items and the DataSource.
the Telerik team
About the Append method,it doesn't seem to work on the dataSource.The only case the method updates the dataSource is when I append on a node that already has children!Only then I can see the new child node added in the DS.
I'm using the Q3 release and a remote Observable-Hierarchical-DataSource.
Any hints?Is this to be expected on remote datasource implementations?
I've tested it with Q3 release and I cannot make it work.
I've uploaded the code for appending nodes (http://jsfiddle.net/OnaBai/UC3uW/). Select a node in the tree and then click on append for adding a child. If you click show, you will see that I'm not getting the DataSource updated. What I am doing wrong?
I checked your code to see if you have the same problem with me and indeed you do.
If you alter you data to :
And then you try to append on node_1 then you will see the change on the dataSource.But as I mentioned above we can see the update happening ONLY if we append on a node who ALREADY had children!
If Vladimir or some other admin could tell us what's going on it would help a lot
PS:In case an Admin needs it for confirmation,here is my code too