The JS paging control can be used for refreshing new pages.

Source: Internet
Author: User

JS paging control, which can be used for refreshing new pages

Copy codeThe Code is as follows:
Function PagerBar (recordcount, pagesize, pageindex, showpagecount ){
Var NumberRegex = new RegExp (/^ \ d + $ /);
This. PageIndex = 1; // page index, current page
If (pageindex! = Null & NumberRegex. test (pageindex) this. PageIndex = parseInt (pageindex );
This. PageSize = 10; // page size
If (pagesize! = Null & NumberRegex. test (pagesize) this. PageSize = parseInt (pagesize );
This. RecordCount = 0;
If (recordcount! = Null & NumberRegex. test (recordcount) this. RecordCount = parseInt (recordcount); // The total number of records
This. PageCount = 0; // total number of pages
Var PagerBar = this;
Function CalculatePageCount (_ pagesize, _ recordcount) {// calculate the total number of pages
If (_ pagesize! = Null & NumberRegex. test (_ pagesize) PagerBar. PageSize = parseInt (_ pagesize );
If (_ recordcount! = Null & NumberRegex. test (_ recordcount) PagerBar. RecordCount = parseInt (_ recordcount );
Else PagerBar. RecordCount = 0;
If (PagerBar. RecordCount % PagerBar. PageSize = 0) {// calculate the total number of pages
PagerBar. PageCount = parseInt (PagerBar. RecordCount/PagerBar. PageSize );
}
Else {
PagerBar. PageCount = parseInt (PagerBar. RecordCount/PagerBar. PageSize) + 1;
}
}
If (this. RecordCount! = 0) {// if the total number of records is input, the total number of pages is calculated.
CalculatePageCount (this. PageSize, this. RecordCount );
}
This. ReplaceString = "# PageLink"; // Replace the page number of text. Note: Symbols in regular expressions are not allowed.
This. ShowPagesCount = 5; // Number of displayed pages
If (showpagecount! = Null & NumberRegex. test (showpagecount. toString () this. ShowPagesCount = parseInt (showpagecount );
This. previubarformat = ""; // text format displayed on the previous page
This. IsShowPreviouString = true; // whether the previous page is displayed
This. NextBarFormat = ""; // text format displayed on the next page
This. IsShowNextString = true; // whether to display the next page
This. PageBarFormat = ""; // display text format of page connections
This. CurrentBarFormat = ""; // text format displayed on the current page
This. IsShowPageString = true; // whether to display the page index
This. FristBarFormat = ""; // text format displayed on the homepage Link
This. IsShowFristString = true; // whether to display the homepage
This. LastBarFormat = ""; // text format displayed on the last page
This. IsShowLastString = true; // whether the last page is displayed
This. CurrentRecordBarFormat = "current record {0}-{1}"; // text format of the current record
This. IsShowCurrentRecordString = true; // whether the current record is displayed
This. CurrentPageBarFormat = "current number" + this. ReplaceString + "Page, total" + (this. PageCount = 0? 1: this. PageCount) + "page"; // text description text format on the current page
This. IsShowCurrentPageString = true; // whether the text description of the current page is displayed
This. OtherBarFormat = ""; // others also display text
This. IsShowOtherString = true; // whether other page text is displayed
Var regexp = new RegExp (this. ReplaceString, "g"); // Replace the regular expression of the number of pages.
Function GetFristPageString () {// get the homepage text
If (PagerBar. FristBarFormat! = "" & PagerBar. PageIndex! = 1 ){
Return PagerBar. FristBarFormat. replace (regexp, 1 );
}
Else {
Return "";
}
}
Function getpreviupagestring () {// obtain the text of the previous page
If (PagerBar. previubarformat! = ""){
If (PagerBar. RecordCount> PagerBar. PageSize & PagerBar. PageIndex! = 1) {// HTML output of the previous page
Return PagerBar. previubarformat. replace (regexp, PagerBar. PageIndex-1 );
}
Else {
Return "";
}
}
Else {
Return "";
}
}
Function GetPageString () {// gets the link to the intermediate page number
Var pagestr = "";
If (PagerBar. CurrentBarFormat! = "" & PagerBar. PageBarFormat! = ""){
Var ShowPageFirest = PagerBar. PageIndex-parseInt (PagerBar. ShowPagesCount/2 + 1) <0? 0: PagerBar. PageIndex-parseInt (PagerBar. ShowPagesCount/2 + 1); // calculate the actual number of pages displayed
If (PagerBar. PageCount <PagerBar. ShowPagesCount) {// The total number of displayed pages is smaller
ShowPageFirest = 0;
}
Else {
If (PagerBar. PageIndex> (PagerBar. PageCount-parseInt (PagerBar. ShowPagesCount/2 + 1) {// when the total number of pages is displayed on the last few pages
ShowPageFirest = PagerBar. PageCount-PagerBar. ShowPagesCount;
}
}
For (var I = ShowPageFirest; I <ShowPageFirest + PagerBar. ShowPagesCount; I ++) {// print the number of pages in a loop
If (PagerBar. PageIndex = I + 1 ){
Pagestr + = PagerBar. CurrentBarFormat. replace (regexp, I + 1 );
}
Else {
Pagestr + = PagerBar. PageBarFormat. replace (regexp, I + 1 );
}
If (I> = PagerBar. PageCount-1) {// pick out the loop when the total number of pages reaches
Break;
}
}
}
Return pagestr;
}
Function GetNextPageString () {// gets the next page Link
If (PagerBar. NextBarFormat! = ""){
If (PagerBar. RecordCount> PagerBar. PageSize & PagerBar. PageIndex! = PagerBar. PageCount) {// output the next HTMl page
Return PagerBar. NextBarFormat. replace (regexp, PagerBar. PageIndex + 1 );
}
Else {
Return "";
}
}
Else {
Return "";
}
}
Function GetLastPageString () {// get the link to the last page
If (PagerBar. LastBarFormat! = "" & PagerBar. PageIndex! = PagerBar. PageCount & PagerBar. RecordCount! = 0 ){
Return PagerBar. LastBarFormat. replace (regexp, PagerBar. PageCount );
}
Else {
Return "";
}
}

Function GetFrontOtherPageString () {// obtain the previous link to another page
If (PagerBar. OtherBarFormat! = ""){
If (PagerBar. PageIndex> PagerBar. ShowPagesCount/2 + 1 ){
Return PagerBar. OtherBarFormat. replace (regexp, PagerBar. PageIndex-PagerBar. ShowPagesCount <= 0? 1: PagerBar. PageIndex-PagerBar. ShowPagesCount)
}
Else {
Return "";
}
}
Else {
Return "";
}
}
Function GetAfterOtherPageString () {// other page links after Retrieval
If (PagerBar. OtherBarFormat! = ""){
If (PagerBar. PageIndex <= PagerBar. PageCount-PagerBar. ShowPagesCount/2 ){
Return PagerBar. OtherBarFormat. replace (regexp,
PagerBar. PageIndex + PagerBar. ShowPagesCount> = PagerBar. PageCount? PagerBar. PageCount: PagerBar. PageIndex + PagerBar. ShowPagesCount );
}
Else {
Return "";
}
}
Else {
Return "";
}
}
Function GetCurrentRecordPageString () {// get the current record text
If (PagerBar. CurrentRecordBarFormat! = ""){
If (PagerBar. RecordCount = 0 ){
Return "";
}
Else {
Return PagerBar. currentRecordBarFormat. replace ("{0}", (PagerBar. pageIndex-1) * PagerBar. pageSize + 1 ). replace ("{1}", PagerBar. pageIndex * PagerBar. pageSize> PagerBar. recordCount? PagerBar. RecordCount: PagerBar. PageIndex * PagerBar. PageSize );
}
}
Else return "";
}
Function GetCurrentPageBarString () {// get the current page record text
If (PagerBar. CurrentPageBarFormat! = ""){
Return PagerBar. CurrentPageBarFormat. replace (regexp, PagerBar. PageIndex );
}
Else return "";
}
This. GetString = function (pageindex) {// output HTML code (all Mode)
If (pageindex! = Null & NumberRegex. test (pageindex) {// If a page index is input, the value is assigned.
This. PageIndex = parseInt (pageindex );
}
If (this. PageCount = 0) {// if the total number of pages is not calculated, the total number of pages is calculated.
CalculatePageCount (this. PageSize, this. RecordCount );
}
Var pagestr = "";
If (this. IsShowCurrentPageString ){
Pagestr = GetCurrentPageBarString ();
}
If (this. IsShowCurrentRecordString ){
Pagestr + = GetCurrentRecordPageString ();
}
If (this. IsShowFristString ){
Pagestr + = GetFristPageString ();
}
If (this. IsShowPreviouString ){
Pagestr + = getpreviupagestring ();
}
If (this. IsShowOtherString ){
Pagestr + = GetFrontOtherPageString ();
}
If (this. IsShowPageString ){
Pagestr + = GetPageString ();
}
If (this. IsShowOtherString ){
Pagestr + = GetAfterOtherPageString ();
}
If (this. IsShowNextString ){
Pagestr + = GetNextPageString ();
}
If (this. IsShowLastString ){
Pagestr + = GetLastPageString ();
}
Return pagestr;
}
This. GetNormalString = function (pageindex ){
If (pageindex! = Null & NumberRegex. test (pageindex) {// If a page index is input, the value is assigned.
This. PageIndex = parseInt (pageindex );
}
If (this. PageCount = 0) {// if the total number of pages is not calculated, the total number of pages is calculated.
CalculatePageCount (this. PageSize, this. RecordCount );
}
Var pagestr = "";
Pagestr + = GetFristPageString ();
Pagestr + = getpreviupagestring ();
Pagestr + = GetPageString ();
Pagestr + = GetNextPageString ();
Pagestr + = GetLastPageString ();
Return pagestr;
}
This. GetSimpleString = function (pageindex ){
If (pageindex! = Null & NumberRegex. test (pageindex) {// If a page index is input, the value is assigned.
This. PageIndex = parseInt (pageindex );
}
If (this. PageCount = 0) {// if the total number of pages is not calculated, the total number of pages is calculated.
CalculatePageCount (this. PageSize, this. RecordCount );
}
Var pagestr = "";
Pagestr + = getpreviupagestring ();
Pagestr + = GetCurrentPageBarString ();
Pagestr + = GetNextPageString ();
Return pagestr;
}
}

Example:

None

Knowledge points required in the content
Pagination character # PageLink

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.