Extjs 4.2.2
I have a store with an ajax proxy that I don't autoload. It's attached to a grid and the grid has a paging toolbar.
I allow the user to choose some options in a form then I call store.load( { params:{some params} } );
. I get the results back correctly from the server.
If the user uses the paging toolbar a new request is made, without the params that were used to make the previous request.
Is there a way to make the store load data as expected?
I know I could manually set the extraParams on the proxy and then call store.load()
with no params. And then when Paging Toolbar makes a request it will use those extraParams.
I have also overridden store.loadPage() to rebuild the request/params, and set the correct start size.
What's the correct way to do this? To me the expected functionality is if I've changed the query and I want the next page of those results, I should get the next page of those results. Not get the next page of some other query/result.
Example store:
Ext.create( 'Ext.data.Store',{
storeId:'some id',
model:'some model',
autoLoad:false,
proxy:{
type:'ajax',
url:'some url',
//extraParams: {sticky params},
limitParam:'rows',
pageParam:undefined,
startParam:'start'
},
loadPage:function( page, options ){
//Build the current query
var o = /*biuld params object*/;
//Update the page size
o.start = (page - 1) * this.pageSize;
if( options ){
options.params = o;
}else{
options = {
params:o
};
}
//Pass it along to the parent loadPage.
this.callParent( [page, options] );
}
});
Actually I guess I was wrong, I can't just set extraParams manually and have the paging work. They use Ext.applyif, which doesn't overwrite properties if they are already exist. So from the source
ext-all-debug.js buildRequest: function(operation) { var me = this,
params = operation.params = Ext.apply({}, operation.params, me.extraParams),
request;
Ext.applyIf(params, me.getParams(operation));
if (operation.id !== undefined && params[me.idParam] === undefined) {
params[me.idParam] = operation.id;
}
...
This gets the paging information. me.getParams(operation) And my params object has the paging information on it. So I guess what I have to do is not set the initial paging information myself, and let Ext handle it.