How to change color of a column on condition

QuestionsHow to change color of a column on condition
jiga asked 7 years ago

Hi, I would like to change the bg color of a column depending on its value
I mean if value of colum estado == ‘REJECTED’ then change its bg color
$col = array();
$col[“title”] = “ESTADO”;
$col[“dbname”] = “cr.estado”;
$col[“name”] = “ESTADO”;
$col[“width”] = “10”;
$col[“editable”] = true;
$col[“align”] = “center”;
$col[“search”] = true;
$cols[] = $col;
$out = $g->render(“list1″);
<html lang=”en”>
<head>
<!– Required meta tags –>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1, shrink-to-fit=no”>
<!– Bootstrap CSS –>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css&#8221; integrity=”sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm” crossorigin=”anonymous”>
<link href=”css/style_memo_index.css” media=”screen” rel=”stylesheet” type=”text/css” />
<link href=”css/helper.css” media=”screen” rel=”stylesheet” type=”text/css” />
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script&gt;
<h1><a href=”javascript:history.go(-1);” title=”Ir al Inicio”> <img src=”<?php echo $logo;?>” alt=”Martin Romero” /> <?php echo $slogan; ?> │ <?php echo $empresa; ?> │ <?php echo $nombre; ?> </a></h1>
<link rel=”shortcut icon” href=”http://srvverapp07/equipo/favicon.ico”&gt;
<link rel=”stylesheet” type=”text/css” media=”screen” href=”lib/js/themes/<?php echo $themes[$i]?>/jquery-ui.custom.css”></link>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”lib/js/jqgrid/css/ui.jqgrid.css”></link>
<script src=”lib/js/jquery.min.js” type=”text/javascript”></script>
<script src=”lib/js/jqgrid/js/i18n/grid.locale-es.js” type=”text/javascript”></script>
<script src=”lib/js/jqgrid/js/jquery.jqGrid.min.js” type=”text/javascript”></script>
<script src=”lib/js/themes/jquery-ui.custom.min.js” type=”text/javascript”></script>
<title>NOV CALIBRACIÓN</title>
</head>
<body>
<script>
function grid_onload(ids)
{
if(ids.rows)
jQuery.each(ids.rows,function(i)
{
// if gender = male and client_id > 10
if (this.estado == ‘RECHAZADO’)
{
// highlight row
jQuery(‘#list1 tr.jqgrow:eq(‘+i+’)’).css(‘background-image’,’inherit’).css({‘background-color’:’#FBEC88′, ‘color’:’green’});
}
// if clientId between 1 & 5, format cell. see ‘aria-describedby=list1_client_id’ is ‘gridid_colname’ convention to identify cell.
if (this.estado == ‘ACEPTADO’)
{
// highlight cell
jQuery(‘#list1 tr.jqgrow:eq(‘+i+’)’).css(‘background-image’,’inherit’);
jQuery(‘#list1 tr.jqgrow:eq(‘+i+’) td[aria-describedby=list1_estado]’).css(‘background’,’inherit’).css({‘background-color’:’#FBEC88′, ‘color’:’green’});
}
});
}
</script>
<div class=”container-fluid”>
<div style=”margin:10px”>
<?php
echo $out;
?>
</div>
</div>

Michael Sheppard replied 7 years ago

I do-this by changing the cell-color on condition (I’m not sure if you can do the entire column).

You specify your condition column and the color in the Grid code and then set the conditions.

This matches the value in the column “estado” and changes it to yellow background with black text if it matches “REJECTED”. You could set multiple conditions as well with different colors with this method.

————8set_conditional_css($f_conditions);

2 Answers
Mike answered 7 years ago

I do-this by changing the cell-color on condition (I’m not sure if you can do the entire column).
You specify your condition column and the color in the Grid code and then set the conditions.
This matches the value in the column “estado” and changes it to yellow background with black text if it matches “REJECTED”. You could set multiple conditions as well with different colors with this method.
————8set_conditional_css($f_conditions);

 

Abu Ghufran Staff answered 7 years ago

Your code seems fine, just try using capital case in ESTADO as set in $col[“name”], e.g.
if (this.ESTADO == ‘ACEPTADO’) …
 
If still not solved, please email me complete code for review at [email protected]

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

14 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?