实现原理:
将分页数据存到sessionStorage里(关闭浏览器会清空数据,如果想一直存在,就存在localStorage里),页面首次加载bootgrid表格时,修改当前页数以及页面大小数据。
不同的bootgrid表格需要取不同的aaa_bootgrid_currentPage名字,否则表格之间会混淆,保存在sessionStorage里的数据每个页面都能用
本来想set当前页数和页面大小,然后再.bootgrid(“reload”)的,但是bootgrid官网好像没有set的接口
$(document).ready(function () {
let aaa_bootgrid_flag = true;
$("#bootgrid").bootgrid({
padding:1,
ajax:true,
ajaxSettings: {
method: "POST",
},
post:function ()
{
let currentPage = $("#bootgrid").bootgrid("getCurrentPage");
let pageSize = $("#bootgrid").bootgrid("getRowCount");
let str = $("#bootgrid").bootgrid("getSearchPhrase");
let sort = $("#bootgrid").bootgrid("getSortDictionary");
console.log(sort);
// 当页面加载时,尝试恢复之前的分页状态,只执行一次
if (aaa_bootgrid_flag){
let aaa_bootgrid_currentPage = sessionStorage.getItem('aaa_bootgrid_currentPage');
let aaa_bootgrid_pageSize = sessionStorage.getItem('aaa_bootgrid_pageSize');
if (aaa_bootgrid_currentPage !== null && PayContract_bootgrid_pageSize !== null) {
currentPage = aaa_bootgrid_currentPage;
pageSize = aaa_bootgrid_pageSize;
}
aaa_bootgrid_flag = false;
}
$.each(sort,function(key,value){
sortKey = key;
sortValue = value;
});
var params = {
currentPage : currentPage,
pageSize : pageSize,
str : str,
sortKey : sortKey,
sortValue : sortValue,
salescategory:"1"
};
return params;
},
rowCount:[10,20,30],
url:"${pageContext.request.contextPath}/AAA/bbb",
labels:{
all:"全部",
loading:"数据加载中",
noResults:"无显示数据",
search:"搜索",
infos:"显示第 {{ctx.start}} 条到第 {{ctx.end}} 条,共 {{ctx.total}} 条记录",
refresh : "刷新数据表"
},
}).on("loaded.rs.jquery.bootgrid",function(){
// 当表格加载完成后,保存当前的分页状态
sessionStorage.setItem('aaa_bootgrid_currentPage', $("#bootgrid").bootgrid("getCurrentPage"));
sessionStorage.setItem('aaa_bootgrid_pageSize', $("#bootgrid").bootgrid("getRowCount"));
});
});