0

i would like to change row color based on my condition. I am using Bootgrid js (http://www.jquery-bootgrid.com/Documentation)

Here is example:

  • my condition can be 1 or 0
  • if it´s 1 than I need red background color, if 0 - default

This works on "normal" tables

<?php 
if(condition = 1){
  <tr class="red">
} else {
  <tr>
}
?>

I have tried with template formater but it apply on whole table not on my condition

Does anybody know is this possible and how to do this? Thx

1 Answers1

0

You can use it with 2 methods

1) shorted if statement like below

<tr <?PHP echo ($condition == 1 ? 'class="red"' : ''); ?>>

2) Normal if statement

<?php 
   if(condition == 1){
     <tr class="red">
   } else {
     <tr>
   }
?>

Another way

$a_json_row["status"] = 0; // success row
$a_json_row["status"] = 1; // info row
$a_json_row["status"] = 2; // warning row
$a_json_row["status"] = 3; // error row

the below js code extend the status mappings.

$("#grid").bootgrid({
    statusMappings: {
        4: "wrong"
    }
});
Ivan Barayev
  • 2,035
  • 5
  • 24
  • 30
  • I have found an answer. Its integrated in Bootgrid so I have to use Status and for each number what you have in your tempalte Bootgrid use different background color (1-success 2 warning, 3 danger...) – JohnWayneX Jun 28 '16 at 13:31