{hero}

destroy

Since: DataTables 1.10

Table destroy event - fired when a table is destroyed.

Description

The destroy event is fired when a DataTable is torn down, to be replaced with an enhanced HTML table (or simply removed from the DOM altogether). This can be used to remove bound events, added DOM nodes etc and can be particularly useful for plug-in authors.

This event is fired when the DataTable is destroyed by calling destroy API method or passing the destroy parameter in the initialisation object.

Please note that, as with all DataTables emitted events, this event is triggered with the dt namespace. As such, to listen for this event, you must also use the dt namespace by simply appending .dt to your event name, as shown in the example below.

This event will bubble up the document, so you can add a listener for destroy.dt to the body to capture all destroy events triggered by DataTables.

Type

function function( e, settings )

Parameters:

Example

Remove bound events on table destroy:

let table = new DataTable('#myTable');

table.on('click', 'td', function () {
	alert(this.innerHTML);
});

table.on('destroy.dt', function (e, settings) {
	table.off('click', 'td');
});

Related

The following options are directly related and may also be useful in your application development.