当bootgrid换页时,保存分页状态,切换到别的页面再切换回来时,恢复到保存的分页状态,而不是默认加载第一页

实现原理:
将分页数据存到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"));
    });
});
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值