2014-06-09 143 views
2

我想根據fnRowCallback中行的列值更改jquery datatable.net中行的顏色,但它不起作用。任何人都可以幫忙嗎?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; 
       } 

     }); 

回答

3

通常情況下,你可以改變BG-顏色是這樣的:

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

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

我不知道,如果nRow持有元素的正確表示,雖然,我在這裏看不到,那是你的責任。

相關問題