Changing store extraParams before grid sortchange event
extjs, extjs4, extjs4.2
Solution
Use the `beforeload` event to change the extraParam object before it is sent:
listeners: {
beforeload: function(store, operation, eOpts){
if(store.sorters && store.sorters.getCount())
{
var sorter = store.sorters.getAt(0);
store.getProxy().extraParams = {
'sort' : sorter.property,
'dir' : sorter.direction
};
}
}
}
Problem
Requirement Every time grid data is sorted - before the event is executed I want to change the store `extraParams` with the values of new sort properties. Like If I am sorting a column Name in DESC direction - before the event is executed I want to overwrite `extraParams` of store with `dataIndex` of Name column and direction property DESC. My store also has `remoteSort` property set to `true`. I am using ExtJS 4.2. Problem I tried `sortchange` event listener on grid but it is executed after the data API is called and records are loaded. What I would like to have is something like beforesortchange. This all with `remoteSort : true`. Next problem is if i call `this.getStore().load();` from `sortchange` then my data api is called twice, which does not make sense. Code Grid listener: ``` sortchange: function(ct, column, direction, eOpts) { this.getStore().getProxy().extraParams = { 'sort' : column.dataIndex, 'dir' : direction } // load() will call the data api again once the data loading is over //this.getStore().load(); } ``` I tried following grid listeners also but either I dont get new grid sort parameters or they are not called at all: `beforeload`, `beforesync`, `beforeprefetch`, `load`. References https://stackoverflow.com/questions/12338407/custom-function-call-after-extjs-4-grid-sort/12338906#12338906