我在 Chrome 和 Edge 中遇到的问题:
- Go to https://datatables.net/examples/basic_init/zero_configuration.html https://datatables.net/examples/basic_init/zero_configuration.html
- 按某些列对表格进行排序(例如“年龄”)
- 使用表格底部的分页界面转到其他页面之一
- 单击左侧的导航链接之一(例如“常见问题解答”或“下载”)
- 单击浏览器的后退按钮,观察表现在已恢复到其原始状态(按第 1 页上的“名称”列排序)
在 Firefox 中,表格仍然按正确的列排序,并且仍然位于正确的页面上。我怎样才能让 Chrome 和 Edge 也有这样的行为?
我知道 DataTables 有它的stateSave
选项 (文档 https://datatables.net/reference/option/stateSave and example https://datatables.net/examples/basic_init/state_save.html),但问题是,当用户浏览网站,然后单击链接转到包含 DataTables 表的页面时,在该场景中,它也会将它们恢复到相同的状态。我只希望用户在使用浏览器的后退按钮时回到相同的状态。
基于此post https://stackoverflow.com/questions/30797848/jquery1-8-datatables-saving-state-on-click-of-a-button当您单击引导您进入包含表格的页面的链接时,您可以清除保存的状态
参见示例here http://codepen.io/dex3844/pen/zoKgqB?editors=0010
$(document).ready(function() {
$('#example').DataTable( {
"paging": true,
"ordering": true,
"info": false,
stateSave: true
} );
} );
$(".table_link").on("click", function(){
$('#example').DataTable().state.clear();
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)