fixedColumns().rowIndex()
Get the row index of a row in a fixed column.
Please note - this property requires the FixedColumns extension for DataTables.
Deprecated
As of v3.2.1 this feature has been deprecated. This feature has not yet been scheduled for removal, but its use is discouraged and the alternatives discussed below should be used.
As of DataTables 1.10.11 and FixedColumns 3.2.1 this method is no longer required to obtain a row index from a node as the row()
method will accept the tr
and td
elements in the fixed column as selector arguments.
Example
Get the row index for any row clicked upon in a table (from the fixed column, or the main table):
var table = $('#myTable').DataTable();
$(table.table().container()).on( 'click', 'tr', function () {
var row = table.row( this );
console.log( row.index() );
} );
Description
When working with FixedColumns, there is additional complexity in the DataTable as the fixed columns are not technically part of the host DataTables - they just look like it! They are in fact HTML table
elements themselves, with specific styling to visually integrate them with the host table.
Since the fixed columns are the ones that the end user sees, they are also the ones that the user will interact with - for example clicking on a cell in the fixed column will give the fixed column cell and not the cell in the DataTable!
This method is provided to be able to convert from a row in the fixed columns into a DataTables row, by returning the row data index (this is not the visible index, but rather an index internal to DataTables!). That index can then be used with the row()
method to obtain a reference to the main DataTable row.
Type
function fixedColumns().rowIndex( row )
- Description:
Get the row index (
row().index()
) for atr
element, regardless of if the row is contained in a fixed column, or in the scrolling table.- Parameters:
Name Type Optional 1 row
No The row (
tr
) to get the row index of. This can be either a row in the fixed columns or in the host DataTable.- Returns:
The row index for the given row
Example
Get the row index for any row clicked upon in a table:
$(document).on( 'click', 'tr', function () {
console.log(
$('#example').DataTable().fixedColumns().rowIndex()
);
} );