5 Star 2 Fork 1

lhtzbj12 / bootstrap-table-maintainColSwitch.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bootstrap-table-maintainColSwitch.min.js 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
lhtzbj12 提交于 2017-09-12 21:26 . 增加注释
/*!
* @author: lihaitao
* @webSite: http://blog.csdn.net/lhtzbj12/
* @version: v1.0.0
* @opensource:https://gitee.com/lhtzbj12/bootstrap-table-maintainColSwitch.js
* @description: 扩展Bootstrap-table插件,通过showColumns显示隐藏列时将设置保存到cookie或者数据库,下次打开时仍保持
*/
(function(c){c.extend(c.fn.bootstrapTable.defaults,{maintainColSwitch:false});var a=c.fn.bootstrapTable.Constructor,b=a.prototype.initTable;a.prototype.initTable=function(){var g=this;b.apply(this,Array.prototype.slice.apply(arguments));var d={initShowColumns:[],cookieKey:window.location.pathname.replace(/\/|\./g,"_")+"_colSwitch_"+g.$el.prop("id"),cookieExpires:7,onSave:function(h){return false},onLoad:function(){return false}};if(g.options.showColumns&&g.options.maintainColSwitch){g.options.maintainColSwitch=c.extend(d,g.options.maintainColSwitch)}else{return}var e=[];if(g.options.maintainColSwitch.initShowColumns.length>0){e=g.options.maintainColSwitch.initShowColumns}else{var f=c.cookie(g.options.maintainColSwitch.cookieKey);if(f){e=f.split("|")}}if(e.length>0){c(g.options.columns[0]).each(function(h,k){if(k.field==="state"){return true}var j=c(e).filter(function(i,l){return l===k.field});k.visible=j.length>0});if(g.options.maintainColSwitch.onLoad){g.options.maintainColSwitch.onLoad()}}g.$el.on("column-switch.bs.table",function(l,k,j){var i=c(this).bootstrapTable("getOptions");var h=c(i.columns[0]).map(function(m,n){return n.visible===true&&n.field!=="state"?n.field:null}).get();c.cookie(i.maintainColSwitch.cookieKey,h.join("|"),{expires:i.maintainColSwitch.cookieExpires});if(i.maintainColSwitch.onSave){i.maintainColSwitch.onSave(h)}});g.$el.on("load-success.bs.table",function(i){var h=g.$toolbar.find(".keep-open");if(e.length>0&&e.length<=g.options.minimumCountColumns){h.find("input:checked").prop("disabled",true)}})}})(jQuery);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/lhtzbj12/bootstrap-table-maintainColSwitch.js.git
git@gitee.com:lhtzbj12/bootstrap-table-maintainColSwitch.js.git
lhtzbj12
bootstrap-table-maintainColSwitch.js
bootstrap-table-maintainColSwitch.js
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891