From 5a6b5a1bd08f74c7fd36d9c730f7470a2e458987 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Wed, 14 Jun 2023 21:00:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20treeTable=20=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E5=85=A8=E9=83=A8=E4=B9=8B=E5=90=8E=E5=AD=90=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=B2=A1=E6=9C=89=E6=8C=89=E7=85=A7=E5=BD=93=E5=89=8D?= =?UTF-8?q?=20`initSort`=20=E6=8E=92=E5=BA=8F=E7=9A=84=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 | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index c5cc0f6c..a2f0e838 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -161,9 +161,6 @@ layui.define(['table'], function (exports) { if (treeOptions.data.isSimpleData) { options.data = that.flatToTree(options.data); } - if (options.initSort && options.initSort.type) { - layui.sort(options.data, options.initSort.field, options.initSort.type === 'desc', true) - } that.initData(options.data); } @@ -171,7 +168,6 @@ layui.define(['table'], function (exports) { options.done = function () { var args = arguments; var doneThat = this; - that.initSort = doneThat.initSort; var isRenderData = args[3]; // 是否是 renderData if (!isRenderData) { delete that.isExpandAll; @@ -899,9 +895,7 @@ layui.define(['table'], function (exports) { d[idKey] !== undefined && (that.status.expand[d[idKey]] = true); } }); - if (options.initSort && options.initSort.type && - (!that.initSort || options.initSort.type !== that.initSort.type && options.initSort.field !== that.initSort.field) && - (!options.url || options.autoSort)) { + if (options.initSort && options.initSort.type && (!options.url || options.autoSort)) { return treeTable.sort(id); } var trAll = table.getTrHtml(id, tableDataFlat); @@ -1073,7 +1067,7 @@ layui.define(['table'], function (exports) { }); // 根据需要处理options中的一些参数 - updateOptions(that.config.id, options, type || true); + updateOptions(that.getOptions().id, options, type || true); // 对参数进行深度或浅扩展 that.config = $.extend(deep, {}, that.config, options); @@ -1137,26 +1131,9 @@ layui.define(['table'], function (exports) { if(!that) return; var options = that.getOptions(); - var initSort = options.initSort; - - if (!options.url) { - if (initSort.type) { - layui.sort(options.data, initSort.field, initSort.type === 'desc', true); - } else { - layui.sort(options.data, table.config.indexName, null, true); - } - that.initData(options.data); - treeTable.reloadData(id); - } else { - // url异步取数的表格一般需要自己添加监听之后进行reloadData并且把排序参数加入到where中 - if (options.autoSort) { - var tableData = that.initData(); - var res = {}; - res[options.response.dataName] = tableData; - typeof options.done === 'function' && options.done( - res, that.page, that.count - ); - } + if (!options.url || options.autoSort) { + that.initData(); + treeTable.renderData(id); } }