tp5 layui 分頁輸出

PHP 

 public function getJson(Request $request,$id)
    {
        $wash_card_list = model('WashCardList');
        //獲取每頁顯示的條數
        $limit= $request->param('limit');
        //獲取當前頁數
        $page= $request->param('page');

        $where = [];
        $where['wash_card_id'] = $id ;

        $list = $wash_card_list->order('user_id desc')->where($where)->paginate($limit,false,['page'=>$page])->toArray();

        return json(['code'=>0,'msg'=>'','count'=>$list['total'],'data'=>$list['data']]);

    }

HTML

 

 layui.use(['layer','table'], function(){
        var table = layui.table;
        //第一個實例
        table.render({
            elem: '#table'
            // ,height: 600
            ,url: "{:url('getJson','id='.input('id'))}" //數據接口
            ,page: true //開啓分頁
            ,toolbar:true
            ,defaultToolbar: ['filter', 'exports']
            ,cols: [[ //表頭
                {field: 'card_number', title: '卡號', sort: true, fixed: 'left'}
                ,{field: 'user_id', title: '綁定用戶',}
                ,{field: 'use_count', title: '使用次數', sort: true}
                ,{field: '', title: '操作',toolbar:'#barDemo',width:260}
            ]],

        });

效果

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章