layUIを使用してテーブルをレンダリングする(方法レンダリング)
5471 ワード
フロントエンド
バックエンド
<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>
<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: '' },
]
],
});
});
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]);
}