简体   繁体   English

jQuery datatable.net根据单元格的值更改行颜色

[英]jquery datatable.net change row color based on value of cell

I want to change color of row in jquery datatable.net based on row's column value in fnRowCallback but its not working. 我想基于fnRowCallback中行的列值更改jquery datatable.net中行的颜色,但是它不起作用。 Can any one help? 有人可以帮忙吗?

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;
                }

        });

Normally you can change the bg-color like this: 通常,您可以像这样更改bg-color:

$(nRow).css("background-color","red");

or 要么

$(nRow).css("background-color","#ff0000");

I don't know if nRow holds a correct representation of the element though, I can't see that here, that's your responsibility. 我不知道nRow持有该元素的正确表示,我在这里看不到,这是您的责任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM