有實(shí)力自適應(yīng)網(wǎng)站建設(shè)哪家好視頻號(hào)推廣
即點(diǎn)擊當(dāng)前表格右上角篩選圖標(biāo)后,對(duì)表頭進(jìn)行顯示隱藏勾選,再刷新頁(yè)面依然保留當(dāng)前篩選狀態(tài)。
要實(shí)現(xiàn)layui表格組件的篩選列記憶功能,可以采取以下步驟:
- 存儲(chǔ)篩選數(shù)據(jù):當(dāng)用戶進(jìn)行篩選操作時(shí),將篩選的數(shù)據(jù)以某種形式存儲(chǔ)起來(lái)??梢赃x擇將數(shù)據(jù)存儲(chǔ)到本地緩存中,或者發(fā)送到服務(wù)器端進(jìn)行存儲(chǔ)。
- 監(jiān)聽(tīng)篩選事件:使用MutationObserver或其他事件監(jiān)聽(tīng)器來(lái)監(jiān)聽(tīng)表格組件的篩選事件。當(dāng)用戶進(jìn)行篩選操作時(shí),監(jiān)聽(tīng)器會(huì)捕獲到相關(guān)的事件并執(zhí)行相應(yīng)的操作。
- 保存篩選狀態(tài):在監(jiān)聽(tīng)到篩選事件后,將篩選的狀態(tài)(如篩選的字段、篩選的條件等)保存下來(lái)。同樣可以選擇將狀態(tài)保存到本地緩存中,或者發(fā)送到服務(wù)器端進(jìn)行保存。
- 恢復(fù)篩選狀態(tài):當(dāng)用戶重新打開(kāi)頁(yè)面或刷新頁(yè)面時(shí),從本地緩存或服務(wù)器端獲取之前保存的篩選狀態(tài),并將其應(yīng)用到表格組件上。
核心代碼
, cols: [function () {var arr = [{type: 'checkbox', fixed: 'left', width: 80}, {field: 'depart_name', title: '一級(jí)管理', sort: true}, {field: 'second_user_name', title: '二級(jí)管理', sort: true, hide: true}, {field: 'butler_name', title: '三級(jí)管理', sort: true, hide: true}, {field: 'poi_name', title: '客戶名稱', sort: true}, {field: 'poi_address', title: '客戶地址', sort: true}, {field: 'poi_phone', title: '客戶電話', sort: true}, {field: 'place', title: '位置調(diào)整', templet: '#checkPoint', unresize: true, align: 'center'}, {field: 'lock', title: '操作', templet: '#checkboxTpl', unresize: true, align: 'center', width: 120}];// 初始化篩選狀態(tài)var local = layui.data('table-filter-lock');layui.each(arr, function (index, item) {if (item.field in local) {item.hide = local[item.field];}});return arr;}()],done: function () {// 記錄篩選狀態(tài)var that = this;that.elem.next().on('mousedown', 'input[lay-filter="LAY_TABLE_TOOL_COLS"]+', function () {var input = $(this).prev()[0];// 此處表名可任意定義layui.data('table-filter-lock', {key: input.name, value: input.checked})});}
@漏刻有時(shí)