【发布时间】:2016-12-28 23:50:00
【问题描述】:
我正在尝试根据单元格的值突出显示数据表中的一行。但奇怪的是,即使满足应用的条件,css也不会应用。数据表正确显示数据,但行突出显示没有发生。请告诉我哪里出错了。仅供参考..我正在使用客户端数据表。
谢谢!! 以下是我的代码:
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;
}
【问题讨论】:
-
您使用的是什么版本的数据表?
createdRow是 1.10 的功能,您使用小写的“dataTable”进行初始化的事实让我觉得您使用的是 1.9 -
@markpsmith 是的,你是对的。我正在使用 jquery 1.9 版本。如何将此代码转换为 jQuery 1.10?
-
@kkk,只包含 1.10.x js/css 版本。 1.10.x 向后兼容,旧代码应该 1:1 工作。
标签: jquery css jquery-datatables