3zzy 3zzy - 1 month ago 5
Javascript Question

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

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

I can't target and style individual cells (

) 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
of a 'column'.


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": [
    { "sWidth": "95px", "sClass": "datatables_action" },
    { "sWidth": "45px", "sClass": "datatables_action" }

You can check datatables documentation