Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use amaze ui paging style to encapsulate a general JS paging control

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article "how to use amaze ui paging style to encapsulate a general JS paging control", so the editor summarizes the following, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "how to use amaze ui paging style to encapsulate a general JS paging control" article.

Step one:

Find the paging HTML code of UI. There are two kinds of code.

Paging code for UI:

Page 1 previous page 1 2 3 4 5 Next page, last page.

The code is simple, the appearance is beautiful, naturally is the first choice of packaging.

Next, it's time to build the wheel. First of all, let's talk about the idea: we need a dynamic paging, then the li in this must be generated dynamically, so we need to use js to generate dom elements. Secondly, the user needs a callback function to request his data and load the data after paging. These are the two core ideas, and the rest are paging routines. For example, the necessary parameters for paging: the current page, the number of entries per page, the total number of pages, and the handling of some events corresponding to this style: the first page, the last page, the previous page, the next page.

The train of thought has been sorted out and opened up.

1. Initialize

Init initialization function, which assigns the parameters passed in by the user, and calculates the total number of pages. Under the total number of pages, I take 0 as the first page, so the total number of pages is the total number of pages / the number of pages per page is rounded up by-1 using Math.ceil.

Function fm_page (cnf) {var fmpage = {id:'page', pageNo: 0 start:0 / current page pageSize: 10 var fmpage / number of entries per page pageCount: 100 showPageNum / total number of pages showPageNum: 5 pageCmp:null / paging element length Total number of pages pageCmp:null, start:0 Init: function () {var it = this If (cnf) {$.each (cnf, function (k, v) {it [k] = v;});} this.pageNum=Math.ceil (this.pageCount/this.pageSize)-1;}} fmpage.init (); return fmpage;}

2. Js dynamically loads li

Dynamically load the starting number from li,start to li according to the number of users want to display:

RenderPage:function (start) {this.start = start | | 0; this.pageCmp=$ ("#" + this.id); this.pageCmp.empty (); this.pageCmp.append ('previous page'. Replace ('{0}', this.id+'.toPrev (); var endNum=this.pageCount/this.pageSize > (this.showPageNum+this.start)? (this.showPageNum+this.start): this.pageCount/this.pageSize / / cut-off element for (var ideterminthis.startteristiprincipthis.startprincipthis.showPageNuminherthis.pageNo

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report