{hero}

dt-error

Since: DataTables 2.0

Error event - An error has occurred during DataTables' processing of data.

Description

Error control is an important consideration in any complex application, and DataTables provides this event to allow you to hook your application's own error handling into DataTables. For example you could trigger an Ajax call that will log an error for investigation, or use the error event to show a custom error message to the end user.

This event goes hand in hand with the DataTable.ext.errMode option which controls how DataTables handles errors. That static option can take one of four values:

  • alert (default) - Alert the error
  • throw - Throw a Javascript error
  • none - Do nothing (you would want to use this error in this case)
  • function - A function common to all DataTables on the page that is called when an error occurs.

Please note that, as with all DataTables emitted events, the event object has a DataTables API instance available on it (the first parameter). Additionally, the events are 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 dt-error.dt to the body to capture all error events triggered by DataTables.

Before DataTables 2, this event was simply called error, however, that would cause onerror DOM0 event handlers to trigger, causing spurious logging if monitoring your site for script errors.

Type

function function( e, settings, techNote, message )

Parameters:

Example

Use the event as a custom error handler:

DataTable.ext.errMode = 'none';

$('#example')
	.on('error.dt', function (e, settings, techNote, message) {
		console.log('An error has been reported by DataTables: ', message);
	})
	.DataTable();

Related

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