Change Row background color based on cell value DataTable
Change Row background color based on cell value DataTable
isaac2k2
Posts: 2Questions: 2Answers: 0
I am using DataTable plugin to display some records. I have 3 rows, Name, Date, Amount. I want the background color of the row to change based on specific values in the amount column.
This is my code:
$(document).ready( function () { var table = $('#tid_css').DataTable({ 'iDisplayLength': 100, "bFilter": false, "aaSorting" : [[2, "desc"]] }); } );As a test, I added below code alongside above code but getting error "DataTables warning: table id=tid_css - Cannot reinitialise DataTable"
$(document).ready( function() { $('#tid_css').dataTable( { "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { if ( aData[2] == "1" ) { $('td:eq(2)', nRow).html( '1' ); } } } ); } );How easy can I do this using "fnRowCallback" with different conditions like if amount is 1 then color is Red, 2 = Blue, 3 = Blue etc.
This discussion has been closed.