31

如何在 Yii2 中删除特定网格视图的摘要和排序器。在 Yii1.1 中,我们可以通过设置模板属性来做到这一点。在yii2中如何实现呢?

4

5 回答 5

45

要仅更改summary选项,您可以使用:

'summary' => "{begin} - {end} {count} {totalCount} {page} {pageCount}",

然后,如果你想summary用空字符串值清空集合,例如:

'summary'=> "",

并更改布局,您可以使用:

'layout'=> "{summary}\n{items}\n{pager}"

然后,如果你想layouts用空字符串值清空集合布局,例如:

'layout'=> "",

参考链接

参考链接

因此,对于示例,我认为下面的示例代码可以帮助了解如何GridView在 Yii 2 中更改和定制表:

                <?= \yii\grid\GridView::widget([
                'id' => 'table',
                'dataProvider' => $dataProvider,
                'layout'=>"{sorter}\n{pager}\n{summary}\n{items}",
                'summary' => "Showing {begin} - {end} of {totalCount} items",
                'tableOptions' => ['class' => 'table  table-bordered table-hover'],
                'rowOptions' => function ($model, $key, $index, $grid) {
                    return [
                        'style' => "cursor: pointer",
                        'onclick' => 'location.href="'
                            . Yii::$app->urlManager->createUrl('test/index')
                            . '?id="+(this.id);',
                    ];
                },
                'columns' => [
                    [
                        'class' => 'yii\grid\SerialColumn',
                        'contentOptions' => ['style' => 'width: 20px;', 'class' => 'text-center'],
                    ],
                    [
                        'class' => 'yii\grid\DataColumn',
                        'attribute' => 'date',
                        'headerOptions' => ['class' => 'text-center'],
                        'label' => 'Date',
                        'contentOptions' => ['style' => 'width: 130px;', 'class' => 'text-center'],
                    ],
                        'template' => '{view}',
                        'buttons' => [
                            'view' => function ($url, $model) {
                                return \yii\helpers\Html::a('<div class="text-center"><em data-toggle="tooltip"
                                                            data-placement="top" title="more detail"
                                                            class="fa fa-external-link-square text-warning"></em></div>',
                                    (new yii\grid\ActionColumn())->createUrl('test/index', $model, $model['id'], 1), [
                                        'title' => Yii::t('yii', 'view'),
                                        'data-method' => 'post',
                                        'data-pjax' => '0',
                                    ]);
                            },
                        ]
                    ],
                ],
            ]); ?>
于 2015-02-27T17:36:13.157 回答
9

明白了。通过设置布局属性,我们可以实现它。

'layout'=>"{summary}\n{items}\n{pager}"
于 2014-02-10T11:35:30.923 回答
6

如果您只想使用网格项目'layout'=>"{items}"

如果您只想摘要使用'layout'=>"{summary}"

如果您只想分拣机使用'layout'=>"{pager}"

于 2014-05-24T18:02:41.460 回答
0

将参数设置summaryText为空字符串:

array(
    'summaryText' => '',
    'dataProvider' => $model->search(),
...
于 2014-02-10T11:15:55.293 回答
0
[
    'class' => 'yii\grid\ActionColumn',
    'buttons' =>
        [
            'update'=>function($url,$model,$key)
            {
                return Html::a( "update" , $url ); //use Url::to() in order to change $url
            },
            'view'=>function($url,$model,$key)
            {
                return Html::a( "update" , $url ); //use Url::to() in order to change $url
            },
            'delete'=>function($url,$model,$key)
            {
                return Html::a( "update" , $url, [
                    'class' => 'btn btn-lg btn-primary',
                    'data' => [
                        'method' => 'post',
                        'params' => ['derp' => 'herp'], // <- extra level
                    ],
                ] ); //use Url::to() in order to change $url
            }
        ],
    'template' => '<div class="column-buttons">
                                        <span>{update}</span>
                                        <span>{view}</span>
                                        <span>{delete}</span>
                                    </div>',
    'header' => 'Actions'
]
于 2017-12-29T11:30:09.957 回答