PDA

View Full Version : Remember tree path and expand as before after reload



vayumahesh
11 Sep 2008, 12:30 PM
I have a Tree Panel (loaded from Json data from server) and a Form Panel. When I click a node on the tree, form is loaded and after submission, I would like to reload the tree and preserve the state of the tree to before reload (like keep nodes expanded/collapsed).

Reload is working fine with the following statement.
caTreePanel.root.reload();

After searching the forums, I came to know getPath() and expandPath() functions will do the trick of reloading the tree to the previous sate. But looks like there is more involved.

I tried the following code but am getting errors.

var treeCurPath = caTreePanel.root.getPath(); //only gets root path
caTreePanel.root.reload();
caTreePanel.root.expandPath(treeCurPath); //error

vayumahesh
11 Sep 2008, 12:49 PM
I figured it out. In the listener for tree panel, I used getPath() function to store the path into a variable and then expanded the tree panel with the expandPath function by supplying the stored path.

var curNodePath = '';

var caTreePanel = new caTree.TreePanel({
... tree definition ...
});

caTreePanel.addListener('click', function (node, event){
curNodePath=node.getPath();
});

//here is how to reload the tree with saved path
caTreePanel.root.reload();
caTreePanel.expandPath(curNodePath);

For my case, I just need to expand the tree to the node user has last clicked on. Hope it helps someone out there.

ExtJs rocks.