1. Controller

public function getUser(Request $request)
    {
        $page = $request->get('page');
        $limit = $request->get('limit');
        $offset = ($page - 1) * $limit;
        $users = User::offset($offset)->paginate($limit);
        foreach ($users as $user) {
            if ($user->active) {
                $user->active = '启用';
            } else {
                $user->active = '禁用';
            }
        }
        $data = $users->toArray();
        $res['data']=$data['data'];
        $res['code'] = 0;
        $res['count'] = $data['total'];
        $res['msg'] = '获取数据失败';
        return $res;
    }
  1. blade模板

table.render({
                elem: '#demo'
                , height: 395
                , url: '/admin/users/getuser' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox',width: 80,align:'center'}
                    , {field: 'id', title: 'ID', width: 80, sort: true, align: 'center'}
                    , {field: 'username', title: '用户名', sort: true, align: 'center'}
                    , {field: 'nickname', title: '昵称', sort: true, align: 'center'}
                    , {field: 'sex', title: '性别', sort: true, align: 'center'}
                    , {field: 'phone', title: '手机', sort: true, align: 'center'}
                    , {field: 'active', title: '状态', sort: true, align: 'center'}
                ]]
                , limit: 8
                , limits: [8, 20, 30, 50, 100]                
            });
Last modification:July 5th, 2020 at 05:44 pm
哎呀呀,大家随意,随意就好!