TP5 laypage分页+搜索

控制器

public function show()
{
    $key = input('key');
    $map = [];
    if($key&&$key!=="")
    {
        $map['title'] = ['like',"%" . $key . "%"];
    }

    //当前页码
    $Nowpage = input('get.page') ? input('get.page') : 1;
    $limits = 5;// 获取总条数
    $count = Db::name('information')->where($map)->where(['state'=>0])->count();//计算总页面
    $allpage = intval(ceil($count / $limits));
    $lists = Db::name('information')->where($map)->where(['state'=>0])->page($Nowpage, $limits)->order('id desc')->select();
    $first_names = array_column($lists, 'id');
    foreach ($lists as $k => $v) {
        $lists[$k]['addtime'] = date('Y-m-d H:i:s', $v['addtime']);
        $lists[$k]['modification'] = date('Y-m-d H:i:s', $v['modification']);
    }
    $this->assign('val', $key);
    $this->assign('Nowpage', $Nowpage); //当前页
    $this->assign('allpage', $allpage); //总页数
    if (input('get.page')) {
        return json($lists);
    }
    return $this->fetch('show',['lists'=>$lists]);
}
<form name="admin_list_sea" class="form-search" method="post" action="{:url('addd/show')}">
    <div class="col-sm-3">
        <div class="input-group">
            <input type="text" id="key" class="form-control" name="key" value="{$val}" placeholder="关键字" />
            <span class="input-group-btn">
                <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
            </span>
        </div>
    </div>
</form>
   //laypage分页
    Ajaxpage();
    function Ajaxpage(curr){
        var key=$('#key').val();
        $.getJSON('{:url("Addd/show")}', {page: curr || 1,key:key}, function(data){
            $(".spiner-example").css('display','none'); //数据加载完关闭动画
            if(data==''){
                $("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            }else{
                var tpl = document.getElementById('list-template').innerHTML;
                laytpl(tpl).render(data, function(html){
                    document.getElementById('list-content').innerHTML = html;
                });
                laypage({
                    cont: $('#AjaxPage'),//容器。值支持id名、原生dom对象,jquery对象,
                    pages:'{$allpage}',//总页数
                    skip: true,//是否开启跳页
                    skin: '#1AB5B7',//分页组件颜色
                    curr: curr || 1,
                    groups: 3,//连续显示分页数
                    jump: function(obj, first){
                        if(!first){
                            Ajaxpage(obj.curr)
                        }
                        $('#allpage').html('第'+ obj.curr +'页,共'+ obj.pages +'页');
                    }
                });
            }
        });
    }
 
 
 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值