From f73501c1570418aeaa4981dfe40153fde9f6bf2e Mon Sep 17 00:00:00 2001 From: morning-star <1453017105@qq.com> Date: Sun, 3 Dec 2023 22:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20table=20=E5=85=A8=E9=80=89?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E7=A6=81=E7=94=A8=E8=A1=8C=E4=BB=8D=E6=9C=89?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E6=A0=B7=E5=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#1436)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复 table 全选时,禁用行仍有选中样式的问题,close `#I8KPUT` close https://gitee.com/layui/layui/issues/I8KPUT * 优化 `table.setRowChecked()` 查找当前行细节,减少全选时的元素查找频率 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com> --- src/modules/table.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index 23bc4812..10a3b6c1 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1560,8 +1560,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ Class.prototype.setRowChecked = function(opts){ var that = this; var options = that.config; + var isCheckAll = opts.index === 'all'; var tr = that.layBody.find('tr'+ ( - opts.index === 'all' ? '' : '[data-index="'+ opts.index +'"]' + isCheckAll ? '' : '[data-index="'+ opts.index +'"]' )); // 默认属性 @@ -1580,12 +1581,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){ // 设置数据选中属性 layui.each(thisData, function(i, item){ if(layui.type(item) === 'array' || item[options.disabledName]) return; // 空项 - if(Number(opts.index) === i || opts.index === 'all'){ + if(Number(opts.index) === i || isCheckAll){ var checked = item[options.checkName] = getChecked(item[options.checkName]); - tr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色 + var currTr = isCheckAll ? tr.filter('[data-index="'+ i +'"]') : tr; + currTr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色 // 若为 radio 类型,则取消其他行选中背景色 if(opts.type === 'radio'){ - tr.siblings().removeClass(ELEM_CHECKED); + currTr.siblings().removeClass(ELEM_CHECKED); } } else if(opts.type === 'radio') { delete item[options.checkName];