{hero}

rows()

Since: DataTables 1.10

Select multiple rows from a table.

Description

Working with rows is a fundamental part of DataTables, and you want to be able to easily select the rows that you want from the table. This method is the row counterpart to the columns() and cells() methods for working with columns and cells in the table, respectively. Using a selector and the selector-modifier option the rows at the table can be obtained with this method's own chained methods providing the ability to get the data from the rows, the row nodes and to invalidate the data, among other actions.

While this rows() method provides access to multiple rows with a single call, its singular counterpart row() is used to select and manipulate a single row at a time, allowing finer gain control and additional methods not available in the plural method such as updating data and working with child rows.

The method has two forms, reflecting the fact the rows can be selected in multiple different ways as your implementation demands:

Types

function rows( [ modifier ] )

Description:

Select all rows

Parameters:
Returns:

DataTables API instance with selected rows

function rows( rowSelector [, modifier ] )

Description:

Select rows found by a row selector

Parameters:
Returns:

DataTables API instance with selected rows in the result set

Examples

Select all rows:

let table = new DataTable('#myTable');

let allRows = table.rows();

Select row with a given id:

let rows = table.rows('#myId');

Select all rows with a specific class:

let rows = table.rows('.myClass');

Select rows of given indexes:

let rows = table.rows([0, 1]);

Select rows with matched data using a function:

let rows = table.rows((idx, data) => data.location === 'Edinburgh');

Select all rows in the search set using a selector modifier:

let rows = table.rows({
	search: 'applied'
});

Related

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