'solved' Compare Two Columns And Color It Depending Of The Return Value In A Cgridview

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,

Remove the two lines that say "return $Flag;"

When you return a value, the rest of the function is skipped.

The switch is not useful. I suggest you do something like this:




public function getColor() {

	if ($this->Km_Vida < $this->Km_Actual) {

		return 'red';

	} else {

		return 'yellow';

	}

}



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




tr.red

{

        background: #E41B17;

}


tr.green

{

        background: #CCFF99;

}


tr.yellow

{

        background: #FFFF99;

}


tr.white

{

        background: #FFFFFF;

}

tr.orange

{

        background: #F87431;

}



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(...

.....


....




and looks like this…

regards to every one…

thanks for the answer pretty much aprecciated

regards