Giving custom classes to each TD for styling - Datatables & jQuery

eozzy picture eozzy · Apr 1, 2013 · Viewed 80.6k times · Source

I'm using datatables for displaying server-side data in tables.

I can't target and style individual cells (<TD>) though. I search a bit and found it might be possible with:

"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    ....
}

... but I'm not quite sure how because I have a few table and not all have the same number of columns and rows. I want to give common class to all TDs of a 'column'.

Answer

Lukasz Koziara picture Lukasz Koziara · Apr 3, 2013

You can use sClass parameter in Columns definition. For example, if you have 3 columns and want to pass custom class for second and third column, you can:

"aoColumns": [
    null,
    { "sWidth": "95px", "sClass": "datatables_action" },
    { "sWidth": "45px", "sClass": "datatables_action" }
]

You can check datatables documentation