This article mainly introduces the use of layer paging in jQuery. The examples introduce the techniques of layer paging. It is of great practical value. Friends who need it can refer to it. I hope it can help everyone.
layui provides us with the paging component. Simple configuration can create the paging effect.
Code above:
// 点击查询按钮 开始显示表格内容 // 如果查询内容不存在 则显示为空 $('#searchBtn').click(function(){ var html = ''; $.ajax({ type:"GET", url:"data/tsResult.json", success:function(TS){ // 拿到投诉案件数据 // 分页器 layui.use(['laypage','layer'],function(){ var laypage = layui.laypage, layer = layui.layer; var num = 7;//每一页出现的数据量 // 模拟渲染 var render = function(curr){//当前页 var html = '', last = curr*num-1;//当前页的最后一行数据的下标 last = last >= TS.length?(TS.length-1):last; for(var i=(curr*num-num); i<=last; i++){ // 从未显示的第一行开始 html += '<tr>'+ '<td width="4%">'+TS[i].id+'</td>'+ '<td width="8%">'+TS[i].COMPNAME+'</td>'+ '<td width="12%">'+TS[i].COMTELPHONE+'</td>'+ '<td width="16%">'+TS[i].COMPCARD+'</td>'+ '<td width="8%">'+TS[i].DJRQ_S+'</td>'+ '<td width="8%">'+TS[i].COMTYPE+'</td>'+ '<td width="28%">'+TS[i].COMCONTEXT+'</td>'+ '<td width="8%">'+TS[i].STATE+'</td>'+ '<td width="8%" style="text-align:center;"><button class="layui-btn doBtn">'+TS[i].btn+'</button></td>'+ '</tr>'; } return html; }; laypage({ cont:'demo4', pages:Math.ceil(TS.length/num), first:false, last: false, jump:function(obj){ document.getElementById('TS-list').innerHTML = render(obj.curr); } }); }); } }); });
Let’s explain the code here a little:
1. Click the button #searchBtn to initiate an ajax request to obtain the data that needs to be paged.
2. After success, the callback is executed to perform paging + splicing.
3. Required code
layui.use(['laypage','layer'],function(){ var laypage = layui.laypage, layer = layui.layer; }
4. Define the number of items num to be displayed on a page, define the render method, and perform simulated rendering.
5. Jump implementation
The above code can be used directly, you only need to change the object.
Related recommendations:
php rewrites the pager CLinkPager sample code sharing
javascript - Novice imitates sg's paging in the project Device. Please give me some advice
JQuery’s Pager implementation code_jquery
The above is the detailed content of Detailed explanation of layer paginator examples in jQuery. For more information, please follow other related articles on the PHP Chinese website!