修改layui tabile.js文件
1.找到512行p = a.elem.attr("lay-filter");在其下方添加如下代码:
[JavaScript] 纯文本查看 复制代码 // 存储表头筛选状态
// var tableFlag = window.location.pathname.replace(new RegExp('/', 'g'), "_");
var urlAddressParameter = window.location.search;
var urlParameterArr = urlAddressParameter.split('&');
var tableFlag = '';
for (let index = 0; index <= 2; index++) {
var urlValue = '';
urlValue = urlParameterArr[index].split('=');
tableFlag += urlValue[1] + '_';
}
if (typeof tableFlag !== "undefined" && tableFlag != "") {
var deploy = localStorage.getItem("TableHidden_" + tableFlag + "");
if(deploy != null){
var arr = new Boolean(deploy) ? eval(deploy) : [];
$.each(arr, function (index, ele) {
var checked = ele.check;
var key = ele.key;
var parentKey = ele.parentKey;
layui.each(a.cols, function (i1, item1) {
layui.each(item1, function (i2, item2) {
if (i1 + '-' + i2 === key) {
var hide = item2.hide;
//同步勾选列的hide值和隐藏样式
item2.hide = !checked;
i.elem.find('*[data-key="' + i.index + '-' + key + '"]')[checked ? 'removeClass' : 'addClass'](f);
//根据列的显示隐藏,同步多级表头的父级相关属性值
// if (hide != item2.hide) {
// a.setParentCol(!checked, parentKey);
// }
//重新适配尺寸
i.resize();
}
})
})
})
}
}
2.修改找571行n.on("checkbox(LAY_TABLE_TOOL_COLS)", function(e) {在其下方添加如下代码:[JavaScript] 纯文本查看 复制代码 if (typeof tableFlag !== "undefined" && tableFlag != "") {
var tableHidden = "";
$('.layui-unselect.layui-form-checkbox').each(function (index, ele) {
var key = $(ele).siblings('input').attr('data-key');
var parentkey = $(ele).siblings('input').attr('data-parentkey');
var checked = $(ele).attr('class').indexOf('layui-form-checked') !== -1 ? true : false;
tableHidden += "{'key':'" + key + "','check':" + checked + ",'parentKey':" + (parentkey ? parentkey : "''") + "},";
})
localStorage.setItem("TableHidden_" + tableFlag + "", "[" + tableHidden + "]");
}
本方法在网上流传的方法上增加了通过url参数作为存储名,用于各个页面单独存储筛选状态,解决了多页面冲突问题
|