From 5b54593d840fb6e101a770bea46dc14ae4d541a5 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Wed, 24 May 2023 16:46:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20treeTable=20`expandAll`=20?= =?UTF-8?q?=E5=B1=95=E5=BC=80=E8=8A=82=E7=82=B9=E6=8E=92=E5=BA=8F=E5=87=BA?= =?UTF-8?q?=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 636eab6a..15d362a8 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -784,15 +784,20 @@ layui.define(['table'], function (exports) { tableView.find('tbody tr[data-level!="0"]').removeClass(HIDE); // 处理节点的图标 tableView.find('.layui-table-tree-flexIcon').html(treeOptions.view.flexIconOpen); - treeOptions.view.showIcon && tableView.find('.layui-table-tree-nodeIcon:not(.layui-table-tree-iconCustom,.layui-table-tree-iconLeaf)').html(treeOptions.view.iconOpen); + treeOptions.view.showIcon && tableView + .find('.layui-table-tree-nodeIcon:not(.layui-table-tree-iconCustom,.layui-table-tree-iconLeaf)') + .html(treeOptions.view.iconOpen); } else { - // 如果有未打开过的父节点,将内容全部生成 + // 如果有未打开过的父节点,将 tr 内容全部重新生成 that.updateStatus(null, function (d) { if (d[isParentKey]) { d[LAY_EXPAND] = true; d[LAY_HAS_EXPANDED] = true; } - }); // {LAY_EXPAND: true, LAY_HAS_EXPANDED: true}); + }); + if (options.initSort && options.initSort.type && (!options.url || options.autoSort)) { + return treeTable.sort(id); + } var trAll = table.getTrHtml(id, tableDataFlat); var trAllObj = { @@ -800,23 +805,17 @@ layui.define(['table'], function (exports) { trs_fixed: $(trAll.trs_fixed.join('')), trs_fixed_r: $(trAll.trs_fixed_r.join('')) } + var props; layui.each(tableDataFlat, function (dataIndex, dataItem) { var dataLevel = dataItem[LAY_DATA_INDEX].split('-').length - 1; - trAllObj.trs.eq(dataIndex).attr({ - 'data-index': dataItem[LAY_DATA_INDEX], - 'lay-data-index': dataItem[LAY_DATA_INDEX], - 'data-level': dataLevel - }) - trAllObj.trs_fixed.eq(dataIndex).attr({ + props = { 'data-index': dataItem[LAY_DATA_INDEX], 'lay-data-index': dataItem[LAY_DATA_INDEX], 'data-level': dataLevel - }) - trAllObj.trs_fixed_r.eq(dataIndex).attr({ - 'data-index': dataItem[LAY_DATA_INDEX], - 'lay-data-index': dataItem[LAY_DATA_INDEX], - 'data-level': dataLevel - }) + }; + trAllObj.trs.eq(dataIndex).attr(props) + trAllObj.trs_fixed.eq(dataIndex).attr(props) + trAllObj.trs_fixed_r.eq(dataIndex).attr(props) }) layui.each(['main', 'fixed-l', 'fixed-r'], function (i, item) { tableView.find('.layui-table-' + item + ' tbody').html(trAllObj[['trs', 'trs_fixed', 'trs_fixed_r'][i]]);