2
votes

This is my code -

 var myTree = {
     containerScroll: "true",
     width: 500,
     root: new Ext.tree.AsyncTreeNode({
         id: "source",
         text: "Root",
         expanded: true,
         draggable: true,
         expandable: true
     }),
     loader: new Ext.tree.TreeLoader({
         dataUrl: 'page.php?action=Get_Tree',
         preloadChildren: true,
         expandAll: function () {}
     }),
     xtype: "treepanel",
     loadMask: {
         msg: 'Loading...'
     },
     maskDisabled: false,
     id: "tree",
     listeners: {
         click: function (node, event) {
             // Render entity data in right panel
             handleAction(node);
         }
     }
 }

when user clicks on any node of Tree, I fetch the data from DB and rendering the another panel using handleAction method. In my case, I need to show node's info in another panel and update it. On update handler, I need to change node's text/id as its updated now.

This works fine but then I need to refresh the tree so that, I can view updated node. But, it doesn't work for me :(.

This is my code for updating node -

var tree = Ext.getCmp('tree');
var id = req.responseText.split('#')[1];
var myId = 'Spec#' + entityId;
var node = tree.getNodeById(myId);
node.id = 'Spec#' + id;
node.text = updated_spec_id;
tree.enable();
tree.getLoader().dataUrl = 'page.php?todo=Get_Tree';
tree.getLoader().load(tree.root);
// This I have tried but not succeed. 
tree.getView().refresh();
tree.expandAll();
node.expand();
tree.getRootNode().expand(true);

However, when I manually expand it using mouse click, node is updated.

Please help. Thanks in advance.

1

1 Answers

0
votes

Have you tried doLayout function? Excerpt from doc:

If the Container is already rendered when add is called, you may need to call doLayout to refresh the view which causes any unrendered child Components to be rendered. This is required so that you can add multiple child components if needed while only refreshing the layout once.

It seems to me, your tree doing normal behaviour. Because, you had used click event, therefore this event fire when you click the node.