Yii2:如何将All选项添加到GridView过滤器?

时间:2018-11-07 14:22:33

标签: gridview filter yii2 widget

我有一个GridView,它带有由Yii2制成的index.php文件的过滤器。它显示了以下选项:

  • 空白

Sí和No在西班牙语中表示是和否。我需要向世界展示全部而不是空白选项:

GridView showing the filter (options: blank, yes and no)

<?= 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}'
        ],
    ],
]) ?>

1 个答案:

答案 0 :(得分:2)

添加属性“ 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