View Full Version : ExtJS4 Grid base params.

13 Jan 2012, 11:25 AM

I have a problem with setting baseParams for grid ajax requests.
I have a store, lets call it Tasks.
I want to create Grid, that loads tasks from serwer. But o want to include some params to every request.
I can achieve this, by setting extraParams to stores proxy.

this.store.proxy.extraParams = { mode: 'all'

But it is wrong! It adds this params to EVERY instance of Tasks store. So if i have another grid that is using Tasks store, it gets this "mode" param.
Is there any method to add baseParams to single instance of store or grid?

13 Jan 2012, 11:35 AM
Besides using extraParams, you can pass params in the params config in the load method:

params : {
foo : 'bar'

You will have to continue to pass the params in there for each request you want to have these params.

13 Jan 2012, 12:08 PM
Hmm not very comfortable solution. And how can i handle grid refresh via Paging Toolbar button?
Currently I'm using beforeload store listener and it's working ok. I just have to modify Ext.data.Operation (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Operation) instance that is passed to listener.

Similar problem is with grid url, I can set it by replacing proxy url, but again this will alter url for all store instances...
Still haven't found some more elegant solution :(

13 Jan 2012, 12:14 PM
If you are going to share instances of the store, you have to deal with it. beforeload is a great place, would be great to save the params onto the grid if you can get the grid in the beforeload event.

13 Jan 2012, 9:34 PM
Why not set the extraParams via the getProxy method?? I use the callback of the store load() method to set the params...


Ext.StoreMgr.lookup("blogTextSearch").load({//now grab the store data on search
params: {
blogSearchTxt: searchTxt,
blogSearchFID: fID,
limit: 25,
sort: "dateTime",
dir: "DESC",
trunkMore: 0
callback: function (records, operation, success) {
if (success) {
Ext.getCmp('blogViewPanel').el.mask("Basic Search: '<i>" + Ext.util.Format.ellipsis( searchTxt, 40, true) + "</i>' ", 'x-mask-loading');
//now setup the store for future reloads/pageTurns
} else {
Alert("Blog Manager", "No matches returned.");
}//end if success
scope: bWin,
add: false // force data to reload

This method works great for store refreshes.

14 Jan 2012, 6:04 AM
I guess you didn't read the post. The store is being shared so if you change the extra params all stores will use those extra params which isn't what he wants.

Also, your code can be optimized. Save your extraParams reference to a variable instead of looking it up 10 times.

14 Jan 2012, 10:47 AM
I'm not sharing one instance of store. I'm creating separate instance for each grid. But the problem is that each instance of store, shares the same instance of proxy. Example:

var one = Ext.create('Tasks');
var two = Ext.create('Tasks');

one === two // false of course
one.proxy === two.proxy //true!

So if I set new url.

one.proxy.url = '/new_url';

two.proxy.url == '/new_url' // :(

14 Jan 2012, 6:09 PM
How are you defining your stores? I wouldn't expect them to share the same proxy if you're specifying them using a proxy config.

15 Jan 2012, 4:45 AM
Store definition is very simple. I just pass model Name in config object. Proxy and reader are defined in model definition. You are saying that i should define proxy in store? But will I be able to save model instances directly?

Will this work then?

var record = Ext.create('Task');

record.name = 'new name';

record.save() // sends ajax to store url etc.

15 Jan 2012, 10:39 AM
Store definition is very simple. I just pass model Name in config object. Proxy and reader are defined in model definition. You are saying that i should define proxy in store?

No, what you're doing is fine, I was just trying to understand how it was happening. Given your explanation everything makes sense now. If the proxy is coming from the model then it will be shared. I think using a beforeload listener is the best strategy given your requirements.

15 Jan 2012, 11:45 AM
Ok, so I will try this approach. Thanks for help!