PDA

View Full Version : Passing initial node to TreeLoader?



Wolfgang
27 May 2007, 5:40 AM
Hello,

i would like to pass an initial value for node to a Treeloader.


var tree = new Ext.tree.TreePanel('treeMenu', {
animate:true,
loader: new Ext.tree.TreeLoader({dataUrl:'/plan/respMainMenu'}),
enableDD:true,
containerScroll: true
});


var root = new Ext.tree.AsyncTreeNode({
text: 'Start',
draggable:false,
id: 'rootNode'
});

tree.setRootNode(root);

tree.render();
root.expand();

I know i have to pass params or baseparams to the Treeloader, but i do not get an idea of how to do it.

This is only required on loading the treedata via JSON the first time.
So how can i pass params or baseparams?

tryanDLS
27 May 2007, 9:28 AM
Did you try something like

new Ext.tree.TreeLoader({dataUrl:'/plan/respMainMenu', baseParams:{foo:'bar', x:1}}),

Wolfgang
27 May 2007, 10:01 AM
Thanks. This works but sends 'foo' on every request.

I am looking for something like this, to get the request only the very first time:
So instead of adding baseParams i am looking to add a key/value pair to params.


// this does not not work
new Ext.tree.TreeLoader({dataUrl:'/plan/respMainMenu', params:{foo:'bar', x:1}})

For a grid i would use something like:


ds.load({params: {foo: 'bar'}})

but i do not know of how to access the datastore of the TreeLoader.

tryanDLS
27 May 2007, 12:48 PM
Update the baseParams property in the beforeload event handler for each call.

Radu094
28 May 2007, 2:41 AM
Actually, I was thinking of a similar thing... adding custom params directly to the tree node object and then passing those params to the server when quering for children.

ie. change the TreeLoader's getParams
to something like

getParams: function(node){
var buf = [], bp = this.baseParams;
for(var key in bp){
if(typeof bp[key] != "function"){
buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
}
}
// --- added here
if (node.customParams)
{
for(var key in node.nodeParams){
if(typeof node.nodeParams[key] != "function"){
buf.push(encodeURIComponent(key), "=", encodeURIComponent(node.nodeParams[key]), "&");
}
}

}
// --- finish add
buf.push("node=", encodeURIComponent(node.id));
return buf.join("");
},

I don't really know if there is anyother (better?) way of doing this but I found this very usefull to create complex tree panel interactions.

Maybe this can also help the OP. You can put the params you need to the root nodes' nodeParams and those will be sent to the server when quering for the first time.

Wolfgang
29 May 2007, 1:46 AM
Thanks.

I thought of something similar, but hoped there is a "builtin" way of doing this.

Maybe the ext team considers this functionallity as a useful enhancement to to Treeloader.

Wolfgang