我为数据表创建了一个自定义过滤器。过滤器将相应地工作;我可以输入一些文本,数据表将找到任何匹配的记录。
问题是,如果用户输入文本,导航到另一个屏幕,然后返回到数据表页面,则数据表仍显示过滤器搜索返回的记录,即使过滤器搜索中的文本不再可见。
用户可以单击过滤器,然后按退格键以清除搜索,但是不必这样做。
我尝试了以下方法:
$(document).ready(function()
{
$('.searchFilter').val(''); // <-- clears the customer search filter
$('input[type=search]').val(''); // <-- thought this would help
var table = $('#example1').DataTable();
table.search('').draw(); // <-- redraw the datatable
});
以上操作无效。
我什至尝试过:
$(window).on('load', function()
{
// same code as above
});
不幸的是,这也不起作用。
我想念什么吗?为什么不重新加载数据表?我该如何解决?
答案 0 :(得分:1)
我会清除表格以使其开始,这样您就不会遇到这个问题。
$(document).ready(function()
{
$('.searchFilter').val(''); // <-- clears the customer search filter
$('input[type=search]').val(''); // <-- thought this would help
var table = $('#example1').DataTable();
table.clear() // <-- table is cleared
table.search('').draw(); // <-- redraw the datatable
});