GridView Cell Color

Hey guys,

I tried and failed to render a specific cell in GridView with an background color. I want to be able to color my GridView from cell to cell but didn’t find anything which leaves me this option. Is it currently possible to do that ?

Why don’t you add a class to column’s grid?





{

    'name' => '....',

    'cssClassExpression' => function($row, $data) { return 'class_name'; }

}






First off, isn’t that a Yii 1 thing ? (I mean that css expression option - can’t write the word 'cause of spam checker…)

Furthermore your way would color the whole row instead of just one cell in that row.

In short words, I need a callback or some options in which I can define the background of a cell !

Here is an example image:

The first row shows how your way would do,

the second row shows how I want the result.

6274

gridview_cell_coloring.png

Nevertheless thanks for your quick response !

Yes, for Yii 2 :





[

     'name' => '.....',

     'options' => [ 'style' => 'background-color:....' ]

]




Okey but in my eyes the problem remains - I just can’t style one cell per CSS.

I don’t want a column/row be fully colored ! Aren’t there any callbacks to the rendering of a cell in GridView ?

Should all cells in a column be the same colour or only on selected rows?

Only on selected rows ! (as shown in the gridview of the attached image on second row)

Try rowOptions

Could you please provide an example of how I could color a single cell in a row with rowOptions ?

I can’t figure out how to do this, in my understanding rowOptions is only able to access the CSS of a row rather than a single cell

This colors only 1 cell on every second row of the grid :lol::)




[

   'attribute' => 'id',

   'label' => 'My Word',

   'options' => [ 'style' => 1==1 ? 'background-color:#FF0000':'background-color:#0000FF'],

],



The 1==1 will always return true so the cell will always be red, not what you want, but maybe this sparks some ideas from the experts here?