{hero}

off()

Since: DataTables 1.10

Table events removal.

Description

DataTables can trigger a number of events which can be useful for taking action when DataTables performs those events. For example, it is often useful to know when an Ajax event occurs (xhr), so you can add additional data to the JSON payload.

DataTables provides three methods for working with DataTables events, matching the core jQuery event methods:

  • on() - Listen for events
  • off() - Stop listening for events
  • one() - Listen for a single event.

This off() method is used to remove a listener that has already been attached to a DataTable. Simply pass in the event you wish to remove the listener for, and optionally the specific function if you want to remove only a single event listener.

Type

function off( event [, callback] )

Description:

Remove event listeners that have previously been added with on().

Parameters:
Returns:

DataTables API instance

Example

Listen for only the first xhr event from DataTables:

var table = new DataTable('#myTable', {
	ajax: '/data',
	serverSide: true
});

table.on('xhr', function (e, settings, json) {
	table.off('xhr');
	console.log('Ajax event occurred. Returned data: ', json);
});

// note that this is the same effect as using `table.one(...);`

Related

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