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

问题描述 投票:0回答:1

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

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

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

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

javascript html datatable bootstrap-4 callback
1个回答
0
投票

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

drawCallback: function() {
    // When page is refreshed, draw table with clear state.
    if (performance.navigation.type == 1)
        table.state.clear();
}
© www.soinside.com 2019 - 2024. All rights reserved.