Change background-color in a row

Hi guys!
I have this attribute in my view file:

       [
          'attribute' => 'ConvMon',
          
          'format' => 'raw',
          'label' => 'Convento',
        ],

I want to change background color of the raw if the content is ‘Novara’. What I have to do?
I try this but it doesn’t work:

‘contentOptions’ => function($model,$key,$index,$widget) {
if (strpos($model->ConvMon, ’ ') !== false) {
return [‘style’ => ‘background-color: pink’];
}

        },

thank you very much !!!

Hi @marco.demurtas
If you want to change background color of the row you need to use GridView attribute rowOptions.

    <?= GridView::widget([
        'id' => 'my-grid',
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'rowOptions' => function($model,$key,$index,$widget) {
                    if ($model->ConvMon === 'Novara') {
                        return ['style' => 'background-color: pink'];
                    }
                },
        'columns' => $columns,
        // ... other options
]); ?>
1 Like

Great! Thank u very much!