javascript - 仅刷新数据表页面时如何清除状态

标签 javascript html datatable bootstrap-4 callback

对于页面中的数据表:我希望数据表以清晰的状态刷新(无列顺序等),但是如果通过按页面上的后退按钮打开页面,它应该保持其状态。

到目前为止我已经尝试过一些方法,它们是:

1-使用performance.nagivation.type,但无法按照我需要的方式执行它。

// Refresh page, and table with a clear state.
if (performance.navigation.type == 1) {
     // some code here
}
// Back key pressed, load parameters and columns.
else if (performance.navigation.type == 2) {
    // some code here
}

2-使用drawCallback函数,但它没有像我想象的那样工作。

drawCallback: function() {
    if (performance.navigation.type == 1) {
        table.state.clear();
    }
}

我真的很困惑,无法理解这里出了什么问题。任何帮助都会很棒。

最佳答案

好吧,实际上我做对了,但完全忘记了缓存。当我刷新页面并忽略缓存时。它按我想要的方式工作。

drawCallback: function() {
    // When page is refreshed, draw table with clear state.
    if (performance.navigation.type == 1)
        table.state.clear();
}

关于javascript - 仅刷新数据表页面时如何清除状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58428404/

相关文章:

javascript - Greasemonkey 脚本 : get matched include rule

javascript - 在 jQuery 中获取元素包含 span 标签之前的文本

html - 图像不工作

javascript - 如何制作第二个提交按钮?

c# - 检查是否没有返回数据行

javascript - 内容类型 : false and processData: false make POST empty in PHP

javascript - 拖放多个文件上传到单个文件上传

checkbox - Flutter Alert 对话框数据表 Checkbox

javascript - 显示书名的简单ajax脚本

javascript - 单击数据表分页停止事件执行