前段展示效果
js 代码
table.render({
elem: '#LAY-app-content-list'
,url:'{:url("Bolg/selectList")}'
,page: true
,cols: [[
{type: 'checkbox', fixed: 'left'},
{field:'id',title: 'ID',sort:true,width :80}
,{field: 'title',title: '标题'}
,{field: 'upload_time',title: '上传时间',}
,{field: 'tags',title: '作者',}
,{field: 'tags',title: '分类',}
// ,{field: 'save_time',title: '更新时间'}
,{field: 'state',title: '状态',templet:function(d){
if(d.state ==1){
return'已发布';
}else if (d.state ==0){
return '未发布';
}
}}
,{field: 'right',title: '操作',width: 150, minWidth: 150, toolbar: '#table-content-list'}
]],
page: {
curr: 1 //重新从第 1 页开始
,layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
,limit:5 //一页显示多少条
,limits:[5,10,15,20,25,30]//每页条数的选择项
,groups: 5 //只显示 2 个连续页码
,first: "首页" //不显示首页
,last: "尾页" //不显示尾页
}
});
后台PHP代码
public function selectList(){
$page=request()->param('page');
$limit=request()->param('limit');
$where[] = ['state', 'neq', 3];
$count=count(Db::name('List')->where($where)->select());
$list=Db::name('List')->where($where)->limit(($page-1)*$limit,$limit)->select();
return json([
'data'=>$list,
'code'=>0,
'count'=>$count,
]);
}
这里借鉴了 夜莺歌 的前段分页操作 但是后台部分我使用的是DB,他使用的是数据库模型
附上原文链接
https://blog.youkuaiyun.com/sinat_37961845/article/details/85243176