View Full Version : Change text in TreePanel nodes
4 Apr 2011, 4:53 AM
After tree is drawn I want to change the displayed node labels.
How I can do it?
It seems something simple, but I can't find a way to do it.
I've tried different options: bind() method (tried to bind and when change store node field), use ModelStringProvider and try to refresh the tree (but there is refresh method)...
4 Apr 2011, 5:20 AM
I found some way to do it, but it's very ugly
I extended TreePanel in order to make findNode(ModelData) method to be public and when I used setInnerHTML on text element. Again this is very ugly, I will be happy to get more elegant solution.
TreePanel.TreeNode n = myExtendedTreeObj.findNode(modelDataObj);
Element el = myExtendedTreeObj.getView().getTextElement(n);
29 Apr 2011, 4:28 PM
Try calling store.update(model). This will cause the label to be refreshed using the string provider if set.
10 Oct 2011, 7:25 AM
Calling store.update(model) does render the new value on the TreeNode label but it does not update the model held onto by the TreeNode , so you end up with a stale model in the TreeNode if you've made an RPC call to update the model and now you're trying to use it with the existing TreeNode. There's not even a way to update the model in the TreeNode or remove and add the TreeNode itself. This is becoming a huge limitation with the TreePanel component. If TreeNode.updateModel(M model) or something to that affect could be added, then this would solve a lot of headaches.
11 Oct 2011, 12:01 AM
I did this thing by reloading the store .. store.getLoader().load() because I had the same problem as you have. So the reloading of the data in the store did the trick ... I must specify that I did the name-changing on the server-side.
11 Oct 2011, 2:09 AM
Reloading the entire store is not an efficient way to handle this, we should be able to update the model contained by the TreeNode via an API such as TreePanel.updateTreeNode(ModelData model) or something similar.
11 Oct 2011, 2:10 AM
of course we should be able to do this .. but as we are not, we must find the best solution for our specific situation :)
17 May 2012, 1:07 AM
Try this code,it work for me, I have to collapse and expand node's ParentNode to triger render work on it:
var selRec = treePanel.getSelectionModel().getLastSelected();
if(selRec.raw != null)
selRec.raw.text = 'set text';
selRec.data["text"]= 'set text';
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.