How To Tell Store What Page Was Loaded
Solution 1:
To change the loaded page you should not use store.load()
. You should find a way to get the page number for the given data (e.g. asking the server via an ajax request) and then update the page via the pagingtoolbar.move(pageNumber)
. This will update your pagingtoolbar along with the grid and the store and everything remains in sync.
Solution 2:
I've found suitable solution. It's not the most elegant solution. However it works.
After digging in sencha code I've found that pagingtoolbar and store.indexOfTotal() were using record.index
(which in my case was set as if the first page was loaded). record.index
is set by store in function store.loadRecords
:
loadRecords: function(records, options) {
// ...//FIXME: this is not a good solution. Ed Spencer is totally responsible for this and should be forced to fix it immediately.for (; i < length; i++) {
if (options.start !== undefined) {
records[i].index = options.start + i;
}
// ...
},
The FIXME comment is not mine. It was in the code.
The ideal solution would be to find an event which is being fired after the response came and before the loadRecords was called and override options
in the handler. However I haven't found such event.
But you always can override loadRecords:
Ext.define('MyApp.store.MyStore', {
extend : 'Ext.data.Store',
// ...
loadRecords : function(records, options) {
if (this.proxy.reader.rawData.page) {
var page = this.proxy.reader.rawData.page;
// This is for pagingtoolbarthis.currentPage = page;
// The following is for rownumberer and correct index behaviour
options.page = page;
options.start = (page-1)*options.limit;
}
this.callParent(arguments);
},
// ...
});
Post a Comment for "How To Tell Store What Page Was Loaded"