error

Since: DataTables 1.10.5

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 $.fn.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, 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.

Type

function function( e, settings, techNote, message )

Parameters:

Example

Use the event as a custom error handler:

$.fn.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.