layui table默认跳页后不存在源页面选中的状态。如果要实现记录源页面的选中状态,需要定义一个全局变量来记录数据选中状态。
1、修改table.js
;layui.define(["laytpl", "laypage", "layer", "form"], function (e) {
"use strict";
var t = layui.$, i = layui.laytpl, a = layui.laypage, l = layui.layer, n = layui.form, o = layui.hint(),
r = layui.device(), d = {
//layuiPageCheckedIds变量记录选中的数据id,格式是“,1,2,3,4,”的字符串
config: {
checkName: "LAY_CHECKED", indexName: "LAY_TABLE_INDEX", layuiPageCheckedIds: ","},
cache: {
},
index: layui.table ? layui.table.index + 1e4 : 0,
set: function (e) {
var i = this;
return i.config = t.extend({
}, i.config, e), i
},
on: function (e, t) {
return layui.onevent.call(this, s, e, t)
}
}
...
S.prototype.pullData = function (e, i) {
var a = this, n = a.config, o = n.request, r = n.response, d = function () {
"object" == typeof n.initSort && a.sort(n.initSort.field, n.initSort.type)
};
if (a.startTime = (new Date).getTime(), n.url) {
var c = {
};
//在发送请求前将选中的数据放入条件中
if(n.layuiPageCheckedIds != undefined && "" != n.layuiPageCheckedIds){
n.where.layuiCheckedIds = n.layuiPageCheckedIds;
}
if(tableRender){
var currPageNumber = getPageNumber();
c[o.pageName] = currPageNumber;
tableRender =