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 row
No TR
element being inserted into the document.2 data
No 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
data
is an object - if you are using arrays, thendata
is an array. Thus how you obtain the data from this parameter will depend on how the DataTable is configured.3 displayNum
No Row number in the current page of displayed rows.
4 displayIndex
No Row number in the current search set of data (i.e. over all available pages).
5 dataIndex
No DataTables' internal index for the row - see
row().index()
.
Examples
Highlight cells based on their content (object data source):
new DataTable('#myTable', {
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):
new DataTable('#myTable', {
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.