DataTables logo DataTables

This site contains the legacy documentation for DataTables v1.9 and earlier for reference only.
DataTables 1.9 was End Of Life in 2014. Do not use it for new work.
The current release of DataTables can always be found on

API plug-ins

The API functions that DataTables provides can be exceptionally useful for creating advanced interactions, however there may be times when an API function which you want to use isn't provided by default. To this end, DataTables provides a method by which new API functions can be added. Further to this, it also exposes its internal (private) methods through the 'oApi' object, which can assist in creating plug-ins.

The API plug-in mechanism revolves around the $.fn.dataTableExt.oApi object, to which new API methods can be attached. The new API function is passed all of the parameters which the function is called with, but each shifted by one and the first argument is an object with the settings information for the table in question (for full documentation of this object, please refer to the DataTables source code) - please refer to the example below for a demonstration of this.

The following example shows how to add a new API function called fnGetHiddenTrNodes(), which will create a list of all TR nodes in the table which are not currently visible (useful for building forms):

$.fn.dataTableExt.oApi.fnGetHiddenTrNodes = function ( oSettings, arg1, arg2 )
	/* Note the use of a DataTables 'private' function thought the 'oApi' object */
	var anNodes = this.oApi._fnGetTrNodes( oSettings );
	var anDisplay = $('tbody tr', oSettings.nTable);
	/* Remove nodes which are being displayed */
	for ( var i=0 ; i<anDisplay.length ; i++ )
		var iIndex = jQuery.inArray( anDisplay[i], anNodes );
		if ( iIndex != -1 )
			anNodes.splice( iIndex, 1 );
	/* Fire back the array to the caller */
	return anNodes;

/* Called with */
oTableObject.fnGetHiddenTrNodes( arg1, arg2 );