fastadmin 表格记忆隐藏的列,刷新依然保持

比如我们在列表页选择隐藏某几列,但是刷新后会依然按照js文件中设定的列参数值显示或者隐藏

 解决方法:

首先:在define中引入cookie库

define(['jquery', 'bootstrap', 'backend', 'table', 'form','columntoggle','layui','cookie'], function ($, undefined, Backend, Table, Form,Columntoggle,undefined) {

然后在

// 初始化表格
table.bootstrapTable({

在 onLoadSuccess:function(){ //中添加代码块
  //代码块
}
,或者在下面添加代码块亲测都可

代码块内容:

var cookiefilenames = 'customer_index_controller';  //对应控制器列表页
table.on('column-switch.bs.table',function(e,json){
    var hideColumns = [];
    $.each(table.bootstrapTable('getHiddenColumns'),function(i,item){
        hideColumns.push(item.field);
    });
    $.cookie('texie_'+cookiefilenames,JSON.stringify(hideColumns),{expires:365,path:'/'});
});
if($.cookie('texie_'+cookiefilenames)){
    $.each(JSON.parse($.cookie('texie_'+cookiefilenames)),function(i,item){
        table.bootstrapTable('hideColumn',item);
    });
}

 

posted @ 2023-07-24 17:11  温柔的风  阅读(159)  评论(0编辑  收藏  举报