我正在使用 jquery datatable版本1.9.4。我想要的是如果用户进入第三页并刷新页面,他应该登陆第三页。为了完成这个任务,我使用的是saveState api。
$JQ( document ).ready( function() {
var oTable=$JQ('#t_id').dataTable( {
"oLanguage" : <jsp:include flush='true' page='...' /> ,
"bAutoWidth": false,
<% if(...){ %>
"aoColumns": [
{ "sWidth": "20px",bSortable : false },
{ "sWidth": "45px" },
{ "sWidth": "180px" },
{ "sWidth": "120px", "iDataSort": 10 },
{ "sWidth": "120px", "iDataSort": 11},
{ "sWidth": "100px" },
{ "sWidth": "100px" },
{ "sWidth": "80px" },
{ "sWidth": "60px" },
{ "sWidth": "20px",bSortable : false },
{ "sWidth": "0px" },// sort by post
{ "sWidth": "0px" } // sort by close
],
<%
} else {
%>
"aoColumns": [
<% if (.... )) { %>
{ "sWidth": "5px" ,bSortable : false },
<% } %>
{ "sWidth": "45px" },
{ "sWidth": "200px" },
{ "sWidth": "100px" },
{ "sWidth": "100px", "iDataSort": 7 },
{ "sWidth": "100px", "iDataSort": 8},
{ "sWidth": "140px" },
{ "sWidth": "80px",bSortable : false },
{ "sWidth": "0px" },// sort by post
{ "sWidth": "0px" } // sort by close
],
<% }%>
"bstateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem('DataTables_' + window.location.pathname, JSON.stringify(oData));
},
"fnStateLoad": function (oSettings) {
var data = localStorage.getItem('DataTables_' + window.location.pathname);
return JSON.parse(data);
},
"fnInitComplete": function() {
// after table is redrawndo something here
initenhanced();
},
"bFilter": true,
"aaSorting": [],
"sDom": '<"top"<"clear">>rt<"bottom"lip<"clear">>'
} );
}
如果我监视本地存储,则每当页面发生更改时,都会存储数据表的当前状态,但每当刷新页面时,数据表都会加载初始状态而不是保存状态。谁能告诉我哪里可能出错了?
注意:HTML中的表格是从for循环中的jsp标记填充的。