Angularjs table paging function details, angularjs table Paging

Source: Internet
Author: User

Angularjs table paging function details, angularjs table Paging

Next, this article mainly introduces the table paging function. Because the project requires this case to be about the front-end paging method, it is rarely used now, but if necessary, you can refer to the ideas here.

Html:

1. Use UL to display the page mark. li of each page mark is dynamically generated by asynchronously loading and retrieving different table data.

<Div class = "pagination"> <ul style = "float: right "> <li id =" previous "> <a href =" "> previous page </a> </li> <! -- Used to display the Page Object --> <ul id = "page_num_all"> </ul> </li> <li id = "next"> <a href = "" style =" border: 1px solid # ddd; float: right "> next page </a> </li> </ul> <span> page <span class =" num "id =" current_page "> </span>, total <span class = "num" id = "page_all"> </span> pages </span> </div>

Js:

1. First, you need to set the number of items to be displayed on each page, and select page elements to determine the total number of items generated this time and the current page number (to prepare for the jump)

2. If the total number of pages is greater than the current number of pages generated, the next page will be generated until the badge is added to the page.

3. Hide all table data and only display 5 of the first page

4. the page Jump function. tab_page () uses the input index (page number) * to display the number of lines to determine the start and end positions of TRs, and then hides all TRS, only tr (display: "") in this range is displayed;

5. The next page of the previous page and the Redirect function are used to obtain the number of the current page. Check whether the number is the first or last page and pass it as the index to the Redirect function.

Function table_page () {var show_page = 5; // number of entries displayed per page var page_all = $ ("# page "). children (). size (); // total number of bars var current_page = 1; // current page // console. log (page_all); var page_num = Math. ceil (page_all/show_page); // total number of pages var current_num = 0; // used to generate the counter var li = ""; // while (page_num> current_num) {// cyclically generated page element li + = '<li class = "page_num"> <a href = "ctictip :( 0)">' + (current_num + 1) + '</a> </li>'; current_num ++ ;}$ ("# page_num_all" ).html (li ); // Add a page to the page $ ('# page tr'mirror.css ('display', 'None'); // set to hide $ (' # page tr '). slice (0, show_page0000.css ('display', ''); // set the display $ (" # current_page ").html (" "+ current_page + ""); // display the current page $ ("# page_all" ).html ("" + page_num + ""); // display the total number of pages $ ("# previous "). click (function () {// Previous Page var new_page = parseInt ($ ("# current_page "). text ()-1; if (new_page> 0) {$ ("# current_page" ).html ("" + new_page + ""); tab_page (new_page );}}); $ ("# next "). click (function () {// next page var new_page = parseInt ($ ("# current_page "). text () + 1; // if (new_page <= page_num) of the current page) {// determine whether it is the last or first page $ ("# current_page" ).html ("" + new_page + ""); tab_page (new_page) ;}}); $ (". page_num "). click (function () {// page Jump var new_page = parseInt ($ (this ). text (); tab_page (new_page) ;}); function tab_page (index) {// switch the page var start = (index-1) * show_page; // The page marker var end = start + show_page; // The number of screenshots ('invalid page'}.children().css ('display', 'None '). slice (start, end).css ('display', ''); current_page = index; $ (" # current_page "HTML .html (" "+ current_page + "");}} table_page ();

The above are the front-end paging method, page number, page label, and other jump methods of the table. Please test with the data in Chapter 1.

Articles you may be interested in:
  • AngularJS basic knowledge note table
  • Detailed description of table use in AngularJS
  • Use angularjs to create a simple table
  • How to Use angularjs to create a complete table

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.