Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 销毁数据表以重用_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript 销毁数据表以重用

Javascript 销毁数据表以重用,javascript,jquery,datatables,Javascript,Jquery,Datatables,我在数据表上有一个名为“返回”的按钮,我想清除并销毁该表,以备重用 我已经能够使用clear()和destroy()方法成功地实现这一点,但是在多次单击之后,它就停止工作了 有没有办法在同一张桌子上连续销毁/重新加载?还是我找错树了 这类工作的代码是: { text: 'Go Back', action: function(e, dt, node, config) { $("#table1_wrapper").swap({ t

我在数据表上有一个名为“返回”的按钮,我想清除并销毁该表,以备重用

我已经能够使用clear()和destroy()方法成功地实现这一点,但是在多次单击之后,它就停止工作了

有没有办法在同一张桌子上连续销毁/重新加载?还是我找错树了

这类工作的代码是:

{
     text: 'Go Back',
     action: function(e, dt, node, config) {
          $("#table1_wrapper").swap({
               target: "adults",
               speed: 1000,
               opacity: "0.5",
          });
          reportstable.clear().draw();
          reportstable.destroy();
          reportstable.dataTable();
      }
}

我自己找到了答案。
下面的代码工作得非常好

$('#table1').dataTable( {
  "bDestroy": true  
});
$('#table1').dataTable().fnDestroy();
$('#table1').empty();

也许你的桌子上有一些按钮。如果是这样的话,这会导致一些问题。如果是这样的话,你可以用这个

function destroyDatatable(table) {
            var buttons = [];
            $.each(table.buttons()[0].inst.s.buttons,
                function () {
                    buttons.push(this);
                });
            $.each(buttons,
                function () {
                    table.buttons()[0].inst.remove(this.node);
                });
            table.destroy();
        }
我已经使用了这个功能,它工作得很好