Jquery Bootgrid table row color based on condition

半腔热情 提交于 2020-01-06 19:57:44

问题


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:


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"
    }
});


来源:https://stackoverflow.com/questions/38076463/jquery-bootgrid-table-row-color-based-on-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!