PDA

View Full Version : Add parameter fixed in store



fabio.policeno
6 Feb 2012, 9:28 AM
Hello,

When calling the store a load of the grid (including the refresh of the grid), must always send the same parameter (p1). I tried putting in extraParams (extraParams = {p1: 1}), but the problem is that it ends up being applied to all components that have an instance of this store, used in other parts of the application. I tried the code below, but is running the first load, but if I click refresh the grid, it no longer sends the parameter. Thank you!



store.on('beforeload', me.onBeforeLoad, me);
...
onBeforeLoad: function (store, options) {
var params = {p1: 1};
Ext.apply(options.params, params);
},

friend
6 Feb 2012, 11:56 AM
This also works, on a one-off basis:



store.load({
params: {
p1: 1
}
});

fabio.policeno
6 Feb 2012, 2:20 PM
Yes friend, but as I said above, when I click "refresh" the grid, it does not send the parameter.

Thank you!

vietits
6 Feb 2012, 3:45 PM
You should set extraParams for store's proxy when you create store for your grid.



var store = Ext.create('Your Store Class', {
proxy: {
type: 'ajax',
extraParams: {
p1: .....
},
.....
}
});
var grid = Ext.create('Ext.grid.Panel', {
store: store,
....
})

Or you can set extraParams after creating store object:


Ext.apply(store.getProxy().extraParams, {p1: ...});

fabio.policeno
6 Feb 2012, 5:01 PM
Hello vietits

Thanks for the reply, actually works, but I would not choose this option, I would go with the idea of changing the params beforeload in the store, but that only works on first load, after it no longer sends the param =/. I tried the ux based filtering as it does exactly what I want, but still could not get a satisfactory result.

vietits
6 Feb 2012, 5:27 PM
Then, you set extraParams in the beforeload event handler:


store.on('beforeload', me.onBeforeLoad, me);
....
onBeforeLoad: function (store, options) {
var params = {p1: 1};
Ext.apply(store.getProxy().extraParams, params);
},

fabio.policeno
7 Feb 2012, 3:15 AM
I know this works, but the main issue is that I do not want to duplicate the proxy (creating new proxy for this store), I would work with the params of the store and not with the extraParams proxy. thus:



onBeforeLoad: function (store, options) {
var params = {p1: 1};
Ext.apply(options.params, params);
},

fabio.policeno
7 Feb 2012, 4:43 AM
I found the problem but found no way to solve it. In my grid that own this store, I use the feature "filters" (ux). So actually, the name of the parameter I am trying to send only works the first time is "filter" and therein lies the problem, if I change the name parameter to filters, works perfectly. I could not reproduce this problem on the example of api that uses this feature. Now the question. Or change the name of the parameter including the backend, or find out how to circumvent this conflict. Any ideas?

Thank you!

fabio.policeno
7 Feb 2012, 5:19 AM
Change parameter name.