data()

Since: DataTables 1.10

Get the data for the whole table.

Description

This method provides access to the raw data that is used for each row in the tables in the API's context. The result set contains the raw data (be it arrays or objects), with each row defined by an entry in the API's result set. The order of the rows is the row data index (i.e. the order the data was originally read into the table).

If you modify the data contained in the returned array, ensure that you use the rows().invalidate(), row().invalidate() or any of the other invalidation methods to cause DataTables to notice the change and re-read the data source.

Please note that the rows().data() method can also provide full access to this data, but in a more flexible manner as it allows row ordering, paging and searching modifications in the result set through the selector-modifier options object. For example rows({'order':'index'}).data() is exactly the same as data() - both are in data index order, while rows().data() will return the full data set, but in the current display order (as defined by order()).

Type

function data()

Description:

Retrieve the data for the whole table, in row index order.

Returns:

DataTables API instance with the data for each row from the table in the result set.

Examples

Show an alert with how many rows of data are in the table:

var table = $('#example').DataTable();

alert( 'There are'+table.data().length+' row(s) of data in this table' );

Modify the data and then invalidate the display to redraw:

var table = $('#example').DataTable();

// Increment a counter for each row
table.data().each( function (d) {
	d.counter++;
} );

// Invalidate all rows and redraw
table.rows().invalidate().draw();

Related

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