[英]jquery datatable.net change row color based on value of cell
我想基于fnRowCallback中行的列值更改jquery datatable.net中行的颜色,但是它不起作用。 有人可以帮忙吗?
var xref_table = $('#grid_table').dataTable({
"bStateSave": true,
"bDestroy": true,
"bJQueryUI": true,
"sAjaxSource" : 'include/admin/xref_topic_product_add.php?grid=1',
"aoColumns": [
{ "mDataProp": "topic_name",sWidth:'200px' },
{ "mDataProp": "product_name", sWidth: '100px'},
{
"mDataProp": "product_id" ,
fnRender: function(row)
{
if( row.aData.product_id === null)
return '<button class="add_button" data_topic_id="'+ row.aData.topic_id + '" data_product_id="'+ row.aData.product_id + '" >Add</button>';
else
return '<button class="delete_button" data_topic_id="'+ row.aData.topic_id + '" data_product_id="'+ row.aData.product_id + '" >Delete</button>';
},
sWidth: '50px'
},
],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
if(aData[3] === null){
$(nRow).css({"background-color":"red"});
}
return nRow;
}
});
通常,您可以像这样更改bg-color:
$(nRow).css("background-color","red");
要么
$(nRow).css("background-color","#ff0000");
我不知道nRow
持有该元素的正确表示,我在这里看不到,这是您的责任。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.