使用layUI渲染表格(方法渲染)
前端
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="./layui/css/layui.css?t=20180403-1">
<script type="text/javascript" src="./layui/layui.js"></script>
</head>
<body>
<table id="demo" lay-filter="test"></table>
<!-- table.on('tool(test)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值" -->
<script>
layui.use('table', function() {
var table = layui.table;
table.render({
elem: '#demo',
request: {
pageName: 'p',
limitName: 'p_n',
},
response: {
countName: 'count',
dataName: 'data'
},
height: 315,
url: "{:url('index_data2')}",
page: true,
cols: [
[
{ field: 'goods_id', title: 'goods_idID', width: 200, sort: true, fixed: 'left' },
{ field: 'goods_sn', title: 'goods_sn', width: 200 },
{ field: '', title: '参看详情', width: 200,templet: '<div><a href="/detail/{{d.goods_id}}" class="layui-table-link">编辑</div>' },
]
],
});
});
</script>
</body>
</html>
后端
public function index_data2()
{
$p = input('p') ?? 1;
$p_n = input('p_n') ?? config('paginate.list_rows');
$list = Db::table('tp_goods')->order('goods_id ASC')->limit(($p - 1) * $p_n, $p_n)->select();
$count = Db::table('tp_goods')->count();
return json(['code' => 0, 'msg' => '加载成功!', 'data' => $list,'count'=>$count]);
}