createdRow
Callback for whenever a TR element is created for the table's body.
Description
This callback is executed when a TR element is created (and all TD child elements have been inserted), or registered if using a DOM source, allowing manipulation of the TR element.
This is particularly useful when using deferred rendering (deferRender) or server-side processing (serverSide) so you can add events, class name information or otherwise format the row when it is created.
Type
createdRow( row, data, dataIndex, cells )
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | row | No | |
| |||
| 2 | data | No | |
Raw data source (array or object) for this row | |||
| 3 | dataIndex | No | |
The index of the row in DataTables' internal storage. | |||
| 4 | cells | No | |
Since 1.10.17: The cells for the column. | |||
Example
Add a class to the row, conditionally based on the row's data:
new DataTable('#myTable', {
createdRow: function (row, data, dataIndex) {
if (data[4] == 'A') {
$(row).addClass('important');
}
}
});Related
The following options are directly related and may also be useful in your application development.