Home > Web Front-end > JS Tutorial > body text

LayUI implements front-end paging function

小云云
Release: 2018-05-18 14:30:25
Original
5488 people have browsed it

This article mainly brings you a method to implement front-end paging function based on LayUI. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.

1. Introduction to LayUI

Layui is a domestic front-end UI framework written using its own module specifications. It follows the writing and organizational form of native HTML/CSS/JS. The threshold is extremely low. Ready to use. Built-in UI framework with some common elements and components.

After downloading, introduce it into the project.

<link rel="stylesheet" href="${pageContext.request.contextPath}/css/layui/css/layui.css" rel="external nofollow" >
<script src="${pageContext.request.contextPath}/js/layui.js" ></script>
Copy after login

2. Introduction to LayPage parameters

laypage is a built-in encapsulated object, which can be called directly when paging. There are mainly the following parameters here for configuring laypage. Key-value pair collection:

##Current page. groups5NumberNumber of consecutive pages. skindefaultStringControl paging skinfirst1Number/String/Boolean is used to control the homepage. first: false, it means not to display the homepage itemslastTotal page valueNumber/String/Boolean is used to control the last page. last: false, it means not to display the last page itemprevPrevious pageString/Boolean is used to control the previous page. If not displayed, set false##nextjumpobj is an object type. Contains all configuration information for paging. 3. Paging Implementation

Key

Default value

Type

Description

cont

Required

String/Object

Container. The value can be passed in the element id or native DOM or jquery object

pages

Required

Number

Page number

##curr

1

Number

Next page

String/Boolean

is used to control the next page. If it is not displayed, set false

Core parameters

Function

Triggers the callback after paging, and the function returns two parameters.
First a Boolean class to detect whether the page is initially loaded. Very useful to avoid infinite refreshes.



Display the page on the front end, the code is as follows:

<script>
 var pcountString= "${pcount}";
 var psizeString= "${psize}";
 var pcountInt= parseInt(pcountString);//总页数
 var psizeInt=parseInt(psizeString); //页面大小
 var pindex = "${pindex}";// 当前页
 var ptotalpages=Math.ceil(pcountInt/psizeInt);// 总记录数
 layui.define(['layer', 'laypage' ], function(exports) {
  var layer = layui.layer;
  var laypage = layui.laypage;
  var pcount = pcountInt;// 总记录数
  var psize = psizeInt;// 每一页的记录数
  // 分页
  laypage({
   cont : 'pagination', // 页面上的id
   pages : ptotalpages,//总页数
   curr : pindex,//当前页
   skin: '#999999',//颜色
   jump : function(obj, first) {
    if (!first) {
     var parId=$("#parId").val();
     var pindex=obj.curr;
    window.location.href="${ctx}/web/rest/RecycleManage/GetFileList?parId=" rel="external nofollow" +parId+"&pindex="+pindex;//跳转链接
    }
   }
  });
 });
</script>
Copy after login
The pagination effect is as follows:

Related recommendations:


A very easy-to-use front-end paging js tool class

About 10 articles recommended for front-end paging

jQuery front-end paging example sharing_jquery

The above is the detailed content of LayUI implements front-end paging function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template