JQuery-based js paging code _ jquery

Source: Internet
Author: User
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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.