Change your script as bellow. please check "fnRowCallback" section
var dataset = [
[
Id = "001",
Name = "nn",
Age = "Age",
DateofBirth = "125"
],
[
Id = "001",
Name = "nn",
Age = "Age",
DateofBirth = "125"
]
];
$('#stdTable').DataTable({
processing: true,
serverSide: false,
ordering: true,
paging: true,
searching: true,
columns: [
{ title: "Id" },
{ title: "Name" },
{ title: "Age" },
{ title: "DateofBirth" },
{ title: "View Data" }
],
columns: [
{ data: "Id" },
{ data: "Name" },
{ data: "Age" },
{ data: "DateofBirth" },
{
data: null,
defaultContent: "<button class='tblview'>View Id</button><button class='tblDelete'>Delete</button>"
}
],
data:dataset,
"columnDefs": [
{
"targets": 0,
"visible": false
}
],
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
if (aData.Age == "20") {
//cell background color
$(nRow).find('td:eq(1)').css('background-color', '#ffc2c2');
}
else if (aData.Age == "10") {
//row background color
$('td', nRow).css('background-color', 'Orange');
}
else if (aData.Age == "25") {
//cell text color
$('td', nRow).css('color', 'red');
}
}
});
});