加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test2.html 3.19 KB
一键复制 编辑 原始数据 按行查看 历史
ele-admin 提交于 2018-07-25 16:55 . 支持通过data参数渲染
<!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"/>
<style>
/** 箭头未展开 */
#table1 + .treeTable .treeTable-icon .layui-icon-triangle-d:before {
content: "\e602";
}
/** 箭头展开 */
#table1 + .treeTable .treeTable-icon.open .layui-icon-triangle-d:before {
content: "\e61a";
}
/** 文件图标 */
#table1 + .treeTable .treeTable-icon .layui-icon-file:before {
content: "\e60d";
}
/** 文件夹未展开 */
#table1 + .treeTable .treeTable-icon .layui-icon-layer:before {
content: "\e637";
}
/** 文件夹展开 */
#table1 + .treeTable .treeTable-icon.open .layui-icon-layer:before {
content: "\e634";
}
</style>
</head>
<body>
<div class="layui-container">
<br><br>
<a class="layui-btn layui-btn-normal" href="index.html">&lt;&lt;返回</a>
&nbsp;&nbsp;
<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', 'treetable'], function () {
var $ = layui.jquery;
var table = layui.table;
var treetable = layui.treetable;
// 渲染表格
var renderTable = function () {
layer.load(2);
treetable.render({
treeColIndex: 1,
treeSpid: "0",
treeIdName: 'd_id',
treePidName: 'd_pid',
treeDefaultClose: true,
treeLinkage: false,
elem: '#table1',
url: 'json/data3.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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化