forked from mengqingquan/treetable-lay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
83 lines (75 loc) · 2.46 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tree-table</title>
<link rel="stylesheet" href="assets/layui/css/layui.css">
<link rel="stylesheet" href="assets/common.css"/>
</head>
<body>
<div class="layui-container">
<br><br>
<a class="layui-btn layui-btn-normal" href="index.html"><<返回</a>
<div class="layui-btn-group">
<button class="layui-btn" id="btn-expand">全部展开</button>
<button class="layui-btn" id="btn-fold">全部折叠</button>
<button class="layui-btn" id="btn-refresh">刷新表格</button>
</div>
<table id="table1" class="layui-table" lay-filter="table1"></table>
</div>
<!-- 操作列 -->
<script type="text/html" id="oper-col">
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="assets/layui/layui.js"></script>
<script>
layui.config({
base: 'module/'
}).extend({
treetable: 'treetable-lay/treetable'
}).use(['table', 'form', 'element', 'treetable'], function () {
var $ = layui.jquery;
var table = layui.table;
var form = layui.form;
var element = layui.element;
var treetable = layui.treetable;
// 渲染表格
var renderTable = function () {
layer.load(2);
treetable.render({
treeColIndex: 2,
treeSpid: -1,
treeIdName: 'd_id',
treePidName: 'd_pid',
elem: '#table1',
url: 'json/data2.json',
page: false,
cols: [[
{type: 'numbers'},
{field: 'id', title: 'id'},
{field: 'name', title: 'name'},
{field: 'sex', title: 'sex'},
{field: 'pid', title: 'pid'},
{templet: '#oper-col', title: 'oper'}
]],
done: function () {
layer.closeAll('loading');
}
});
};
renderTable();
$('#btn-expand').click(function () {
treetable.expandAll('#table1');
});
$('#btn-fold').click(function () {
treetable.foldAll('#table1');
});
$('#btn-refresh').click(function () {
renderTable();
});
});
</script>
</body>
</html>