Skip to content

Commit f73501c

Browse files
Sight-wcgsentsim
andauthored
修复 table 全选时,禁用行仍有选中样式的问题 (layui#1436)
* 修复 table 全选时,禁用行仍有选中样式的问题,close `#I8KPUT` close https://gitee.com/layui/layui/issues/I8KPUT * 优化 `table.setRowChecked()` 查找当前行细节,减少全选时的元素查找频率 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com>
1 parent 3680858 commit f73501c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/modules/table.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,8 +1560,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
15601560
Class.prototype.setRowChecked = function(opts){
15611561
var that = this;
15621562
var options = that.config;
1563+
var isCheckAll = opts.index === 'all';
15631564
var tr = that.layBody.find('tr'+ (
1564-
opts.index === 'all' ? '' : '[data-index="'+ opts.index +'"]'
1565+
isCheckAll ? '' : '[data-index="'+ opts.index +'"]'
15651566
));
15661567

15671568
// 默认属性
@@ -1580,12 +1581,13 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
15801581
// 设置数据选中属性
15811582
layui.each(thisData, function(i, item){
15821583
if(layui.type(item) === 'array' || item[options.disabledName]) return; // 空项
1583-
if(Number(opts.index) === i || opts.index === 'all'){
1584+
if(Number(opts.index) === i || isCheckAll){
15841585
var checked = item[options.checkName] = getChecked(item[options.checkName]);
1585-
tr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色
1586+
var currTr = isCheckAll ? tr.filter('[data-index="'+ i +'"]') : tr;
1587+
currTr[checked ? 'addClass' : 'removeClass'](ELEM_CHECKED); // 标记当前选中行背景色
15861588
// 若为 radio 类型,则取消其他行选中背景色
15871589
if(opts.type === 'radio'){
1588-
tr.siblings().removeClass(ELEM_CHECKED);
1590+
currTr.siblings().removeClass(ELEM_CHECKED);
15891591
}
15901592
} else if(opts.type === 'radio') {
15911593
delete item[options.checkName];

0 commit comments

Comments
 (0)