Jul
3 Apr 2007, 9:09 PM
I am attempting to implement simple state functionality in a TreePanel implementation but am having trouble with re-expanding the tree after a refresh. I'm only trying to keep track of the last selected node and wish to expand the tree to that node in the event of a page refresh. The state information is saving correctly, so I think the problem may be with the TreePanel's expandPath().
I'll include my sample code below, but basically here is what I'm doing:
A) Added a click handler to the TreePanel and save the node's path in the cookie manager.
B) When the table is refreshed, it grabs the cookie and if not undefined, will expand just the rootnode of the tree. If defined, it will send the string stored in the cookie to expandPath() to make that node visible.
The call to expandPath() seems to expand the top node, but not any children. According to the docs for expandPath(), it says "A path can be retrieved from a node with Ext.data.Node.getPath" which I assume means you feed expandPath() that string and the tree should expand to that node.
Am I using expandPath() wrong?
Here is my source snippet:
var buildTree = function (){
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var tree = new Ext.tree.TreePanel('dtree', {
animate:false,
loader: new Ext.tree.TreeLoader({dataUrl:location + '&getTreeNodes'}),
enableDD:false,
containerScroll: true
});
// set the root node
var root = new Ext.tree.AsyncTreeNode({
text: 'Menu',
id:'mainmenu'
});
tree.setRootNode(root);
tree.on('click', function (x, y){Ext.state.Manager.set("treestate", x.getPath());});
tree.render();
var theState = Ext.state.Manager.get("treestate");
if (theState == undefined)
root.expand(false, false);
else
tree.expandPath(theState);
}
Ext.onReady(buildTree);
I'll include my sample code below, but basically here is what I'm doing:
A) Added a click handler to the TreePanel and save the node's path in the cookie manager.
B) When the table is refreshed, it grabs the cookie and if not undefined, will expand just the rootnode of the tree. If defined, it will send the string stored in the cookie to expandPath() to make that node visible.
The call to expandPath() seems to expand the top node, but not any children. According to the docs for expandPath(), it says "A path can be retrieved from a node with Ext.data.Node.getPath" which I assume means you feed expandPath() that string and the tree should expand to that node.
Am I using expandPath() wrong?
Here is my source snippet:
var buildTree = function (){
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var tree = new Ext.tree.TreePanel('dtree', {
animate:false,
loader: new Ext.tree.TreeLoader({dataUrl:location + '&getTreeNodes'}),
enableDD:false,
containerScroll: true
});
// set the root node
var root = new Ext.tree.AsyncTreeNode({
text: 'Menu',
id:'mainmenu'
});
tree.setRootNode(root);
tree.on('click', function (x, y){Ext.state.Manager.set("treestate", x.getPath());});
tree.render();
var theState = Ext.state.Manager.get("treestate");
if (theState == undefined)
root.expand(false, false);
else
tree.expandPath(theState);
}
Ext.onReady(buildTree);