如何在没有引用的情况下销毁现有的DataTable对象?

时间:2022-06-28 18:52:41

When I create a DataTable, ($('.tableContainer table').DataTable({ ... })), I don't retain the object reference. Later on in the script, I want to destroy the table, but the only thing I know about it is the selector. Having not kept the original object reference, how do I find the table object to destroy it?

当我创建一个DataTable,($('。tableContainer table')。DataTable({...}))时,我不保留对象引用。稍后在脚本中,我想破坏表,但我唯一知道的是选择器。没有保留原始对象引用,如何找到要破坏它的表对象?

2 个解决方案

#1


To retrieve the table object instance, call DataTable on the table (just as you did when creating it), but pass it an object with bRetrieve=true.

要检索表对象实例,请在表上调用DataTable(就像创建它时一样),但是传递一个bRetrieve = true的对象。

table = $('.tableContainer table').DataTable({ 'bRetrieve':true });

This returns the original instance.

这将返回原始实例。

Next, to destroy it, you need to call fnDestroy(), not Destroy(). I don't know why this is, but it appears that any methods you want to call on the retrieved object need to be prefixed with "fn".

接下来,为了销毁它,你需要调用fnDestroy(),而不是Destroy()。我不知道为什么会这样,但是看起来你要在检索到的对象上调用的任何方法都需要以“fn”作为前缀。

table.fnDestroy();

#2


Following link might help solve your issue: 
https://datatables.net/reference/option/destroy

table = $('.tableContainer table').DataTable({ 'destroy':true });

#1


To retrieve the table object instance, call DataTable on the table (just as you did when creating it), but pass it an object with bRetrieve=true.

要检索表对象实例,请在表上调用DataTable(就像创建它时一样),但是传递一个bRetrieve = true的对象。

table = $('.tableContainer table').DataTable({ 'bRetrieve':true });

This returns the original instance.

这将返回原始实例。

Next, to destroy it, you need to call fnDestroy(), not Destroy(). I don't know why this is, but it appears that any methods you want to call on the retrieved object need to be prefixed with "fn".

接下来,为了销毁它,你需要调用fnDestroy(),而不是Destroy()。我不知道为什么会这样,但是看起来你要在检索到的对象上调用的任何方法都需要以“fn”作为前缀。

table.fnDestroy();

#2


Following link might help solve your issue: 
https://datatables.net/reference/option/destroy

table = $('.tableContainer table').DataTable({ 'destroy':true });