index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Layui树形表格2.x演示</title>
  6. <link rel="stylesheet" href="layui/css/layui.css">
  7. <link rel="stylesheet" href="demo.css">
  8. </head>
  9. <body class="page-no-scroll">
  10. <div class="page-wrapper">
  11. <fieldset class="layui-elem-field layui-field-title">
  12. <legend>Layui树形表格2.x演示</legend>
  13. </fieldset>
  14. <div class="layui-btn-container" style="display: inline-block;">
  15. <button id="btnExpandAll" class="layui-btn layui-btn-sm layui-btn-primary">
  16. <i class="layui-icon">&#xe668;</i>展开全部
  17. </button>
  18. <button id="btnFoldAll" class="layui-btn layui-btn-sm layui-btn-primary">
  19. <i class="layui-icon">&#xe66b;</i>折叠全部
  20. </button>
  21. <button id="btnExpand" class="layui-btn layui-btn-sm layui-btn-primary">
  22. <i class="layui-icon">&#xe625;</i>展开2
  23. </button>
  24. <button id="btnFold" class="layui-btn layui-btn-sm layui-btn-primary">
  25. <i class="layui-icon">&#xe623;</i>折叠2
  26. </button>
  27. <button id="btnChecked" class="layui-btn layui-btn-sm layui-btn-primary">
  28. <i class="layui-icon">&#xe605;</i>勾选1_1_2
  29. </button>
  30. </div>
  31. <input class="layui-input" id="edtSearch" value="1_1_2" placeholder="输入关键字"
  32. style="display: inline-block;width: 140px;height: 30px;line-height: 30px;padding: 0 5px;margin-right: 5px;"/>
  33. <div class="layui-btn-container" style="display: inline-block;">
  34. <button id="btnSearch" class="layui-btn layui-btn-sm layui-btn-primary">
  35. <i class="layui-icon">&#xe615;</i>搜索
  36. </button>
  37. <button id="btnClearSearch" class="layui-btn layui-btn-sm layui-btn-primary">
  38. <i class="layui-icon">&#x1006;</i>清除搜索
  39. </button>
  40. </div>
  41. <div class="layui-btn-container" style="display: inline-block;">
  42. <a href="async.html" class="layui-btn layui-btn-sm layui-btn-primary" lay-tips="千呼万唤始出来~"
  43. style="position: relative;">
  44. <i class="layui-icon">&#xe64d;</i>异步加载&nbsp;&nbsp;
  45. <span class="layui-badge-dot" style="position: absolute;right: 3px;top: 3px;"></span>
  46. </a>
  47. <a href="fixed.html" class="layui-btn layui-btn-sm layui-btn-primary">
  48. <i class="layui-icon">&#xe62d;</i>固定表头
  49. </a>
  50. <a href="edit.html" class="layui-btn layui-btn-sm layui-btn-primary">
  51. <i class="layui-icon">&#xe642;</i>单元格编辑
  52. </a>
  53. <a href="icon.html" class="layui-btn layui-btn-sm layui-btn-primary">
  54. <i class="layui-icon">&#xe639;</i>自定义图标
  55. </a>
  56. <a href="big.html" class="layui-btn layui-btn-sm layui-btn-primary">
  57. <i class="layui-icon">&#xe62c;</i>数据量测试
  58. </a>
  59. <a href="../demo1x/index.html" class="layui-btn layui-btn-sm layui-btn-primary" target="_blank">
  60. 回顾1.x
  61. </a>
  62. <a href="https://whvse.gitee.io/treetable/" class="layui-btn layui-btn-sm layui-btn-primary" target="_blank">
  63. bom表格
  64. </a>
  65. </div>
  66. <table id="demoTreeTable1"></table>
  67. </div>
  68. <div class="right-desc">
  69. <div class="layui-text desc-item">
  70. treeTable时隔一年进行了彻底重构,不再基于数据表格table,从零开始,
  71. 实现了数据表格的大部分功能,在使用方法上与数据表格一致,
  72. 并且支持懒加载、复选框联动、折叠状态记忆等功能,
  73. <a href="https://gitee.com/whvse/treetable-lay" target="_blank">码云下载</a>。
  74. </div>
  75. <div class="layui-text desc-item" style="padding: 0;overflow: hidden;">
  76. <img src="https://s2.ax1x.com/2019/08/23/msiO78.png" width="100%"/>
  77. <div style="padding: 5px 10px;">
  78. EasyWeb管理系统模板
  79. <a href="https://demo.easyweb.vip/iframe/" style="float: right;" target="_blank">前往查看</a>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- 表格操作列 -->
  84. <script type="text/html" id="demoTreeTableBar1">
  85. <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
  86. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  87. </script>
  88. <!-- 表格状态列 -->
  89. <script type="text/html" id="demoTreeTableState1">
  90. <input type="checkbox" lay-filter="ckState" value="{{d.id}}" lay-skin="switch"
  91. lay-text="正常|锁定" {{d.state==0?'checked':''}}/>
  92. </script>
  93. <div class="page-loading">
  94. <div class="ball-loader sm">
  95. <span></span><span></span><span></span><span></span>
  96. </div>
  97. </div>
  98. <script src="layui/layui.js"></script>
  99. <script>
  100. layui.config({
  101. base: '../module/'
  102. }).extend({
  103. treeTable: 'treeTable/treeTable'
  104. }).use(['layer', 'util', 'treeTable'], function () {
  105. var $ = layui.jquery;
  106. var layer = layui.layer;
  107. var util = layui.util;
  108. var treeTable = layui.treeTable;
  109. var data = [{
  110. id: "1",
  111. name: "xxx",
  112. state: 0,
  113. createTime: "2019/11/18 10:44:00",
  114. children: [{
  115. id: "1_1",
  116. name: "xxx",
  117. state: 0,
  118. createTime: "2019/11/18 10:44:00",
  119. children: [{
  120. id: "1_1_1",
  121. name: "xxx",
  122. state: 0,
  123. createTime: "2019/11/18 10:44:00",
  124. children: []
  125. }, {
  126. id: "1_1_2",
  127. name: "xxx",
  128. state: 0,
  129. createTime: "2019/11/18 10:44:00",
  130. children: []
  131. }, {
  132. id: "1_1_3",
  133. name: "xxx",
  134. state: 0,
  135. createTime: "2019/11/18 10:44:00",
  136. children: []
  137. }]
  138. }, {
  139. id: "1_2",
  140. name: "xxx",
  141. state: 0,
  142. createTime: "2019/11/18 10:44:00",
  143. children: [{
  144. id: "1_2_1",
  145. name: "xxx",
  146. state: 0,
  147. createTime: "2019/11/18 10:44:00",
  148. children: []
  149. }, {
  150. id: "1_2_2",
  151. name: "xxx",
  152. state: 0,
  153. createTime: "2019/11/18 10:44:00",
  154. children: []
  155. }, {
  156. id: "1_2_3",
  157. name: "xxx",
  158. state: 0,
  159. createTime: "2019/11/18 10:44:00",
  160. children: []
  161. }]
  162. }, {
  163. id: "1_3",
  164. name: "xxx",
  165. state: 0,
  166. createTime: "2019/11/18 10:44:00",
  167. children: []
  168. }]
  169. }, {
  170. id: "2",
  171. name: "xxx",
  172. state: 0,
  173. createTime: "2019/11/18 10:44:00",
  174. children: [{
  175. id: "2_1",
  176. name: "xxx",
  177. state: 0,
  178. createTime: "2019/11/18 10:44:00",
  179. children: [{
  180. id: "2_1_1",
  181. name: "xxx",
  182. state: 0,
  183. createTime: "2019/11/18 10:44:00",
  184. children: []
  185. }, {
  186. id: "2_1_2",
  187. name: "xxx",
  188. state: 0,
  189. createTime: "2019/11/18 10:44:00",
  190. children: []
  191. }, {
  192. id: "2_1_3",
  193. name: "xxx",
  194. state: 0,
  195. createTime: "2019/11/18 10:44:00",
  196. children: []
  197. }]
  198. }, {
  199. id: "2_2",
  200. name: "xxx",
  201. state: 0,
  202. createTime: "2019/11/18 10:44:00",
  203. children: []
  204. }, {
  205. id: "2_3",
  206. name: "xxx",
  207. state: 0,
  208. createTime: "2019/11/18 10:44:00",
  209. children: []
  210. }]
  211. }, {
  212. id: "3",
  213. name: "xxx",
  214. state: 0,
  215. createTime: "2019/11/18 10:44:00",
  216. children: [{
  217. id: "3_1",
  218. name: "xxx",
  219. state: 0,
  220. createTime: "2019/11/18 10:44:00",
  221. children: []
  222. }, {
  223. id: "3_2",
  224. name: "xxx",
  225. state: 0,
  226. createTime: "2019/11/18 10:44:00",
  227. children: []
  228. }, {
  229. id: "3_3",
  230. name: "xxx",
  231. state: 0,
  232. createTime: "2019/11/18 10:44:00",
  233. children: []
  234. }]
  235. }, {
  236. id: "4",
  237. name: "xxx",
  238. state: 0,
  239. createTime: "2019/11/18 10:44:00",
  240. children: []
  241. }, {
  242. id: "5",
  243. name: "xxx",
  244. state: 0,
  245. createTime: "2019/11/18 10:44:00",
  246. children: []
  247. }];
  248. // 渲染表格
  249. var insTb = treeTable.render({
  250. elem: '#demoTreeTable1',
  251. data: data,
  252. tree: {
  253. iconIndex: 2
  254. },
  255. cols: [
  256. {type: 'numbers'},
  257. {type: 'checkbox'},
  258. {field: 'id', title: 'ID'},
  259. {field: 'name', title: 'name', width: 160},
  260. {
  261. field: 'createTime', title: '创建时间', templet: function (d) {
  262. return util.toDateString(d.createTime);
  263. }, width: 180
  264. },
  265. {templet: '#demoTreeTableState1', title: '状态', width: 100},
  266. {align: 'center', toolbar: '#demoTreeTableBar1', title: '操作', width: 120}
  267. ],
  268. style: 'margin-top:0;'
  269. });
  270. treeTable.on('tool(demoTreeTable1)', function (obj) {
  271. var event = obj.event;
  272. if (event == 'del') {
  273. layer.msg('点击了删除', {icon: 1});
  274. } else if (event == 'edit') {
  275. layer.msg('点击了修改', {icon: 1});
  276. }
  277. });
  278. // 全部展开
  279. $('#btnExpandAll').click(function () {
  280. insTb.expandAll();
  281. });
  282. // 全部折叠
  283. $('#btnFoldAll').click(function () {
  284. insTb.foldAll();
  285. });
  286. $('#btnExpand').click(function () {
  287. insTb.expand('2');
  288. });
  289. $('#btnFold').click(function () {
  290. insTb.fold('2');
  291. });
  292. $('#btnChecked').click(function () {
  293. insTb.expand('1_1_2');
  294. insTb.setChecked(['1_1_2']);
  295. });
  296. $('#btnSearch').click(function () {
  297. var keywords = $('#edtSearch').val();
  298. if (keywords) {
  299. insTb.filterData(keywords);
  300. } else {
  301. insTb.clearFilter();
  302. }
  303. });
  304. $('#btnClearSearch').click(function () {
  305. insTb.clearFilter();
  306. });
  307. $(document).on('mouseenter', '*[lay-tips]', function () {
  308. layer.tips($(this).attr('lay-tips'), this, {tips: [1, '#FF5722'], time: -1});
  309. }).on('mouseleave', '*[lay-tips]', function () {
  310. layer.closeAll('tips');
  311. });
  312. setTimeout(function () {
  313. $('body').children('.page-loading').hide();
  314. $('body').removeClass('page-no-scroll');
  315. }, 150);
  316. });
  317. </script>
  318. </body>
  319. </html>