{hero}

row().index()

Since: DataTables 1.10

Get the row index of the selected row.

Description

DataTables stores the data for rows and columns in internal indexes for fast ordering, searching etc. It can be useful at times to know what these indexes are, as they can be used for efficient selectors in the row(), column() and other API methods which use selectors.

This method is used to retrieve the indexes of the selected rows which can then be used as part of a selector to update data.

Type

function row().index()

Description:

Get the row index of the row column.

Returns:

Row index

Examples

Show an alert with the row index that was clicked upon:

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

$('#example tbody').on('click', 'tr', function () {
	alert('Row index: ' + table.row(this).index());
});

Use the selected row as part of a cells() selector.:

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

$('#example tbody').on('click', 'tr', function () {
	var idx = table.row(this).index();

	table
		.cell(idx, 0) // note that you could actually pass in 'this' as the row selector!
		.data('Updated')
		.draw();
});

Related

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