Javascript paging Based on jquery Encapsulation

Source: Internet
Author: User

Copy codeThe Code is as follows:
(Function ($ ){
Var PageFunc = function PageFunc (){}
$. PageFunc = function (Total, PageSize, curPageNum, FunUrl ){
If (PageSize = "" | PageSize = null | PageSize = undefined ){
PageSize = 10;
}
If (curPageNum = "" | curPageNum = null | curPageNum = undefined ){
CurPageNum = 1;
}
// Calculate the total number of pages
Total = parseInt (Total); // Total number of records
PageSize = parseInt (PageSize); // number of entries displayed per page
CurPageNum = parseInt (curPageNum); // current page
// Total number of pages
Var AllPage = Math. floor (Total/PageSize );
If (Total % PageSize! = 0 ){
AllPage ++;
}

Var navHtml = "";

If (curPageNum <= 0)
CurPageNum = 1;
If (AllPage> 1 ){
If (curPageNum! = 1 ){
// Process the homepage connection
NavHtml + = "<span> <a href = \" javascript: "+ FunUrl +" ('1') \ ">|< </a> </span> ";
}
If (curPageNum> 1 ){
// Process the connection of the previous page
NavHtml + = "<span> <a href = \" javascript: "+ FunUrl +" ('"+ (curPageNum-1) + "') \ "> </a> </span> ";
}
Else {
NavHtml + = "<span class = \" disabled \ "> </span> ";
}

Var currint = 5;
For (var I = 0; I <= 10; I ++ ){
// A total of 10 page numbers can be displayed, including the first 5 and the last 5
If (curPageNum + I-currint)> = 1 & (curPageNum + I-currint) <= AllPage)
If (currint = I ){
// Process the current page
NavHtml + = "<span lass = \" current \ "> [" + curPageNum + "] </span> ";
}
Else {
// General page processing
Var n = curPageNum + I-currint;
NavHtml + = "<a href = \" javascript: "+ FunUrl +" ('"+ (parseInt (n) + "') \ ">" + n + "</a> ";
}
}
If (curPageNum <AllPage ){
// Process the next page
NavHtml + = "<span> <a href = \" javascript: "+ FunUrl +" ('"+ (parseInt (curPageNum) + 1) + "') \ ">>></a> </span> ";
}
Else {
NavHtml + = "<span class = \" disabled \ ">></span> ";
}

If (curPageNum! = AllPage ){
NavHtml + = "<span> <a href = \" javascript: "+ FunUrl +" ('"+ AllPage + "') \ ">>| </a> </span> ";
}

}

NavHtml + = "<span> [" + curPageNum + "/" + AllPage + "] </span> ";

Return navHtml;

};

}) (JQuery );

The following is the call method:
Copy codeThe Code is as follows:
Function QueryList (curpage ){
If (curpage = "" | curpage = null | curpage = undefined ){
Curpage = 1;
}
Var pagesize = 10;

Var Countys = $ ("# Countys"). val (); // County
Var enddate = $ ("# enddate"). val (); // End Time
Var begindate = $ ("# begindate"). val (); // start time
$. Ajax ({
Url :"",
Type: "POST ",
Data: {"Countys": Countys, "enddate": enddate, "begindate": begindate, "curpage": curpage, "pagesize": pagesize },
DataType: "json ",
Error: function (xhr, status, errMsg) {window. location. href = "/CommonError/index/" + errMsg. code + "? Txt = "+ errMsg. msg ;},
Success: function (mydata ){
Var str = "";
$. Each (mydata. Tdata, function (I, item ){

Str + = "<tr>"
Str + = "<td>" + $. FormatDateTime (item. ControlBeginTime, false) + "</td> ";
Str + = "<td>" + $. FormatDateTime (item. ControlEndTime, false) + "</td> ";
Str + = "<td>" + item. Name + "</td> ";
Str + = "<td>" + item. PlateNumber + "</td> ";
Str + = "<td>" + item. ControlDept + "</td> ";
If (item. IsAll = "0 "){
Str + = "<td> County Control </td> ";
}
Else {
Str + = "<td> control by bayonet points </td> ";
}
Str + = "<td>" + item. IsAll = "0 "? "County control": "control by bayonet points" + "</td> ";
Str + = "<td> modify </td> ";
Str + = "<td> Delete </td> ";
Str + = "<td> details </td> ";
Str + "</tr> ";
});

$ ("# Srh_rslt tbody" 2.16.html (str );

$ (". Pagination" ).html ($. PageFunc (mydata. total, pagesize, curpage, "QueryList "));
}
});
}

Related Article

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.