Negative Values in RED

Negative Values in RED

jamessteelforthjamessteelforth Posts: 17Questions: 4Answers: 0
edited June 2013 in General
Now i have succesfully implemented the datatables on my page. i have one last requirement : i need to show any negative values in red in any of the numerical columns. As my implementation is in salesforce i am using for my table. Each of the having numerical values has some id. the following is what i am trying to implement in javascript -

$('#JustTable PriorEP').each(function()
{
var valu = $(this).val();
alert(valu);
if(valu < '0')
{
$('#JustTable PriorEP').css('color', 'red');
}

});
Table id = "JustTable", column id ="PriorEP"
Its not working.

Replies

  • allanallan Posts: 61,734Questions: 1Answers: 10,110 Site admin
    I think you might want to use the fnCreatedCell callback and add the colouring there.

    An alternative (if you are feeling brave!) is to use DataTables 1.10 (which is pre-beta at the moment) where you would be able to do something like this after initialisation:

    [code]
    table.column( x ).nodes().each( function (cell) {
    if ( table.cell( cell ).data() < 0 ) {
    $(cell).css('color', 'red');
    }
    } );
    [/code]

    where `x` is the column id / selector that you want to operate on.

    A slightly more optimal option since it doesn't need to look up each cell:

    [code]
    var data = table.column( x ).data();
    table.column( x ).nodes().each( function (cell, i) {
    if ( data[i] < 0 ) {
    $(cell).css('color', 'red');
    }
    } );
    [/code]

    Progress... :-)

    Regards,
    Allan
  • jamessteelforthjamessteelforth Posts: 17Questions: 4Answers: 0
    Gee, thanks, i used fnCreatedCell as its too late in the project to try anything new. Worked like a charm!!! Thanks Alan!
This discussion has been closed.