Answer the question
In order to leave comments, you need to log in
Yii2 gridview how to assign class under different conditions?
Good day, there is a grid, I would like to tritely assign a class to a certain line in the grid,
[
'attribute' => 'date',
'contentOptions' => ['class' => 'date'],
],
Answer the question
In order to leave comments, you need to log in
To whom MB is useful, the right decision.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' => function ($model, $key, $index, $grid)
{
if($model->date < date('Y-m-d')) {
return ['class' => 'red'];
}
},
$data = [
'attribute' => 'date',
'contentOptions' => ['class' => 'date'],
];
if ($yourTime < time()) {
$data["contentOptions"]["class"] = "otherDate";
}
'contentOptions' => function () {
return ['class' => 'myClass'];
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question