gridview 单元格的颜色,几种情况

cru*_*uim 0 yii2

如何像这样改变单元格的颜色

if($data['type'] == 'London' or $data['type'] == 'Manchester' and $data['from_sale']){
            return ['style' => 'background-color:#BCC6F0;'];
        }
Run Code Online (Sandbox Code Playgroud)

如果“type”行中的值为 London 或 Manchester,则更改“from_sell”行中单元格的颜色。颜色必须仅在“from_sell”行中的两个单元格中更改

Yup*_*pik 5

使用contentOptions:

[
    'attribute' => 'attribute_name',
    'contentOptions' => function ($model, $key, $index, $column) {
        return ['style' => 'background-color:' 
            . ($model->type == 'London' ? 'red' : 'blue')];
    },
],
Run Code Online (Sandbox Code Playgroud)