【发布时间】:2012-02-23 02:33:00
【问题描述】:
我是数据表的新手 - 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",
});
});
【问题讨论】:
-
我们可能至少需要一个关于您特别想要的东西的想法。你能给我们举一些例子吗?
-
我有类似下面的内容。我想根据单元格的内容设置第 6 列单元格的背景,例如如果内容是“A”,那么我想将背景设置为红色。 oTable = $('#example').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "scripts/server_processing.php", "sPaginationType": "full_numbers" } );
标签: jquery jquery-plugins datatables