How to clean up before calling destroy()?

How to clean up before calling destroy()?

JeffRastracJeffRastrac Posts: 1Questions: 1Answers: 0
edited November 2020 in Free community support

What is a proper way to clean up any pending datatable events or other artifacts before calling destroy()?
I am seeing symptoms that suggest that some transients are being left after the destroy() call, which is immediately followed in the code by a new instantiation of the same dataTable. I feel like I should be typing "destroy().then{...}" or otherwise implementing some sort of asynchronous completion routine.

Thanks in advance for not scolding my lack of an MWE.

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923
    edited November 2020

    This is according to the destroy() docs:

    DataTables adds a number of HTML elements, event listeners and other modifications in order to enhance the original HTML table with the features of DataTables. This method can be used to remove those enhancements and return the table to its original un-enhanced state, with the data shown in the table.

    I am seeing symptoms that suggest that some transients are being left after the destroy() call, which is immediately followed in the code by a new instantiation of the same dataTable.

    Can you provide details of what you are seeing?

    You may need to clean up any events you added. You may need to use jQuery empty() if you are changing the number of columns. See the second example in the destroy() docs.

    Kevin

This discussion has been closed.