Skip to content

Instantly share code, notes, and snippets.

@jrbarron
Created January 17, 2014 10:44
Show Gist options
  • Save jrbarron/8471458 to your computer and use it in GitHub Desktop.
Save jrbarron/8471458 to your computer and use it in GitHub Desktop.
// This class and api was inspired by https://github.com/ptnplanet/backbone-pagination
function KinveyPaginator() {
return {
_paginatorConfig: {
itemsPerPage: 10
},
nextPage: function() {
this.currentPage++;
this.loadPage(this.currentPage);
},
previousPage: function() {
this.currentPage--;
this.loadPage(this.currentPage);
},
loadPage: function(page) {
this.currentPage = page;
var query = this.query || new Kinvey.Query();
var ipp = this._paginatorConfig.itemsPerPage;
query.limit(ipp);
query.skip(ipp * (page-1));
this.fetch({query: query});
}
};
}
if (window.define) {
define(function(){return KinveyPaginator();})
} else if (window.Kinvey) {
window.Kinvey.KinveyPaginator = KinveyPaginator();
} else {
window.KinveyPaginator = KinveyPaginator();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment