


Detailed explanation of the difference between LayUI paging and LayUI laypage paging
This article mainly introduces the usage examples based on LayUI paging and LayUI laypage paging. The editor thinks it is quite good, so I will 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.
Rendering:
1. Reference js dependency
Mainly jquery -1.11.3.min.js and layui.all.js, json2.js is used to convert json objects
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/plugin/layui/lay/dest/layui.all.js"></script> <script type="text/javascript" src="${pageContext.request.contextPath}/js/json2.js"></script>
2. js paging method encapsulation (pagination uses template laytpl)
1. Template rendering
/** * 分页模板的渲染方法 * @param templateId 分页需要渲染的模板的id * @param resultContentId 模板渲染后显示在页面的内容的容器id * @param data 服务器返回的json对象 */ function renderTemplate(templateId, resultContentId, data){ layuiuse(['form','laytpl'], function(){ var laytpl = layui.laytpl; laytpl($("#"+templateId).html()).render(data, function(html){ $("#"+resultContentId).html(html); }); }); layui.form().render();// 渲染 };
2. layui.laypage paging encapsulation
/** * layuilaypage 分页封装 * @param laypagepId 分页控件p层的id * @param pageParams 分页的参数 * @param templateId 分页需要渲染的模板的id * @param resultContentId 模板渲染后显示在页面的内容的容器id * @param url 向服务器请求分页的url链接地址 */ function renderPageData(laypagepId, pageParams, templateId, resultContentId, url){ if(isNull(pageParams)){ pageParams = { pageIndex : 1, pageSize : 10 } } $ajax({ url : url,//basePath + '/sysMenu/pageSysMenu', method : 'post', data : pageParams,//JSON.stringify(datasub) async : true, complete : function (XHR, TS){}, error : function(XMLHttpRequest, textStatus, errorThrown) { if("error"==textStatus){ error("服务器未响应,请稍候再试"); }else{ error("操作失败,textStatus="+textStatus); } }, success : function(data) { var jsonObj; if('object' == typeof data){ jsonObj = data; }else{ jsonObj = JSON.parse(data); } renderTemplate(templateId, resultContentId, jsonObj); //重新初始化分页插件 layui.use(['form','laypage'], function(){ laypage = layui.laypage; laypage({ cont : laypagepId, curr : jsonObj.pager.pageIndex, pages : jsonObj.pager.totalPage, skip : true, jump: function(obj, first){//obj是一个object类型。包括了分页的所有配置信息。first一个Boolean类,检测页面是否初始加载。非常有用,可避免无限刷新。 pageParams.pageIndex = obj.curr; pageParams.pageSize = jsonObj.pager.pageSize; if(!first){ renderPageData(laypagepId, pageParams, templateId, resultContentId, url); } } }); }); } }); };
3. The method of refreshing the current paging can be omitted
/** * 分页插件刷新当前页的数据,必须有跳转的确定按钮,因为根据按钮点击事件刷新 */ function reloadCurrentPage(){ $(".layui-laypage-btn").click(); };
3. Page code
1. Paging table and paging control
<!-- 分页表格 --> <p class="layui-form"> <table class="layui-table"> <thead> <tr> <th class="w20"><input type="checkbox" name="checkBoxAll" lay-skin="primary" lay-filter="allChoose"></th> <th class="w200">许可名称</th> <th class="w200">许可编码</th> <th class="w200">菜单名称</th> <th>许可链接</th> </tr> </thead> <tbody id="page_template_body_id"> </tbody> </table> </p> <!-- 分页控件p --> <p id="imovie-page-p"></p>
2. Paging template
<script id="page_template_id" type="text/html"> {{# layui.each(d.list, function(index, item){ }} <tr> <td><input type="checkbox" name="permissionId" lay-skin="primary" value="{{item.permissionId}}"></td> <td>{{item.permissionName || ''}}</td> <td>{{item.permissionCode || ''}}</td> <td>{{item.menuName || ''}}</td> <td>{{item.permissionUrl || ''}}</td> </tr> {{# }); }} </script>
3. Paging execution code:
Paging parameters:
function getPageParams(){ var pageParams = { pageIndex : 1, pageSize : 2 }; pageParams.permissionName = $("input[name='permissionName']").val(); pageParams.permissionCode = $("input[name='permissionCode']").val(); pageParams.menuName = $("input[name='menuName']").val(); return pageParams; };
Paging execution method:
function initPage(){ renderPageData("imovie-page-p", getPageParams(), "page_template_id", "page_template_body_id", basePath + '/sysPermission/pageSysPermission'); };
Page loading initialization paging:
$(function(){ initPage(); });
If you include the query of the above rendering, it is as follows:
Html page code
<p> <form class="layui-form layui-form-pane"> <p class="layui-form-item"> <p class="layui-inline"> <label class="layui-form-label">许可名称</label> <p class="layui-input-inline"> <input type="text" name="permissionName" autocomplete="off" class="layui-input" placeholder="请输入许可名称" > </p> </p> <p class="layui-inline"> <label class="layui-form-label">许可编码</label> <p class="layui-input-inline"> <input type="text" name="permissionCode" autocomplete="off" placeholder="请输入许可编码" class="layui-input"> </p> </p> <p class="layui-inline"> <label class="layui-form-label">菜单名称</label> <p class="layui-input-inline layui-input-inline-0"> <input type="text" name="menuName" autocomplete="off" placeholder="请选择菜单名称" class="layui-input"> </p> </p> <p class="layui-inline"> <button id="btnSubmit" class="layui-btn" lay-submit="" lay-filter="formFilter">查询</button> </p> </p> </form> </p>
Query statement:
$(function(){ initPage(); layui.use(['form'], function(){ var form = layui.form(); //监听提交 formon('submit(formFilter)', function(data){ initPage(); return false; }); }); });
Related recommendations:
layui paging effect implementation code sharing
php paging class instance analysis
Detailed explanation of jQuery encapsulated paging component
The above is the detailed content of Detailed explanation of the difference between LayUI paging and LayUI laypage paging. 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

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



Layui login page jump setting steps: Add jump code: Add judgment in the login form submit button click event, and jump to the specified page through window.location.href after successful login. Modify the form configuration: add a hidden input field to the form element of lay-filter="login", with the name "redirect" and the value being the target page address.

layui provides a variety of methods for obtaining form data, including directly obtaining all field data of the form, obtaining the value of a single form element, using the formAPI.getVal() method to obtain the specified field value, serializing the form data and using it as an AJAX request parameter, and listening Form submission event gets data.

Adaptive layout can be achieved by using the responsive layout function of the layui framework. The steps include: referencing the layui framework. Define an adaptive layout container and set the layui-container class. Use responsive breakpoints (xs/sm/md/lg) to hide elements under specific breakpoints. Specify element width using the grid system (layui-col-). Create spacing via offset (layui-offset-). Use responsive utilities (layui-invisible/show/block/inline) to control the visibility of elements and how they appear.

The method of using layui to transmit data is as follows: Use Ajax: Create the request object, set the request parameters (URL, method, data), and process the response. Use built-in methods: Simplify data transfer using built-in methods such as $.post, $.get, $.postJSON, or $.getJSON.

The difference between layui and Vue is mainly reflected in functions and concerns. Layui focuses on rapid development of UI elements and provides prefabricated components to simplify page construction; Vue is a full-stack framework that focuses on data binding, component development and state management, and is more suitable for building complex applications. Layui is easy to learn and suitable for quickly building pages; Vue has a steep learning curve but helps build scalable and easy-to-maintain applications. Depending on the project needs and developer skill level, the appropriate framework can be selected.

layui is a front-end UI framework that provides a wealth of UI components, tools and functions to help developers quickly build modern, responsive and interactive web applications. Its features include: flexible and lightweight, modular design, rich components, Powerful tools and easy customization. It is widely used in the development of various web applications, including management systems, e-commerce platforms, content management systems, social networks and mobile applications.

The layui framework is a JavaScript-based front-end framework that provides a set of easy-to-use UI components and tools to help developers quickly build responsive web applications. Its features include: modular, lightweight, responsive, and has complete documentation and community support. layui is widely used in the development of management backend systems, e-commerce websites, and mobile applications. The advantages are quick start-up, improved efficiency, and easy maintenance. The disadvantages are poor customization and slow technology updates.

layui and vue are front-end frameworks. layui is a lightweight library that provides UI components and tools; vue is a comprehensive framework that provides UI components, state management, data binding, routing and other functions. layui is based on a modular architecture, and vue is based on a componentized architecture. layui has a smaller ecosystem, vue has a large and active ecosystem. The learning curve of layui is low, and the learning curve of vue is steep. Layui is suitable for small projects and rapid development of UI components, while vue is suitable for large projects and scenarios that require rich functions.
