layui快取當前頁和批量刪除 table.checkStatus
html
<div class="layui-card"> <!--<div class="layui-card-header">示例表頭</div>--> <div class="layui-card-body"> <table class="layui-hide" id="LAY-table-operate" lay-filter="LAY-table-operate"></table> <script type="text/html" id="test-table-switchTpl"> <input type="checkbox" name="enabled" lay-skin="switch" lay-text="啟用|禁用" lay-filter="test-table-enabledDemo" value="{{ d.enabled }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.enabled== 1 ? 'checked' : '' }}> </script> <button id="J_bulkDelete" class="layui-btn layui-btn-xs layui-btn-danger margin-top10" title="批量刪除規則"> <!--<i class="layui-icon"></i>--> 批量刪除</button> </div> <script type="text/html" id="test-table-operate-barDemo"> <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">檢視</a> <a class="layui-btn layui-btn-xs" lay-event="edit">編輯</a> <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">刪除</a> </script> </div>
layui.use(['admin', 'table'], function () { var table = layui.table, $ = layui.jquery, t, config, cur_page = $.cookie("cur_page") || 1; config = { elem: '#LAY-table-operate', // url: window.CONTEXT_PATH + "/monitor/listURIRules", cellMinWidth: 30, // 全域性定義常規單元格的最小寬度,layui 2.2.1 新增, cols: [[ {type: "checkbox", fixed: "left"}, {field: 'id', width: 40, title: 'ID', sort: true}, {field: 'uri', title: '介面URI'}, {field: 'name', title: '介面描述'}, {field: 'scan_freq', width: 40, title: '掃描頻率'}, {field: 'response_seconds', width: 60, title: '響應'}, // {field:'email', title: '郵箱'}, // {field:'mobile', title: '手機號'}, {field: 'enabled', title: '啟用', width: 80, templet: '#test-table-switchTpl', unresize: true}, {width: 178, align: 'center', fixed: 'right', toolbar: '#test-table-operate-barDemo'} ]], page: {curr: 1, limit: 10},//注意這裡預設寫的第一頁
done: function (res, cur_page, count) {
// console.log(res)
// console.log(cur_page)
// console.log(count)
var pager = t.config.page, $aa;
console.log(pager);
var $pager = $("#" + pager.elem);//整個頁碼元素盒子
$aa = $pager.find("a"); //頁碼的左右箭頭
console.log($aa)
$aa.on("click", function (e) {
var cur = this.getAttribute("data-page");
$.cookie("cur_page", cur); //把當前頁存入快取
});
var cp = parseInt($.cookie("cur_page")), $input = $pager.find(".layui-input"), //到第幾頁的輸入框
$btn = $pager.find(".layui-laypage-btn"); //確定按鈕
if (cur_page !== cp) {
$input.val(cp);
// trigger($btn.get(0), "click");
}
$btn.on("click", function () { //點選確定時快取頁變為輸入的頁碼
$.cookie("cur_page", $input.val());
});
$input.on("keydown", function (e) {
if (e.keyCode === 13) {
e.preventDefault();
$.cookie("cur_page", $input.val());
}
});
/**
* 批量刪除規則
*/
var $del = $("#J_bulkDelete");
$del.off("click", "**");
$del.on("click", function() {
var checkStatus = table.checkStatus('LAY-table-operate'),
checkData = checkStatus.data; //得到選中的資料
console.log(checkData);
if (checkData.length === 0) {
return layer.msg('請選擇資料');
}
layer.confirm('確定刪除嗎?', function (index) {
var reqBody = checkData.reduce(function(acc, cur) {
acc += cur.id + ",";
return acc;
}, "");
reqBody = reqBody.substr(0, reqBody.length-1);
console.log(reqBody);
$.ajax({
type: 'POST',
url: window.CONTEXT_PATH + "/monitor/bulkDeleteRule",
processData: false,
data: reqBody
}).done(function(data) {
reload_table({});
layer.msg("刪除了" + data.count + "條規則");
});
});
});
},
text: "載入異常"
};
config.url = window.CONTEXT_PATH + "/monitor/listURIRules";
if (param !== undefined) {
config.url += '?' + $.param(param);
}
// 設定渲染表格 初始顯示頁碼
config.page.curr = cur_page;
t = table.render(config);
-----------------------------------
©著作權歸作者所有:來自51CTO部落格作者mzh9112的原創作品,如需轉載,請註明出處,否則將追究法律責任
layui表格id, lay-filter命名 必須以 LAY-table- 開頭 layui checkbox 批量刪除 table.checkStatus
https://blog.51cto.com/u_11658127/3404611