PDA

View Full Version : dynamic dataUrl



xenon
16 Sep 2010, 12:18 AM
Hi is there any way to load different dataUrl in treepanel?

Heres a panel


var tp = new Ext.tree.TreePanel({
title: 'Specialties',
width: 400,
height: 300,
userArrows: true,
animate: true,
autoScroll: true,
rootVisible: false,
dataUrl: 'json.php',
root: {
nodeType: 'async',
text: 'My Project',
id:'node-root'
}


and when clicking on button


listeners:{
click: function() {
tp.dataUrl = "json.php?foo=bar";
}
}

MrSparks
16 Sep 2010, 12:53 AM
You need to first load the json in the TreePanel and then reload the root from your "click" listener.

e.g.



var tp = new Ext.tree.TreePanel({
title: 'Specialties',
width: 400,
height: 300,
dataUrl: 'json.php?foo=bar',
userArrows: true,
animate: true,
autoScroll: true,
rootVisible: false,
dataUrl: 'json.php',
root: {
nodeType: 'async',
text: 'My Project',
id:'node-root'
}


listeners:{
click: function() {
tp.getRootNode().reload();
}
}
You can then add another listener to your TreePanel, which passes the value you need



listeners: {
beforeload: function(node){
tp.getLoader().baseParams = {
foo: Ext.getCmp('some ID/ref').getValue()
};

}

xenon
16 Sep 2010, 1:03 AM
Thanks MrSparks,

I reconstruct my code a little bit by using TreeLoader



var tl = new Ext.tree.TreeLoader({
dataUrl: 'json.php'
});

var tp= new Ext.tree.TreePanel({
title: 'Specialties',
width: 400,
height: 300,
userArrows: true,
animate: true,
autoScroll: true,
rootVisible: false,
//dataUrl: 'testjson.php',
root: {
nodeType: 'async',
text: 'My Project',
id:'node-root'
},
loader: tl


and on listeners


listeners: {
click: function() {
tp.loader = new Ext.tree.TreeLoader({dataUrl: "json.php?foo=bar"});
tp.getRootNode().reload();
}

but still i cant make the tree load on new data, any idea?

Thanks in advance

MrSparks
16 Sep 2010, 1:08 AM
Yes, I updated the post a couple of minutes ago. you will need this in your treepanel also.



listeners: {
beforeload: function(node){
tp.getLoader().baseParams = {
foo: Ext.getCmp('some ID/ref').getValue()
};

}

xenon
16 Sep 2010, 1:21 AM
Fixed, Thank you MrSparks

it worked also this way

xtype: Button


listeners: {
click: function() {
tp.getLoader().baseParams = {foo:'bar'}
tp.getRootNode().reload();
}

Thanks again!