PDA

View Full Version : Reset page for paginator on sort change



jgeiger
1 Sep 2011, 11:51 AM
There was an example of how to do this back in extjs2, but i can't see to get this working with 4.x and the MVC method of object creation.

There isn't really a place in my code where I create the store variable, so I was hoping to define it inside the Store itself. If someone could provide an example it would be appreciated.

Example:

store.sort = store.sort.createInterceptor(function(){
if(store.lastOptions && store.lastOptions.params){
store.lastOptions.params.start = 0;
}
});

My model:

Ext.define('RA.store.Members', { extend : 'Ext.data.Store',
requires : 'RA.model.Member',
model : 'RA.model.Member',
autoLoad : {
start : 0,
limit : 2
},
remoteSort : true,
remoteFilter : true,
pageSize : 2, // items per page
sorters : [{
property : 'last_name',
direction : 'ASC'
}]
});

skirtle
1 Sep 2011, 6:52 PM
Couldn't you just override the doSort method to reset the paging parameters? Haven't tested it but something like:


Ext.define('RA.store.Members', {
...
doSort: function() {
this.currentPage = 1;
this.callParent(arguments);
}
});

raz0r1
1 Sep 2011, 9:23 PM
i dont like overrides so may the following also works:



grid.on('sortchange', function() {
Ext.ComponentQuery.query('pagingtoolbar')[0].moveFirst();
});


maybe you have to adjust the query-string.

hope that help.

jgeiger
2 Sep 2011, 5:09 AM
This worked like I expected and it seems really simple. Thanks.

skirtle
2 Sep 2011, 6:15 AM
i dont like overrides so may the following also works:



grid.on('sortchange', function() {
Ext.ComponentQuery.query('pagingtoolbar')[0].moveFirst();
});


maybe you have to adjust the query-string.

hope that help.

I don't like using Ext.overrides() on existing classes but overriding a method in a subclass like I have here is a key part of the way Ext is designed. The alternative you've suggested may work but I can see a couple of potential problems. Firstly, it assumes the use of a grid and a paging toolbar, neither of which are strictly required. Secondly, I think it would cause the store to load twice as I'd expect the sortchange event to fire after the store has loaded the resorted results.