Detailed explanation of angularjs table paging function_AngularJS
Continuing from the last time, this time we mainly introduce the table paging function. Due to the needs of the project, this case is about the front-end paging method. It is rarely used in this way now, but you can refer to the ideas if necessary
html:
1. Display page labels through UL, where the li of each page label is dynamically generated from different table data obtained through asynchronous loading.
<div class="pagination"> <ul style="float:right"> <li id="previous"><a href="">上一页</a></li> <li><!--用于页标的显示 --> <ul id="page_num_all"> </ul> </li> <li id="next"><a href="" style="border:1px solid #ddd;float:right">下一页</a></li> </ul> <span> 当前为第<span class="num" id="current_page"></span>页,总共<span class="num" id="page_all"></span>页 </span> </div>
js:
1. First, you need to set the number of items you want to display on each page, and determine the total number of items generated this time by selecting page elements, as well as the current page number (preparing for the jump)
2. If the total number of pages is greater than the current number of pages generated, continue to generate the next page until it is completed, and add the corner mark to the page
3. Hide all table data and only display the 5 items on the first page set at the beginning
4. Jump page function, tab_page() uses the incoming index (number of pages) * the number of displayed items to determine the starting position and ending position of the intercepted tr, and then hides all tr and only displays within this range tr(display: "");
5. Previous page, next page and jump function, get the number of the current page, pay attention to determine whether it is the first or last page, and pass it into the jump function as index
function table_page(){ var show_page=5;//每页显示的条数 var page_all=$("#page").children().size();//总条数 var current_page=1;//当前页 // console.log(page_all); var page_num=Math.ceil(page_all/show_page);//总页数 var current_num=0;//用于生成页标的计数器 var li="";//页标元素 while(page_num>current_num){//循环生成页标元素 li+='<li class="page_num"><a href="javasctip:(0)">'+(current_num+1)+'</a></li>'; current_num++; } $("#page_num_all").html(li);//添加页标到页面 $('#page tr').css('display', 'none');//设置隐藏 $('#page tr').slice(0, show_page).css('display', '');//设置显示 $("#current_page").html(" "+current_page+" ");//显示当前页 $("#page_all").html(" "+page_num+" ");//显示总页数 $("#previous").click(function(){//上一页 var new_page=parseInt($("#current_page").text())-1; if(new_page>0){ $("#current_page").html(" "+new_page+" "); tab_page(new_page); } }); $("#next").click(function(){//下一页 var new_page=parseInt($("#current_page").text())+1;//当前页标 if(new_page<=page_num){//判断是否为最后或第一页 $("#current_page").html(" "+new_page+" "); tab_page(new_page); } }); $(".page_num").click(function(){//页标跳转 var new_page=parseInt($(this).text()); tab_page(new_page); }); function tab_page(index){//切换对应页标的页面 var start=(index-1)*show_page;//开始截取的页标 var end=start+show_page;//截取个数 $('#page').children().css('display', 'none').slice(start, end).css('display', ''); current_page=index; $("#current_page").html(" "+current_page+" "); } } table_page();
The above is the front-end paging method of the table and the page number, page label and other jump methods. Please combine it with the data test in Chapter 1.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Javascript is a very unique language. It is unique in terms of the organization of the code, the programming paradigm of the code, and the object-oriented theory. The issue of whether Javascript is an object-oriented language that has been debated for a long time has obviously been There is an answer. However, even though Javascript has been dominant for twenty years, if you want to understand popular frameworks such as jQuery, Angularjs, and even React, just watch the "Black Horse Cloud Classroom JavaScript Advanced Framework Design Video Tutorial".

In today's information age, websites have become an important tool for people to obtain information and communicate. A responsive website can adapt to various devices and provide users with a high-quality experience, which has become a hot spot in modern website development. This article will introduce how to use PHP and AngularJS to build a responsive website to provide a high-quality user experience. Introduction to PHP PHP is an open source server-side programming language ideal for web development. PHP has many advantages, such as easy to learn, cross-platform, rich tool library, development efficiency

With the continuous development of the Internet, Web applications have become an important part of enterprise information construction and a necessary means of modernization work. In order to make web applications easy to develop, maintain and expand, developers need to choose a technical framework and programming language that suits their development needs. PHP and AngularJS are two very popular web development technologies. They are server-side and client-side solutions respectively. Their combined use can greatly improve the development efficiency and user experience of web applications. Advantages of PHPPHP

When using Microsoft Word for document editing, you often encounter the problem of table pagination. Especially when processing large amounts of data or complex tables, paging will affect the aesthetics and readability of the overall document. This article will share some methods to solve the problem of table pagination in Word to help you better handle the table pagination situation. 1. Merge cells In Word tables, merging cells is a common operation, which can merge multiple cells into one large cell, thereby reducing the possibility of paging. Merging cells can not only

With the rapid development of Web technology, Single Page Web Application (SinglePage Application, SPA) has become an increasingly popular Web application model. Compared with traditional multi-page web applications, the biggest advantage of SPA is that the user experience is smoother, and the computing pressure on the server is also greatly reduced. In this article, we will introduce how to build a simple SPA using Flask and AngularJS. Flask is a lightweight Py

The content of this article is about the basic introduction to AngularJS. It has certain reference value. Now I share it with you. Friends in need can refer to it.

With the popularity of web applications, the front-end framework AngularJS has become increasingly popular. AngularJS is a JavaScript framework developed by Google that helps you build web applications with dynamic web application capabilities. On the other hand, for backend programming, PHP is a very popular programming language. If you are using PHP for server-side programming, then using PHP with AngularJS will bring more dynamic effects to your website.

With the popularity of the Internet, more and more people are using the network to transfer and share files. However, due to various reasons, using traditional methods such as FTP for file management cannot meet the needs of modern users. Therefore, establishing an easy-to-use, efficient, and secure online file management platform has become a trend. The online file management platform introduced in this article is based on PHP and AngularJS. It can easily perform file upload, download, edit, delete and other operations, and provides a series of powerful functions, such as file sharing, search,
