Since: DataTables 1.10

Reduce an Api instance to a single context and result set.


The DataTables API is designed to work with multiple tables (contexts) in a single API instance, which can often be useful, but there times when you want to work with just a single table and benefit from the reduced complexity that invites (a scalar rather than vector).

The API's selectors methods will all provide their result sets in a 2D array format, with the outer array used to identify each table in the context, while the inner array contains that table's results from the selector. You can readily loop over each table if needed, but if you are using just a single table, this method can be used to reduce the API instance to just the table in question.

As an illustrative example, the rows() method will return the 2D array format described above, with the the inner array data containing the row indexes selected. For simple manipulation of a single table we want just a 1D array which contains the selected row indexes, and the API instance's context set to the table in question. This is exactly the ability the eq() method provides.


function eq( idx )


Reduce an API instance to a single context and result set, based on a given index. This can be useful for simplifying some interactions with the API.


New DataTables API instance with the context and result set containing the table and data for the index specified, or null if no matching index was available.


Add a class to a row, based on a conditional expression:

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

table.rows().eq( 0 ).each( function (idx) {
	var row = table.row( idx );

	if ( row.data().grade === 'A' ) {
		row.node().to$().addClass( 'gradeA' );
} );

Display the child rows for all rows in the table:

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

table.rows().eq( 0 ).each( function (idx) {
	table.row( idx ).child.show();
} );