How can I add a class to the row I'm adding in the datatable?
If not possible, how can I use fnRowCallback
or fnDrawCallback
to change the class?
oTable = $('#example').dataTable( {
"bJQueryUI": true,
"bSortClasses": false,
"sDom":'T<"clear">',
"sPaginationType": "full_numbers",
"sDom": 'T<"clear"><"fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix"lfr>t<"fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"ip>',
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
var oSettings = oTable.fnSettings();
oSettings.aoData[iDisplayIndex].nTr.className = "gradeX odd";
}
});
The above code is giving me an error.
this is how I add the row:
oTable.fnAddData(arr);
Official documentation says:
var table = $('#example').DataTable();
table
.rows.add( [
new Pupil( 43 ),
new Pupil( 67 ),
new Pupil( 102 )
] )
.draw()
.nodes()
.to$()
.addClass( 'new' );
Please read: rows.add()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With