Yii2:如何将 All 选项添加到 GridView 过滤器?
Yii2: How to add the All option to the GridView filter?
我有一个 GridView,其中包含我使用 Yii2 制作的 index.php 文件的过滤器。它显示了这个选项:
- 空白
- 四
- 没有
Sí and No 在西班牙语中表示是和否。我需要向世界展示 All 而不是空白选项:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'nombre_motivo_movimiento',
[
'attribute' => 'entrada',
'format' => 'raw',
'filter' => ['1' => 'Sí', '0' => 'No'], // The filter I want to improve.
'contentOptions' => [
'class' => 'text-center',
],
'value' => function($m){
if ($m->entrada) {
return '<span class="label label-success"><i class="fa fa-check"></span>';
}
else {
return '<span class="label label-danger"><i class="fa fa-remove"></span>';
}
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}'
],
],
]) ?>
添加 属性 'filterInputOptions':
'filter' => ['1' => 'Sí', '0' => 'No'], // The filter I want to improve.
'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => 'Todos'], // to change 'Todos' instead of the blank option
我有一个 GridView,其中包含我使用 Yii2 制作的 index.php 文件的过滤器。它显示了这个选项:
- 空白
- 四
- 没有
Sí and No 在西班牙语中表示是和否。我需要向世界展示 All 而不是空白选项:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'nombre_motivo_movimiento',
[
'attribute' => 'entrada',
'format' => 'raw',
'filter' => ['1' => 'Sí', '0' => 'No'], // The filter I want to improve.
'contentOptions' => [
'class' => 'text-center',
],
'value' => function($m){
if ($m->entrada) {
return '<span class="label label-success"><i class="fa fa-check"></span>';
}
else {
return '<span class="label label-danger"><i class="fa fa-remove"></span>';
}
}
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}'
],
],
]) ?>
添加 属性 'filterInputOptions':
'filter' => ['1' => 'Sí', '0' => 'No'], // The filter I want to improve.
'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => 'Todos'], // to change 'Todos' instead of the blank option