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 DataTables.net.

Javascript API

Although most of the time your Javascript interaction with DataTables will be done using the initialisation object as described in the Usage section of this site, there are times at which you might find it useful to have some external control of the table. The following functions are available from the jQuery.dataTable object.

There are also a number of plug-in API functions available which extend the capabilities of DataTables beyond the built-in functions described on this page.

Note for those using server-side processing: A number of the API functions make the assumption that data storage it done on the client-side, rather than the server-side. As such functions such as fnAddData and fnDeleteRow will not effect the data held on your database. Indeed DataTables does not know if you are even using a database! As such, you must make the required calls to the server to manipulate your data as required, and then simply redraw the table (fnDraw) to view the new data.

$
Show details

Perform a jQuery selector action on the table's TR elements (from the tbody) and return the resulting jQuery object.

_
Show details

Almost identical to $ in operation, but in this case returns the data for the matched rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes rather than any descendants, so the data can be obtained for the row/cell. If matching rows are found, the data returned is the original data array/object that was used to create the row (or a generated array if from a DOM source).

This method is often useful in-combination with $ where both functions are given the same parameters and the array indexes will match identically.

fnAddData
Show details

Add a single new row or multiple rows of data to the table. Please note that this is suitable for client-side processing only - if you are using server-side processing (i.e. "bServerSide": true), then to add data, you must add it to the data source, i.e. the server-side, through an Ajax call.

fnAdjustColumnSizing
Show details

This function will make DataTables recalculate the column sizes, based on the data contained in the table and the sizes applied to the columns (in the DOM, CSS or through the sWidth parameter). This can be useful when the width of the table's parent element changes (for example a window resize).

fnClearTable
Show details

Quickly and simply clear a table

fnClose
Show details

The exact opposite of 'opening' a row, this function will close any rows which are currently 'open'.

fnDeleteRow
Show details

Remove a row for the table

fnDestroy
Show details

Restore the table to it's original state in the DOM by removing all of DataTables enhancements, alterations to the DOM structure of the table and event listeners.

fnDraw
Show details

Redraw the table

fnFilter
Show details

Filter the input based on data

fnGetData
Show details

Get the data for the whole table, an individual row or an individual cell based on the provided parameters.

fnGetNodes
Show details

Get an array of the TR nodes that are used in the table's body. Note that you will typically want to use the '$' API method in preference to this as it is more flexible.

fnGetPosition
Show details

Get the array indexes of a particular cell from it's DOM element and column index including hidden columns

fnIsOpen
Show details

Check to see if a row is 'open' or not.

fnOpen
Show details

This function will place a new row directly after a row which is currently on display on the page, with the HTML contents that is passed into the function. This can be used, for example, to ask for confirmation that a particular record should be deleted.

fnPageChange
Show details

Change the pagination - provides the internal logic for pagination in a simple API function. With this function you can have a DataTables table go to the next, previous, first or last pages.

fnSetColumnVis
Show details

Show a particular column

fnSettings
Show details

Get the settings for a particular table for external manipulation

fnSort
Show details

Sort the table by a particular column

fnSortListener
Show details

Attach a sort listener to an element for a given column

fnUpdate
Show details

Update a table cell or row - this method will accept either a single value to update the cell with, an array of values with one element for each column or an object in the same format as the original data source. The function is self-referencing in order to make the multi column updates easier.

fnVersionCheck
Show details

Provide a common method for plug-ins to check the version of DataTables being used, in order to ensure compatibility.

Static methods

As well as the functions above which apply to individual tables, DataTables provides a number of static functions which give general information about the use of DataTables on the page. These functions can be accessed through the object $.fn.dataTable.{functionName}.

fnVersionCheck
Show details

Provide a common method for plug-ins to check the version of DataTables being used, in order to ensure compatibility.

fnIsDataTable
Show details

Check if a TABLE node is a DataTable table already or not.

fnTables
Show details

Get all DataTable tables that have been initialised - optionally you can select to get only currently visible tables.