Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-01 11:23:04 09月11日 Update

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

Tags: Style encapsulation content number of pages controls code functions dynamics previous users elements parameters that is ideas beauty data articles knowledge articles home page Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Xiaomi NVidia macOS