【问题标题】:Yii2: How to add the All option to the GridView filter?Yii2:如何将 All 选项添加到 GridView 过滤器?
【发布时间】:2018-11-07 14:22:32
【问题描述】:

我有一个 GridView,它带有我用 Yii2 制作的 index.php 文件的过滤器。它显示了这个选项:

  • 空白
  • 西
  • 没有

Sí 和 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}'
        ],
    ],
]) ?>

【问题讨论】:

  • 你试过['' =&gt; 'All', '1' =&gt; 'Sí', '0' =&gt; 'No']吗?

标签: gridview filter yii2 widget


【解决方案1】:

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

【讨论】:

  • 谢谢@Vendro.nds,很久以来我一直在寻找这个选项
猜你喜欢
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多