Jquery's paging code is implemented in combination with the database. Here, only the core jquery code is provided. Other people can make use of it.
The Code is as follows:
Function pagerBar (dataCount, pageSize, serverUrl, contentPlace, pagerbarPlace, callBack ){
This. dataCount = dataCount;
This. pageSize = pageSize;
This. serverUrl = serverUrl;
This. contentPlace = $ ("#" + contentPlace );
This. pagerbarPlace = $ ("#" + pagerbarPlace );
This. callBack = callBack;
This. pageCount = 0;
This. pageIndex = 1;
This. curInfo = $ ("");
This. prePage = $ ("");
This. nextPage = $ ("");
This. init ();
}
PagerBar. prototype = {
Init: function (){
This. getPageCount ();
This. initLink ();
This. showBarInfo ();
If (this. pageCount> 0 ){
This. setLink (1 );
}
},
GetPageCount: function (){
This. pageCount = parseInt (this. dataCount/this. pageSize );
If (this. dataCount % this. pageSize! = 0 ){
This. pageCount ++;
}
},
InitLink: function (){
Var self = this;
This. prePage = $ (").html (" Previous Page "). addClass (" pageLink ");
This. prePage. click (function (){
Self. setLink (self. pageIndex-1 );
});
This. nextPage = $ ("" ).html ("next page"). addClass ("pageLink ");
This. nextPage. click (function (){
Self. setLink (self. pageIndex + 1 );
});
This. pagerbarPlace. append (this. curInfo). append (this. prePage). append (this. nextPage );
},
ShowBarInfo: function (){
This. prePage. hide ();
This. nextPage. hide ();
If (this. pageCount = 0 ){
This.curInfo.html ("No information! ");
}
Else if (this. pageCount = 1 ){
This.curInfo.html ("1/1 ");
}
Else {
This.curInfo.html (this. pageCount + "/" + this. pageIndex );
}
},
SetLink: function (I ){
Var self = this;
$. Ajax ({
Url: self. serverUrl,
Type: "get ",
Data: {pageSize: self. pageSize, pageIndex: I },
Cache: false,
Error: function (){
Alert ("data loading failed! ");
},
Success: function (htmlData ){
Self.contentPlace.html (htmlData );
If (self. pageCount = 1 ){
Self. prePage. hide ();
Self. nextPage. hide ();
} Else {
If (I = 1 ){
Self. prePage. hide ();
Self. nextPage. show ();
} Else if (I = self. pageCount ){
Self. prePage. show ();
Self. nextPage. hide ();
} Else {
Self. prePage. show ();
Self. nextPage. show ();
}
}
Self. pageIndex = I;
Self.curInfo.html (self. pageCount + "/" + self. pageIndex );
If (self. callBack ){
Self. callBack ();
}
}
});
},
ChangeServerUrl: function (dataCount, serverUrl ){
This. dataCount = dataCount;
This. serverUrl = serverUrl;
This. pageIndex = 1;
This. getPageCount ();
This. showBarInfo ();
This.contentPlace.html ("");
If (this. pageCount> 0 ){
This. setLink (1 );
}
},
DataCountDec: function (){
This. dataCount --;
This. getPageCount ();
If (this. pageCount This. pageIndex = this. pageCount;
}
If (this. pageIndex> 0 ){
This. setLink (this. pageIndex );
}
This. showBarInfo ();
}
}