gpt4 book ai didi

javascript - 无法使用 search() API 的自定义正则表达式实现进行 stateSave

转载 作者:行者123 更新时间:2023-11-28 03:59:01 25 4
gpt4 key购买 nike

我通过以下方式启用了正则表达式过滤,因为默认值为 false -

$(document).ready(
function() {
var table = $('#companies').DataTable({
stateSave: true,
stateDuration: 0, //force the use of Local Storage
// other code for 'dom' & 'buttons' properties
});

table.search($(this).val(), true, true, true).draw();
});

但是,之前在页面刷新时可以正常恢复搜索参数的 stateSave 已停止工作。它仍然记得对列进行排序,这让我认为它不适用于搜索,因为正则表达式过滤器是在外部实现的。

This answer提到了 state.loaded() 的使用,但它下面的注释说这是一个草率的黑客行为,应该使用 stateSave 来代替。 Another similar question没有得到答复。

那么,如何使用 search() API 的自定义实现来保存搜索参数?

编辑 - Obfuscated fiddle JavaScript 完好无损,但删除了所有 JSP 代码。

最佳答案

基于this answerPrashant根据建议,我能够使用 state.loaded() 保存搜索词并在重新加载时填充搜索框,如下所示 -

$(document).ready(
function() {
var table = $('#companies').DataTable({
stateSave: true,
stateDuration: 0, //force the use of Local Storage
// other code for 'dom' & 'buttons' properties
});
if (searchText !== null && searchText !== "") {
table.search(searchText.search, true, true, true).draw();
} else {
table.search($(this).val(), true, true, true).draw();
}
});

$(document).on('init.dt', function(e, settings) {
var api = new $.fn.dataTable.Api(settings);
var state = api.state.loaded();
searchText = state.search;
});

关于javascript - 无法使用 search() API 的自定义正则表达式实现进行 stateSave,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47309061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com