AngularJS front-end paging implementation
This article mainly introduces the AngularJS front-end paging implementation, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
Pagination ideas
Assessor query , because the overall data volume is relatively small, we can put paging in the foreground for processing.
In fact, the principle of paging is also very simple. We determine the number of items in the array currently displayed based on the number of pages selected for paging and the number of data items on each page, and then construct the paging parameters and pass them in Existing paging instructions.
// 初始化分页参数 $scope.pageParams = { size: $stateParams.size, // 每页数据条数 page: $stateParams.page, // 页码数 last: undefined, // 是否首页 first: undefined, // 是否尾页 totalPages: undefined, // 总页数 totalElements: undefined, // 总数据条数 numberOfElements: undefined // 当前页有几条数据 };
This is the data required by our paging instruction, so we have two tasks. First, intercept the data that should be displayed on the current page, and second, generate parameters and pass them to the paging instruction.
Public method
This is the last public method implemented in CommonService
.
/** * 重新生成分页参数与分页数据 * @param {每页数据条数} size * @param {页码数} page * @param {全部数据} data * @param {Function} callback * callback (pageParams, currentPageData) * pageParams: 分页的标准 * currentPageData: 当前页的数据 */ self.reloadPageParamsAndData = function(size, page, data, callback) { // 校验传入的参数 if (typeof size === 'undefined') { throw '未接收到每页数据条数信息'; } if (typeof page === 'undefined') { throw '未接收到分页信息'; } if (typeof data === 'undefined') { throw '未接收到数据信息'; } // 计算总页数和总数据条数 var totalPages = Math.ceil(data.length / size); var totalElements = data.length; // 计算当前页是否为首页 是否为尾页 var first = page === 0 ? true : false; var last = page === totalPages - 1 ? true : false; // 根据分页参数计算当前页应该显示的数据 slice数组元素分割 var currentPageData = data.slice(0 + page * size, size + page * size); // 获取当前页总共有多少条数据 var numberOfElements = currentPageData.length; // 重新生成分页参数 var pageParams = { size: size, // 每页数据条数 page: page, // 页码数 last: last, // 是否首页 first: first, // 是否尾页 totalPages: totalPages, // 总页数 totalElements: totalElements, // 总数据条数 numberOfElements: numberOfElements // 当前页有几条数据 }; // 回调 if (callback) { callback(pageParams, currentPageData); } };
Get the data of the current page
To get the data of the current page, we need to know the number of data items on each page and the page number to split the data.
var currentPageData = data.slice(0 + page * size, size + page * size);
Split the data. The data should be from 0
to size
, plus page * size
is the number of previous pages. The amount of data.
Construct paging parameters
// 计算总页数和总数据条数 var totalPages = Math.ceil(data.length / size); var totalElements = data.length; // 计算当前页是否为首页 是否为尾页 var first = page === 0 ? true : false; var last = page === totalPages - 1 ? true : false; // 获取当前页总共有多少条数据 var numberOfElements = currentPageData.length;
The total number of data is divided by the number of data items per page and rounded up to get the total number of pages.
If the number of pages is 0
, it is the first page; if the number of pages is the total number of pages minus 1
, it is the last page.
<yunzhi-page></yunzhi-page>
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
AngularJS export Excel command
AngularJS document reading command scope
The above is the detailed content of AngularJS front-end paging implementation. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

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



How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

Introduction to how to use JavaScript and WebSocket to implement a real-time online ordering system: With the popularity of the Internet and the advancement of technology, more and more restaurants have begun to provide online ordering services. In order to implement a real-time online ordering system, we can use JavaScript and WebSocket technology. WebSocket is a full-duplex communication protocol based on the TCP protocol, which can realize real-time two-way communication between the client and the server. In the real-time online ordering system, when the user selects dishes and places an order

How to use WebSocket and JavaScript to implement an online reservation system. In today's digital era, more and more businesses and services need to provide online reservation functions. It is crucial to implement an efficient and real-time online reservation system. This article will introduce how to use WebSocket and JavaScript to implement an online reservation system, and provide specific code examples. 1. What is WebSocket? WebSocket is a full-duplex method on a single TCP connection.

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

Usage: In JavaScript, the insertBefore() method is used to insert a new node in the DOM tree. This method requires two parameters: the new node to be inserted and the reference node (that is, the node where the new node will be inserted).

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis
