DataTables .draw()无法正确触发 [英] DataTables .draw() not firing properly

查看:981
本文介绍了DataTables .draw()无法正确触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以当单击清除按钮时,我有一个试图重新渲染的数据表.

Okay, so I have a DataTable that I'm trying to re-render when the clear button is clicked.

当我通过自定义过滤器过滤表格时,它会按预期工作.但是,当我单击清除"时,所有输入均按预期清除,但表未重绘.而是,该表仍显示未找到匹配的记录".在控制台中不会引发任何错误,并且相同的代码在另一个模板中也可以工作.

When I filter the table through my custom, filters, it works as expected. However, when I click 'Clear' all the inputs are cleared as expected, but the table doesn't get redrawn. Rather, the table still displays 'No Matching Records Found'. There are no errors being thrown in the console and the same code works in another template.

有什么想法吗?

var table = $('#pages').DataTable({
  'ordering': true,
  "columnDefs": [
    { "name": "title", "targets" : 0},
    { "name": "path", "targets" : 1 },
    { "name": "created", "targets" : 2 },
    { "name": "updated", "targets" : 3 },
    { "name": "creator", "targets" : 4 },
    { "name": "templateName", "targets" : 5 },
    { "name": "status", "targets" : 6 },
    { "name": "includeOnMenu", "targets" : 7 },
  ],
    "dom": 'tip'  
});
$('.clear-filter').click(function() {
  $("#filter :input").each(function() {
    this.value = "";
  });
  table.draw();
});

推荐答案

您应该可以在table.draw();之前使用table.destroy();.您可能在进行表格绘制之前以某种方式过滤",这导致了此问题. table.destroy();将删除所有过滤条件,然后您可以从头开始绘制.

You should be able to use table.destroy(); immediately before table.draw();. It's likely that you're "filtering" somehow before you do the table draw, which is causing this problem. table.destroy(); will take out any filtering and then you can draw from scratch.

https://datatables.net/reference/api/destroy()

这篇关于DataTables .draw()无法正确触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆