hi actually im trying to make a comparation beetween 2 columns in a cgrid view and dependind on the value of that comparation i want to color the row in my project:
if Km_Actual is more than Km_Vida then i want to color the row in red
if Km_Actual is the same as Km_Change then color the row in yellow,
and if the Km_Actial is less than Km_change color the row in green
so i have this Function in my model Llantas
public function getColor() {
$Flag = 0;
if ($this->Km_Vida < $this->Km_Actual) {
$Flag = 1;
return $Flag;
} else {
$Flag = 2;
return $Flag;
}
$statuscolor = 'white';
switch ($Flag) {
case 1:
$statuscolor = 'red';
break;
case 2:
$statuscolor = 'yellow';
break;
}
return $statuscolor;
}
so when i run the code on my browser it just show the data grid it self it does not color anything, a have the colors already declared on my css that is not the issue,
for the ones who still being interested I solved the issue already I made the comparation on the same function this is on my model and it looks like this…
public function getColor() {
$statuscolor='white';
if ($this->Km_Actual > $this->Km_Vida){
$statuscolor='red';
}
elseif ($this->Km_Actual < $this->Km_Vida){
$statuscolor='white';
}
elseif($this->Km_Actual === $this->Km_Change) {
$statuscolor='yellow';
}
elseif($this->Km_Actual > $this->Km_Change and $this->Km_Actual < $this->Km_Vida) {
$statuscolor='orange';
}
return $statuscolor;
}
this is the code I have on the css main file to color the rows
and finally I print the result on the CGridView in the view Like this
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'llantas-unidad-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'rowCssClassExpression'=>'$data->color',// here I call the function color
'columns'=>array(...
.....
....