Skip to content

Instantly share code, notes, and snippets.

@brihter
Created August 7, 2013 18:49
Show Gist options
  • Save brihter/6177207 to your computer and use it in GitHub Desktop.
Save brihter/6177207 to your computer and use it in GitHub Desktop.
An ExtJS paging toolbar override that fixes the incorrect paging behaviour in an edge case. Compatible with ExtJS 4.2.1.
/**
* A paging toolbar override that fixes the incorrect paging behaviour when navigating
* to a certain page (where page no. > 1), doing a remote load of data (i.e.: filtering
* data) and size of the remote data is less than store's defined pageSize.
*
* Compatible with ExtJS 4.2.1.
*
* @class Ext.toolbar.Paging
* @override
* @author Bostjan Rihter <bostjan.rihter@gmail.com>
*/
Ext.override(Ext.toolbar.Paging, {
getPageData: function () {
var store = this.store,
totalCount = store.getTotalCount(),
currentPage = store.currentPage,
pageCount = Math.ceil(totalCount / store.pageSize),
fromRecord = ((store.currentPage - 1) * store.pageSize) + 1,
toRecord = Math.min(store.currentPage * store.pageSize, totalCount);
//#region override
if (totalCount <= store.pageSize) {
currentPage = 1;
fromRecord = 1;
}
//#endregion
return {
total: totalCount,
currentPage: currentPage,
pageCount: pageCount,
fromRecord: fromRecord,
toRecord: toRecord
};
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment