PDA

View Full Version : Node Expansion Issue in TreePanel State Implementation



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);

JeffHowden
3 Apr 2007, 11:36 PM
I'm able to use getPath(), expandPath(), selectPath() and get the desired behavior for each. Do your IDs have a forward slash (/) in them? If so, you'll need to either change that or you'll need to choose a different pathSeparator character.

Jul
4 Apr 2007, 12:55 AM
Yes, my IDs do have forward slashes in them.

I just converted to periods instead and now it works great.

I see now that the path generated by getPath() already has forward slashes in it. I suspect using that character in the IDs for the nodes must have confused the expansion function.

Thanks for your help!

JeffHowden
4 Apr 2007, 7:25 AM
The other option would be to change the pathSeparator:


tree.pathSeparator = '>';

where "tree" is a reference to an instance of the TreePanel class.

jack.slocum
4 Apr 2007, 7:41 AM
Jeff, I think you have officially spent too much time with the tree - you know it better than I do! When I read this thread earlier I was wondering why I didn't make the separator configurable. :D