PDA

View Full Version : ListPaging for Local data Sqlite or Data array



GopiVeda
16 Oct 2016, 6:28 AM
ListPaging plugin is extended to work with local data like SQLite or data array. The "nextPageCallback" is the main callback config in the extended plugin has to be implemented. This function will be called in loadpage of list's store. This function has three params,
1. pageSize - which is defined it the store
2. Page - the pages record that has to be returned
3. callback2 (data, totalCount) data: the data returned for that page and totalCount: Total records to be paged.

The nextPageCallback has to implement the following query in SQLite (in case of SQLite)
1. To fetch the records for the requested page
2. fetch the totalcount of records for the same criteria.

The demo is available in this fiddle https://fiddle.sencha.com/#fiddle/1ik9


Ext.define('Ext.ux.plugin.ListPagingLocal', {
extend: 'Ext.plugin.ListPaging',
alias: 'plugin.listpaginglocal',
config:{
nextPageCallback:null
},
bindStore:function(newStore, oldStore){
this.callParent(arguments);
var me = this,
store = this.getList().getStore(),
total = store.getTotalCount();
if (newStore){
newStore.loadPage = function(page, options, scope) {
var callback = me.getNextPageCallback(),
pageSize = store.getPageSize();
debugger;
if (callback){
callback(pageSize,page,
function(data,totalCount,sorter){ //callback2
if (!page || page<=1){
store.removeAll();
if (sorter){
store.setSorters([sorter]);
}else{
store.setSorters([]);
}
}
store.setTotalCount(totalCount);
store.currentPage = page;
store.addData(data);
store.fireEvent('load', store);
}
);
}
}
}
}
});

Gary Schlosberg
17 Oct 2016, 8:33 AM
Nice job. Thanks for sharing your work with the community!