PDA

View Full Version : EditorGridPanel and HttpProxy: How to change the proxy URL dynamically ?



Snoop74
11 Sep 2010, 4:23 AM
var OrderPositionsGridStore = new Ext.data.GroupingStore({
id: 'OrderPositionsGridStore',
reader: new Ext.data.JsonReader({
idProperty: 'OrderPositionsGridStoreReader',
fields: [
{name: 'ID'},
{name: 'name'},
],
root: 'data',
remoteGroup: true,
remoteSort: true
}),
proxy : new Ext.data.HttpProxy({
url: 'order.php?action=getOrderPosition&OrderID=1',
method: 'POST'
}),
sortInfo: {field: 'name', direction: 'ASC'},
groupField: 'name'
});

var OrderPositionsGrid = new Ext.grid.EditorGridPanel({
border: false,
ds: OrderPositionsGridStore,
columns: [ ... ]
[.. more settings ..]
});
How can i change the GroupingStore-URL dynamically on runtime ?
(the OrderID should be taken from a javascript var)

I tried several ways now - the script is executing the right URL - but the results (received data from the script) were not shown in the grid.

Some ideas ?

vishalnnsingh
11 Sep 2010, 4:55 AM
var id = id //gra. ur id here
grid.store.proxy. conn.url = 'ur url?orderId=' + id;

Snoop74
11 Sep 2010, 5:12 AM
Thank your for your answer - but: no, it is not working.

I also tried out

var ST = OrderPositionsGridStore;
ST.proxy.setUrl('url.php?param=1', true); Also without success.

vishalnnsingh
11 Sep 2010, 5:39 AM
hope u r reloading the store after setting the url.
grid.store.reload() or urstorename.reload().

Animal
11 Sep 2010, 6:21 AM
You're not changing the URL, you're changing PARAMETERS.

Use a beforeload event listener

Snoop74
11 Sep 2010, 6:48 AM
Now i use

OrderPositionsGridStore.on({
beforeload: {
fn: function (store, options) {
// use {@link Ext.data.HttpProxy#setUrl setUrl} to change the URL for *just* this request.
var link = 'order.php?action=getOrderPositions&OrderID=' + CurrentOrderID;
store.proxy.setUrl(link, true);
alert(link);
}
}
});

The alert-Message displays me the correct link. Everything seems fine.
But now the retrieved data are being displayed in the Ext.grid.EditorGridPanel.

Argh !

What am i doing wrong ??

Snoop74
11 Sep 2010, 6:51 AM
Thank you animal (one more time) :o)

With the beforelistener event it is working now.
Ticket can be closed.

vishalnnsingh
11 Sep 2010, 7:31 AM
thanx animal.... and snoop

Animal
11 Sep 2010, 7:36 AM
So you are actually setting the params in the options, then, not messing with a URL?

Condor
11 Sep 2010, 7:50 AM
So what you actually want is:

var store = new Ext.data.Store({
url: 'order.php',
method: 'GET',
baseParams: {
action: 'getOrderPositions'
},
reader: ...
});
...
store.load({
params: {
OrderID: CurrentOrderID
}
});