后台加载给前端的table字段很多,一两百个,但是每个人关注的字段不同,有些人会设置这个defaultToolbar中的列字段,但是每次进去页面都得重新设置,很麻烦。
想法是,defaultToolbar的filter这个功能中,用户自定义显示列时保存起来,下次进入页面默认加载用户的设置。
table.render({elem: '#test',url: 'json/table/demo1.json',toolbar: 'default',cols: [function(){var arr = [{type: 'checkbox', fixed: 'left'},{field:'id', title:'ID', width:80, fixed: 'left'},{field:'username', title:'用户名', width:120},{field:'ip', title:'IP', width: 120},{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}];//初始化筛选状态var local = layui.data ('table-filter-test');layui.each(arr, function(index, item){if(item.field in local){item.hide = true; // 在本地标识中则隐藏}});return arr;}() ],done: function(){//记录筛选状态var that = this;that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function(){var input = $(this).prev()[0];var input = $(this).prev()[0];if (input.checked === true){ // 复选框取消,则加入本地缓存标识layui.data ('table-filter-lock', {key: input.name,value: !input.checked})}else { // 复选框勾上,则移除本地标识layui.data('table-filter-lock', {key: input.name, remove: true});}});}});
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号