jQuery addClass example
Change class name on click in jQuery
HTML
<script src="https://cdn.datatables.net/1.9.4/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.9.4/css/jquery.dataTables.css">
<table id="data2" class="">
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
</tr>
</thead>
</table>
JavaScript 1.7
// find elements
var data = [
["test", [20.2, "green"], "test"],
['test1', ['10.2', 'red'], "test"],
['test2', ['15.2', 'red'], "test"],
['test3', ['0', 'red'], "test"],
['test4', ['0.5', 'green'], "test"],
['test5', ['1.5', 'green'], "test"],
];
$(document).ready(function() {
$('#data2').DataTable(
{
'bSort': true,
'aaData': data,
"aaSorting": [[1, 'asc']],
"aoColumnDefs": [
{
"bSortable": true,
"sType": "numeric",
"aTargets": [1],
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html('<label style="color:'+sData[1]+'">'+sData[0]+'</label>');
},
}
]
}
);
} );