我是数据表的新手 - http://datatables.net/ - 。我很难找到一个例子,我可以根据它的位置和内容来改变单元格的背景颜色。
除了现在突出显示所选行之外,这样的事情对我有用 在已改变背景颜色的细胞中“过度染色”。如果我可以在fnRowCallback中获取行的类名,那么我可以处理它。
$(document).ready(function() {
// Add a click handler to the rows - this could be used as a callback
$("#example tbody").click(function(event) {
$(oTable.fnSettings().aoData).each(function() {
$(this.nTr).removeClass('row_selected');
});
(event.target.parentNode).addClass('row_selected');
});
oTable = $('#example').dataTable({
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$(nRow).children().each(function(index, td) {
if (index == 6) {
if ($(td).html() === "pending") {
$(td).css("background-color", "#078DC6");
} else if ($(td).html() === "rendering") {
$(td).css("background-color", "#FFDE00");
} else if ($(td).html() === "success") {
$(td).css("background-color", "#06B33A");
} else if ($(td).html() === "failure") {
$(td).css("background-color", "#FF3229");
} else {
$(td).css("background-color", "#FF3229");
}
}
});
return nRow;
},
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"sPaginationType": "full_numbers",
});
});