From 9044647dc20748d3986006fbab68524925af9e6f Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Mon, 10 Apr 2023 15:55:55 +0800 Subject: [PATCH] =?UTF-8?q?table=E4=BF=AE=E5=A4=8D=E5=A4=9A=E7=BA=A7?= =?UTF-8?q?=E8=A1=A8=E5=A4=B4=E5=AD=98=E5=9C=A8=E8=87=AA=E5=8A=A8=E5=88=86?= =?UTF-8?q?=E9=85=8D=E5=AE=BD=E5=BA=A6=E5=88=97=E7=9A=84=E6=97=B6=E5=80=99?= =?UTF-8?q?=E5=9C=A8=E6=9F=90=E4=BA=9B=E5=9C=BA=E6=99=AF=E4=B8=8B=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E5=8D=A0=E6=BB=A1=E8=A1=A8=E6=A0=BC=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9BtreeTable=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?set=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E9=BB=98=E8=AE=A4=E5=B1=9E=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 23 +++++++++++++---------- src/modules/treeTable.js | 7 ++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index e0e1e902..7782bef6 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -811,13 +811,20 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ if(that.autoColNums > 0 && patchNums >= -colNums && patchNums <= colNums){ var getEndTh = function(th){ - var field; - th = th || that.layHeader.eq(0).find('thead > tr:first-child > th:last-child') - field = th.data('field'); + var field, thRet; + th = th || that.layHeader.eq(0).find('thead th:last-child') + layui.each(th, function (thIndex, thElem) { + thElem = $(thElem); + if (!thElem.children('.'+ELEM_GROUP).length) { // 排除合并表头 + field = thElem.attr('data-field'); + thRet = thElem; + } + }) + if(!field && th.prev()[0]){ return getEndTh(th.prev()) } - return th + return thRet }; var th = getEndTh(); var key = th.data('key'); @@ -897,6 +904,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ table.cache[that.key] = []; //格式化缓存数据 that.syncCheckAll(); + that.renderForm(); + that.setColsWidth(); }; // 初始页码 @@ -957,7 +966,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } // 检查数据格式是否符合规范 if(res[response.statusName] != response.statusCode){ - that.renderForm(); that.errorView( res[response.msgName] || ('返回的数据不符合规范,正确的成功状态码应为:"'+ response.statusName +'": '+ response.statusCode) @@ -980,10 +988,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ } ,error: function(e, msg){ that.errorView('请求异常,错误提示:'+ msg); - - that.renderForm(); - that.setColsWidth(); - typeof options.error === 'function' && options.error(e, msg); } }); @@ -1269,7 +1273,6 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ //如果无数据 if(data.length === 0){ - that.renderForm(); return that.errorView(options.text.none); } else { that.layFixLeft.removeClass(HIDE); diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 67e82821..5a1db61a 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -19,6 +19,11 @@ layui.define(['table'], function (exports) { // 遍历字段 eachCols: table.eachCols, index: table.index, + set: function(options){ + var that = this; + that.config = $.extend({}, that.config, options); + return that; + }, }; // 操作当前实例 @@ -1034,4 +1039,4 @@ layui.define(['table'], function (exports) { }; exports(MOD_NAME, treeTable); -}); \ No newline at end of file +});