Hi, I'm new to javascript and seeking help for my table coloring issue. I have a dynamic table where data is inserted through an Ajax call. The goal is to color specific records based on their status.
I attempted a solution but only one record gets colored while multiple records should be highlighted. Each row's color should change according to the 'status' property received via Ajax call.
Below is the code snippet:
<div class="tb TBN" style="height:125px; border:none;">
<table class="table table-condensed nchild customer" id="records_table">
<tbody>
</tbody>
</table>
</div>
$.map(data.response.data, function(item) {
var stat = item.status;
if (stat == 'A') {
trHTML += '<tr bgcolor="#0072B5" id="' + item.rCOxylane + '">' +
'<td align="center" width="5%"> <input type="radio" id="radio" class="radioDetails" name="empdetails" checked="checked" value="' + item.rCOxylane + '"/> </td>' +
'<td id="decId" style="word-wrap:break-word;">' + item.rCOxylane + '</td>' +
'<td id="activeId" style="display:none;"> ' + item.status + ' </td>' +
'<td id="fname">' + fname + '</td>' +
'<td id="lname">' + item.name2 + '</td>' +
'<td id="mob">' + item.rCMobile + '</td>' +
'<td id="emailid" style="word-wrap:break-word;">' + item.rCEmail + '</td>' +
'<td id="landLine">' + item.rCLandline + '</td>' +
'<td id="zipCode">' + item.rCZipcode + '</td>' +
"<td><a id='EditCustomer' class='EditDetails' href='#EditDetails' role='button' data-backdrop='static' data-toggle='modal'>Edit Details</a></td>" +
'</tr>';
} else {
trHTML += '<tr id="' + item.rCOxylane + '">' +
'<td align="center" width="5%"> <input type="radio" id="radio" class="radioDetails" name="empdetails" checked="checked" value="' + item.rCOxylane + '"/> </td>' +
'<td id="decId" style="word-wrap:break-word;">' + item.rCOxylane + '</td>' +
'<td id="activeId" style="display:none;"> ' + item.status + ' </td>' +
'<td id="fname">' + fname + '</td>' +
'<td id="lname">' + item.name2 + '</td>' +
'<td id="mob">' + item.rCMobile + '</td>' +
'<td id="emailid" style="word-wrap:break-word;">' + item.rCEmail + '</td>' +
'<td id="landLine">' + item.rCLandline + '</td>' +
'<td id="zipCode">' + item.rCZipcode + '</td>' +
"<td><a id='EditCustomer' class='EditDetails' href='#EditDetails' role='button' data-backdrop='static' data-toggle='modal'>Edit Details</a></td>" +
'</tr>';
}
});
The problem I am facing is that only one record with status 'A' is being colored instead of all matching records. Any advice or assistance would be highly appreciated. Thank you in advance!