I want to give colors to rows of a GridView. But Yii2 show an error. It is like the model doesn't exist:
This is part of my index view:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
function($model) {
if ($model->quantity == 0) {
return ['class' => 'danger'];
}
},
'columns' => [
'item',
'quantity',
],
]) ?>
The data to fill the GridView is coming from a SQL query in the ProductsSearch model:
$query = Products::find()
->select(['item', 'quantity']);
$dataProvider = new ActiveDataProvider([
'query' => $query->asArray(),
'key' => 'item',
]);
return $dataProvider;