我试图根据一个单元格中的值计算数量制作背景颜色.这是我的代码:
[
'attribute' => 'coefTK',
'label' => '<abbr title="Koefisien Jumlah Tenaga Kerja">TK</abbr>',
'encodeLabel' => false,
'headerOptions' => ['style'=>'text-align:center'],
'options' => [ 'style' => $dataProvider['coefTK']/$dataProvider['coefTK_se']<2 ? 'background-color:red':'background-color:blue'],
],
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,说"不能使用类型为yii\data\ActiveDataProvider的对象作为数组"
那么,我如何更改具有某些计算值的背景gridview单元格?
用途contentOptions:
[
'attribute' => 'coefTK',
'label' => '<abbr title="Koefisien Jumlah Tenaga Kerja">TK</abbr>',
'encodeLabel' => false,
'headerOptions' => ['style'=>'text-align:center'],
'contentOptions' => function ($model, $key, $index, $column) {
return ['style' => 'background-color:'
. (!empty($model->coefTK_se) && $model->coefTK / $model->coefTK_se < 2
? 'red' : 'blue')];
},
],
Run Code Online (Sandbox Code Playgroud)