Font color should depand on Value

Font color should depand on Value

paintitblackpaintitblack Posts: 60Questions: 20Answers: 0

Hello,

I tried to change the color in Column 3 (profit) depanding on the value (>0 = green; else red), but the rowCallback espacially the data[3] variable is unknown.

I can call e.g. data.currentprice but not data.profit. Can I give Column #3 a name or can I manage the font color directly in the data: null, render: function ( data, type, row ) { area?

` var table = $('#_stocks').DataTable( {
"rowCallback": function( row, data, index ) {
if ( data[3] >0 ) {
$("td:eq(3)", row).css("color","green");
} else {
$("td:eq(3)", row).css("color","red");
}
},

            dom: 'Bfrtip',
            ajax: 'table._stocks.php',
            stateSave: true,
            columns: [
                    {
                            "data": "status"
                    },
                    { data: null, render: function ( data, type, row ) {
                             return '<a href="'+data.url+'" target="_blank">'+data.name+'</a>';
                    } },
                    {
                            "data": "quantity"
                    },
                    { data: null, render: function ( data, type, row ) {
                             if(data.status==2) {
                                     profit = (data.sellprice*data.quantity)-(data.purchaseprice*data.quantity);
                             } else {
                                     profit = (data.currentprice*data.quantity)-(data.purchaseprice*data.quantity);
                             }
                             return profit.toFixed(2);
                    } }
            ]
    } );`

Than you very much for helping.

Kind regards

This discussion has been closed.