While working with jQuery DataTables, I have successfully managed to access row data and apply styling to the entire row.
Below is the code snippet used to initialize the datatable:
var $dataTable = $('#example1').DataTable({
"data": data,
"dataType": "json",
"iDisplayLength": 25,
"order": [[6, "desc"]],
"scrollY": 550,
"scrollX": true,
"bDestroy": true,
"stateSave": true,
// this part of the code styles the row
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
if (aData[12] == "Y"){$('td', nRow).css('background-color', '#EE6363');}
if (aData[9] == "Y"){$('td', nRow).css('font-weight', 'bold');}
}
});
The first if
statement in the code above checks if the data in the 12th column named REJECTED is "Y", resulting in the entire row turning red.
The second if
statement examines whether the data in the 9th column labeled URGENT is "Y", making the text bold for the entire row.
I am now looking to modify my code to make only the cell in that specific column red, instead of the whole row, particularly for the first row.
How can I update the existing code to achieve this desired effect?