Destroying a child row Datatable: $.detach() vs $.remove()?
Destroying a child row Datatable: $.detach() vs $.remove()?
Loren Maxwell
Posts: 462Questions: 112Answers: 10
Referencing the wonderful "Parent / child editing in child rows" blog post:
https://datatables.net/blog/2019-01-11
Under "Destroying a DataTable", it calls the following code:
function destroyChild(row) {
var table = $("table", row.child());
table.detach();
table.DataTable().destroy();
// And then hide the row
row.child.hide();
}
I'm not keying in on the purpose of table.detach();.
If I'm destroying the DataTable to prevent a memory leak, doesn't table.detach(); rather than table.remove(); run the same risk?
Or does table.DataTable().destroy(); clean it all up anyway?
And if so, why call table.detach(); or table.remove(); at all?
This question has an accepted answers - jump to answer
Answers
Good spotting! I think we could shorten it to be:
which will remove the table from the document, using jQuery's
$().remove()method. That will clean up any event handlers, so yup - go for that:Allan