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

Detailed explanation of layer paginator examples in jQuery

小云云
Release: 2018-01-22 16:29:10
Original
2145 people have browsed it

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 += &#39;<tr>&#39;+
                    &#39;<td width="4%">&#39;+TS[i].id+&#39;</td>&#39;+
                    &#39;<td width="8%">&#39;+TS[i].COMPNAME+&#39;</td>&#39;+
                    &#39;<td width="12%">&#39;+TS[i].COMTELPHONE+&#39;</td>&#39;+
                    &#39;<td width="16%">&#39;+TS[i].COMPCARD+&#39;</td>&#39;+
                    &#39;<td width="8%">&#39;+TS[i].DJRQ_S+&#39;</td>&#39;+
                    &#39;<td width="8%">&#39;+TS[i].COMTYPE+&#39;</td>&#39;+
                    &#39;<td width="28%">&#39;+TS[i].COMCONTEXT+&#39;</td>&#39;+
                    &#39;<td width="8%">&#39;+TS[i].STATE+&#39;</td>&#39;+
                    &#39;<td width="8%" style="text-align:center;"><button class="layui-btn doBtn">&#39;+TS[i].btn+&#39;</button></td>&#39;+
                  &#39;</tr>&#39;;
            }
            return html;
        };

        laypage({
          cont:&#39;demo4&#39;,
          pages:Math.ceil(TS.length/num),
          first:false,
          last: false,
          jump:function(obj){
            document.getElementById(&#39;TS-list&#39;).innerHTML = render(obj.curr);
          }
        });
      });
    }
  });
});
Copy after login

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([&#39;laypage&#39;,&#39;layer&#39;],function(){
        var laypage = layui.laypage,
        layer = layui.layer;
        }
Copy after login

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!

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