使用GridView在Yii2.0中显示过滤器的空白行

Peo*_*eon 7 php yii

我已经设置了GridView来在Yii2.0中伪造我的表,如下所示:

<?= \yii\grid\GridView::widget([
    'dataProvider' => $model->dataProvider,
    'filterModel' => $model->searchModel,
    'columns' => [
        [
            'label' => Yii::t( $cat, 'Id' ),
            'value' => 'id',
        ],
        [
            'label' => Yii::t( $cat, 'Title' ),
            'format' => 'raw',
            'value' => function ( $data ) {
                if ( $data['status_code'] != 5 )
                {
                    return Html::a( $data['title'], '/signer/view/' . $data['id'] );
                }
                else
                {
                    return $data['title'];
                }
            },
        ],
        [
            'label' => Yii::t( $cat, 'Description' ),
            'value' => 'description',
        ],
        [
            'label' => Yii::t( $cat, 'Filename' ),
            'value' => 'filename',
        ],
        [
            'label' => Yii::t( $cat, 'Status' ),
            'value' => 'status',
            'contentOptions' => function ( $data ) {
                    $statuses = [
                        1 => 'text-primary',    # New
                        2 => 'text-warning',    # Unsigned
                        3 => 'text-warning',    # Partially signed
                        4 => 'text-success',    # Signed
                        5 => 'text-danger',     # Deleted
                    ];
                    return [ 'class' => $statuses[$data['status_code']] ];
                }
        ],
        [
            'label' => Yii::t( $cat, 'Created' ),
            'value' => 'created',
        ],
        //[ 'class' => 'yii\grid\ActionColumn' ],
    ],
]);
?>
Run Code Online (Sandbox Code Playgroud)

我得到了所有正确的数据,但不是过滤器输入,我得到空行.

在此输入图像描述

这是为什么?我错过了什么?

PS:搜索模型本身工作正常,这意味着,当我添加到网址时,?title=asd它实际上获得了搜索结果!

nem*_*esv 4

根据该房产的文件$filterModel

请注意,为了显示用于过滤的输入字段,必须设置列的yii\grid\DataColumn::$attribute属性或将其yii\grid\DataColumn::$filter设置为输入字段的 HTML 代码。

因此,您需要yii\grid\DataColumn::$attribute在列上设置属性,在大多数情况下,这使得value不必要的操作:

<?= \yii\grid\GridView::widget([
    'dataProvider' => $model->dataProvider,
    'filterModel' => $model->searchModel,
    'columns' => [
        [
            'label' => Yii::t( $cat, 'Id' ),
            'attribute' => 'id',
        ],
        [
            'label' => Yii::t( $cat, 'Title' ),
            'format' => 'raw',
            'attribute' => 'title',
            'value' => function ( $data ) {
                if ( $data['status_code'] != 5 )
                {
                    return Html::a( $data['title'], '/signer/view/' . $data['id'] );
                }
                else
                {
                    return $data['title'];
                }
            },
        ],
        [
            'label' => Yii::t( $cat, 'Description' ),
            'attribute' => 'description',
        ],
        [
            'label' => Yii::t( $cat, 'Filename' ),
            'attribute' => 'filename',
        ],
        [
            'label' => Yii::t( $cat, 'Status' ),
            'attribute' => 'status',
            'contentOptions' => function ( $data ) {
                    $statuses = [
                        1 => 'text-primary',    # New
                        2 => 'text-warning',    # Unsigned
                        3 => 'text-warning',    # Partially signed
                        4 => 'text-success',    # Signed
                        5 => 'text-danger',     # Deleted
                    ];
                    return [ 'class' => $statuses[$data['status_code']] ];
                }
        ],
        [
            'label' => Yii::t( $cat, 'Created' ),
            'attribute' => 'created',
        ],
        //[ 'class' => 'yii\grid\ActionColumn' ],
    ],
]);
?>
Run Code Online (Sandbox Code Playgroud)