当用户点击后退按钮(没有stateSave选项)时,让DataTable保持状态 [英] Getting DataTables to keep its state when the user clicks the back button (without the stateSave option)

查看:439
本文介绍了当用户点击后退按钮(没有stateSave选项)时,让DataTable保持状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome和Edge中遇到的问题:

The problem I'm experiencing in Chrome and Edge:


  1. 转到 https://datatables.net/examples/basic_init/zero_configuration.html

  2. 按表格排序列(例如年龄)

  3. 使用表格底部的分页界面转到其他页面

  4. 点击一个的左侧导航链接(例如常见问题解答或下载)

  5. 点击浏览器的后退按钮,观察表现在恢复到原始状态(按名称列,第1页)

  1. Go to https://datatables.net/examples/basic_init/zero_configuration.html
  2. Sort the table by some column (e.g. "Age")
  3. Use the pagination interface at the bottom of the table to go to one of the other pages
  4. Click on one of the navigation links to the left (e.g. "FAQs" or "Download")
  5. Click the browser's back button and observe that the table is now back to its original state (sorted by the "Name" column and on page 1)

在Firefox中,表仍然按正确的列排序,仍在正确的页面上。我如何使Chrome和Edge的行为方式如此?

In Firefox, the table is still sorted by the correct column and is still on the correct page. How can I make Chrome and Edge also behave this way?

我知道DataTables的 stateSave 选项(文档示例),但问题是当用户浏览网站时,然后单击链接以转到具有DataTables表的页面,则会将它们重新放入在这种情况下也是这样。我只希望用户使用浏览器的后退按钮将其恢复到相同的状态。

I know DataTables has its stateSave option (documentation and example), but the problem with that is when the user navigates around the site and then clicks a link to go to the page that has the DataTables table, it will put them back into the same state in that scenario too. I only want the user to be put back into the same state if they use their browser's back button.

推荐答案

a href =http://stackoverflow.com/questions/30797848/jquery1-8-datatables-saving-state-on-click-of-a-button> post 您可以清除保存的状态,当你点击导航到页面的链接

Based on this post you could clear the saved state when you click on the link that leads you to the page with the table

请参见示例 here

$(document).ready(function() {
    $('#example').DataTable( {
        "paging":   true,
        "ordering": true,
        "info":     false,
        stateSave: true
    } );
} );

$(".table_link").on("click", function(){
  $('#example').DataTable().state.clear();
});

这篇关于当用户点击后退按钮(没有stateSave选项)时,让DataTable保持状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆