2017-02-21 60 views
0

我对所谓的“返回”这是我想要清除和销毁表准备好重新使用销毁数据表重用

我已经能够做到这一点使用明确的数据表的按钮()和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(); 
     } 
} 

回答

1

我已经找到自己的答案。
以下代码工作正常

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

可能你的表中可能有一些按钮。如果是这样的话,就会有一些问题。如果是这种情况,你可以使用它。

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

我已经使用这个功能,它工作正常。