Answer the question
In order to leave comments, you need to log in
How to remove empty option in gridview in format row in yii2?
In the gridview, I made a drop-down list with which you can display published and unpublished posts.
[
'attribute' => 'status',
'format' => 'raw',
'filter' => [
'off' => 'Не опубликована',
'on' => 'Опубликована',
],
'headerOptions' => ['width' => '200'],
'value' => function ($model, $key, $index, $column) {
$status = $model->status === 'on';
return \yii\helpers\Html::tag(
'span',
$status ? 'Опубликована' : 'Не опубликована',
[
'class' => 'label label-' . ($status ? 'success' : 'danger'),
]
);
},
],
<option value=""></option>
<option value="off" selected>Не опубликована</option>
<option value="on">Опубликована</option>
Answer the question
In order to leave comments, you need to log in
You can pass not an array, but a string in which there will be ready-made html for the filter cell, and there you can do whatever you want. If you are interested in how it works, then here are the sources:
https://github.com/yiisoft/yii2/blob/master/framew...
Alternatively, you can create your own yii\grid\DataColumn and remake this method as you wish.
But it seems to me that the goal itself is not quite adequate. You display all values in the table, which means that there is no filter set for them, so there should be an empty option. You will not be able to select all entries will have or published or not. Why take functionality away from the user?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question