Since: DataTables 1.10.8

Get the number of elements that are contained in an API instance.


If can sometimes be useful to know how many items are contained in an API's result set - a function that is provided by this method.

It is important to note that the length property cannot simply be reliably used itself to determine if the API result set contains any elements or not as the DataTables API is multi-table aware and the result set consists of nested arrays. Therefore we must flatten arrays before being able to use the length property. This method does exactly that (i.e. it is a shortcut for api.flatten().length).


function count()


Get the number of entries in an API instance's result set, regardless of multi-table grouping (e.g. any data, selected rows, etc).


The number of items in the API instance's result set


Count how many rows there are with the class selected:

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

alert( 'Rows '+table.rows( '.selected' ).count()+' are selected' );

Count the number of data entries (i.e. rows) in a table:

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

if ( ! ) {
	alert( 'Empty table' );


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