When using server-side processing on a DataTable, there is a mechanism to add an ID, class, or data-*
attribute to the table row (<tr>
) by including the DT_RowId
, DT_RowClass
or DT_RowData
properties, respectively, to the JSON data for each row: .html.
Is there a similar (or any) mechanism for adding additional markup to the table columns (<td>
)?
When using server-side processing on a DataTable, there is a mechanism to add an ID, class, or data-*
attribute to the table row (<tr>
) by including the DT_RowId
, DT_RowClass
or DT_RowData
properties, respectively, to the JSON data for each row: https://datatables/examples/server_side/ids.html.
Is there a similar (or any) mechanism for adding additional markup to the table columns (<td>
)?
2 Answers
Reset to default 3You can add classes to columns like so, but not sure if this gets you where you want to go:
var all_data = data;
$("#example").DataTable({
"data": all_data,
"aoColumns": [{
"data": 'cat_code',
"className": "lang_body_2",//you can add whatever you want for a specific column here.
"visible": false
}, {
"data": 'value',
"searchable": false,
"width": "20%",
"className": "lang_body_2",
"title": ""
}]
})
Other way, from off. sites docs. Assign class my_class to first column
$('#example').dataTable( {
"columnDefs": [
{ className: "my_class", "targets": [ 0 ] }
]
} );