rowCallback
Row draw callback.
Description
This callback allows you to 'post process' each row after it have been generated for each table draw, but before it is rendered into the document. This means that the contents of the row might not have dimensions ($().width() for example) if it is not already in the document.
This function might be used for setting the row class name or otherwise manipulating the row's tr element (although note that createdRow can often be more efficient).
Type
function rowCallback( row, data, displayNum, displayIndex, dataIndex )
- Parameters:
Name Type Optional 1 rowNo TRelement being inserted into the document.2 dataNo Data source for the row. Important: This parameter is the original data source object that is used for the row. If you are using objects, then
datais an object - if you are using arrays, thendatais an array. Thus how you obtain the data from this parameter will depend on how the DataTable is configured.3 displayNumNo Row number in the current page of displayed rows.
4 displayIndexNo Row number in the current search set of data (i.e. over all available pages).
5 dataIndexNo DataTables' internal index for the row - see
row().index().
Examples
Highlight cells based on their content (object data source):
$('#example').dataTable( {
"rowCallback": function( row, data ) {
if ( data.grade == "A" ) {
$('td:eq(4)', row).html( '<b>A</b>' );
}
}
} );Highlight cells based on their content (array data source):
$('#example').dataTable( {
"rowCallback": function( row, data ) {
if ( data[4] == "A" ) {
$('td:eq(4)', row).html( '<b>A</b>' );
}
}
} );Related
The following options are directly related and may also be useful in your application development.