Negative Values in RED
Negative Values in RED
jamessteelforth
Posts: 17Questions: 4Answers: 0
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.
$('#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.
This discussion has been closed.
Replies
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