Change background color in Yii2 gridview cell depend on its value -
i trying make background color depending on value calculation number in 1 cell. code:
[ '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'], ],
but got error, "cannot use object of type yii\data\activedataprovider array"
so, how can change background gridview cell have value calculation ?
use 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')]; }, ],
Comments
Post a Comment