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

时间:2019-10-17 08:42:30

标签: 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();
    }
}

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

2 个答案:

答案 0 :(得分:0)

嗯,实际上我做的正确,但是完全忘记了缓存。当我刷新页面时忽略缓存。它按我的意愿工作。

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

答案 1 :(得分:0)

您可以尝试:

var table = $('#example').DataTable({stateSave: false});
相关问题