Pagination formula and pagination navigation bar Summary

Source: Internet
Author: User
In actual programming, you often need to display a large amount of data by PAGE, and provide a paging navigation bar for users to choose from. A formula for regular paging is concluded, which is concise and universal. Page number = (total number of records + number of records per page-1)/number of records per page note that the division here is division. For example, if the total number of records is 10 and five records are required to be displayed on each page, the number of pages is (10 + 5-1)/5 = 2. If the total number of records is changed to 11, and 5 records are still required to be displayed on each page, the number of pages is (11 + 5-1)/5 = 3. This is in line with the actual situation. In addition, you need to provide a paging navigation bar for users to flip pages. I have observed the paging navigation bar of many websites and think that Google's paging navigation bar is the best. It provides two methods: page number and up/down flip, and the page number displayed on the navigation bar is always several numbers adjacent to the current page number. (A) the current page is page 1st (B) the current page is page 8th (c) the current page is the last page. Figure 4.5 Google's pagination navigation bar, the page number in Google's paging navigation bar shows such a rule. That is, at most 10 smaller pages are displayed on the left of the current page number, and at most 9 larger pages are displayed on the right. Then the basic idea is like this, know the current page number is N, then the left border of the navigation bar page number is temporarily set to N-10, if the N-10 <1, then adjust the left border to 1. The right border of the page number in the navigation bar is set to N + 9. If N + 9> total page number, adjust the right border to the total page number. We can verify that in Figure 4.3 (B), the current page is 8, 8-10 =-2,-2 is smaller than 1, so the left boundary is adjusted to 1. 8 + 9 = 17,17 <24 (total number of pages), so the right boundary is still 17. The specific JavaScript implementation code is as follows: function showpager (cur, max) {var beindex = cur-10; // assume that the left boundary var endindex = cur + 9; // assume that the right boundary if (beindex <1) beindex = 1; // fine-tune if (endindex> max) endindex = max; if (cur> 1) document. write ("<a href = 'board. aspx? Pageno = "+ (cur-1) +" '> previous page </a> & nbsp; "); for (I = beindex; I <= endindex; I ++) {if (I = cur) {document. write ("<strong>" + I + "<strong> & nbsp;") ;}else {document. write ("<a href = 'board. aspx? Pageno = "+ I +" '> "+ I +" </a> & nbsp; ") ;}} if (cur <max) {document. write ("<a href = 'board. aspx? Pageno = "+ (cur + 1) +" '> next page </a> ");}}

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.