我试图根据单元格的值突出显示dataTable中的一行。但奇怪的是,即使符合条件,css也不适用。数据表正确地显示数据,但行高亮不起作用。请告诉我哪里出错了。我使用客户端 dataTables。基于jQuery数据中未指向的单元格值的行突出显示表
谢谢! 下面是我的代码:
的jQuery:
//data to be added to dataTable is added into the html table before this line.
oTableQ= $('#myDataTable').dataTable({
"sPaginationType": "full_numbers",
"bLengthChange":false,
"bInfo": true,
"columns": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
{ "visible": false }
],
"createdRow": function(row, data, dataIndex) {
if (data[9] == "ACTIVE") {
$(row).addClass('highlightRow'); //this line has no effect on the page even if the 'if' condition is satisfied.
console.log(" row text is : "+ $(row).text() + "data at 9th column : " + data[9]);
}
},
"iDisplayLength":10
});
CSS:
.highlightRow {
background-color: #ffaabb;
}
您正在使用什么版本的DataTable的呢? 'createdRow'是一个1.10的特性,而且你用小写'dataTable'初始化的事实让我觉得你正在使用1.9 – markpsmith 2014-09-23 10:44:59
@markpsmith是的,你是对的。我使用jQuery 1.9版本。如何将此代码转换为jQuery 1.10? – kkk 2014-09-23 11:12:04
@kkk,只包含1.10.x js/css版本。 1.10.x是向后兼容的,旧代码应该工作在1:1。 – davidkonrad 2014-09-23 11:19:42