/**
* Paging plug-in class (lack of display number per page, listrows will be written tomorrow)
* @param page {Number} current page
* @param pagesize {Number} number of records per page
* @ param total {Number} total number of records
* @constructor
*/
function Paginate(page, pagesize, total){
if(!page || page <1){
page = 1;
}
if(!pagesize || pagesize<1){
pagesize = 20; total = total;
if(this.total%this.pagesize ===0){
this.maxpage = parseInt(this.total/this.pagesize);
}else{
this .maxpage = parseInt(this.total /this.pagesize) 1;
}
if(page>this.maxpage){
this.page = this.maxpage;
}else{
This.page = page;
}
}
/*
* The current starting number
*/
Paginate.prototype.first = function(){
var first = (this.page-1)*this.pagesize; if(first>this.total){
return (this.maxpage-1)*this.pagesize;
}
return first;
}
/*
* The maximum number of items on the current page
*/
Paginate.prototype.last = function(){
var last = this.first() this.pagesize;
if(last>this.total ){
return this.total;
}
return last;
}
/**
* Previous page
* @returns {number}
*/
Paginate.prototype.prev = function(){
if(this.page <= 1){
return false;
}
Return this.page-1;
}
/**
* Next page
* @returns {*}
*/
Paginate.prototype.next = function(){
if(this.page >= this.maxpage){
return false;
}
return (parseInt(this.page) 1);
}
module.exports = Paginate;
Usage examples