mirror of https://github.com/layui/layui
修复 table 全选时,禁用行仍有选中样式的问题 (#1436)
* 修复 table 全选时,禁用行仍有选中样式的问题,close `#I8KPUT` close https://gitee.com/layui/layui/issues/I8KPUT * 优化 `table.setRowChecked()` 查找当前行细节,减少全选时的元素查找频率 --------- Co-authored-by: 贤心 <3277200+sentsim@users.noreply.github.com>pull/1442/head
parent
36808582e3
commit
f73501c157
|
@ -1560,8 +1560,9 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
Class.prototype.setRowChecked = function(opts){
|
Class.prototype.setRowChecked = function(opts){
|
||||||
var that = this;
|
var that = this;
|
||||||
var options = that.config;
|
var options = that.config;
|
||||||
|
var isCheckAll = opts.index === 'all';
|
||||||
var tr = that.layBody.find('tr'+ (
|
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){
|
layui.each(thisData, function(i, item){
|
||||||
if(layui.type(item) === 'array' || item[options.disabledName]) return; // 空项
|
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]);
|
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 类型,则取消其他行选中背景色
|
// 若为 radio 类型,则取消其他行选中背景色
|
||||||
if(opts.type === 'radio'){
|
if(opts.type === 'radio'){
|
||||||
tr.siblings().removeClass(ELEM_CHECKED);
|
currTr.siblings().removeClass(ELEM_CHECKED);
|
||||||
}
|
}
|
||||||
} else if(opts.type === 'radio') {
|
} else if(opts.type === 'radio') {
|
||||||
delete item[options.checkName];
|
delete item[options.checkName];
|
||||||
|
|
Loading…
Reference in New Issue