Black Mamba
Black Mamba

Reputation: 205

Negative Values in RED in Datatables

Now i have succesfully implemented the datatables on my VF page. i have one last requirement : i need to show any negative values in red and in bold 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.

KK, now i changed the code to

          $('#JustTable PriorEP').each(function()
        {   
         var valu = $(this).val();

      if(parseInt(valu) < 0)
      {
          alert(parseInt(valu));
          $(this).css('color', 'red');
      }

  });

The alert is not thrown up even once

Upvotes: 0

Views: 3425

Answers (1)

Black Mamba
Black Mamba

Reputation: 205

Hehe, solved it using datatables API itslef. Scrapped the jquery and changed my datatable initilization as following:

$(document).ready( function() {
$('#example').dataTable( {
"aoColumnDefs": [ {
  "aTargets": [4,5,6,7,8,9],
  "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
     if ( sData < "0" ) {
                      $(nTd).css('color', 'red')
                      $(nTd).css('font-weight', 'bold')
    }
  }
} ]
});
} );

Here, aTargets lets you specify which column numbers to apply function to. fnCreatedCell is the function that lets you define what should happen when a certain type of data is found, in my scenario, Bold and red if value less than 0

Upvotes: 4

Related Questions