CGridView table cell color <td> that is


I am attempting to assign a specific class to a table cell based on the cells content, however my evaluation is rendering incorrectly. Also, being a noob to Yii, I’m probably putting adding this code in the wrong place (CGridColumn.php) so a recomendation there is also appreciated. What is being returned is the entire row of cells is assigned the css class, yet only 4 of the 14 cells should return the class. Thanks for any help.

public function renderDataCell($row)









				$options['class'].=' '.$class;





                foreach ($data as $field)



                    if($field==='XXX')  //my attempt to change the rdo table cell color

                    $tdrdocell = 'td class="rdo"';   //my attempt to change the rdo table cell color

                    else   //my attempt to change the rdo table cell color

                    $tdrdocell = 'td';   //my attempt to change the rdo table cell color



                echo CHtml::openTag($tdrdocell,$options);


		echo '</td>';


You can’t use foreach since last field in $data will be decisive for which value to use.

Instead try $this->id in an if statement. Format of id: <name_of_your_grid>+‘c’+<field_no>

Actually you don’t have to extend the class at all, just use a trinary operator when you specify the cssClassExpression property:



Thanks for the reply. I will have to study the docs a bit more. My app works as expected and has been deployed without the cell color attribute. (too little time) The table cell color was only an effort to highlight specific cells, but is not mandatory for the app, just an idea of mine to make something a little more readable. I have used my code in apps from scratch and they work fine, but again that is code from scratch and not using a framework. It’s just a matter of figuring out Yii I suppose. What I really wanted to do was to find a way to implement my desire in a widget instead of the core code, hence I put this little aspect on the back burner until I can figure it out. Thanks again for the reply.

Perhaps you could confirm something for me during deployment?

When deploying, the framework folder also must be uploaded to the live server? I assume this is true since my app would not work without it.

Are there any folders that should NOT be uploaded?

Thanks again for your previous response.