YII2 gridview

Posted Yeah,程序猿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了YII2 gridview相关的知识,希望对你有一定的参考价值。

<?= \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‘,
                                    ]);
                            },
                        ]
                    ],
                ],
            ]); ?>

  

以上是关于YII2 gridview的主要内容,如果未能解决你的问题,请参考以下文章

隐藏 Yii2 GridView 操作按钮

Yii2的Gridview应用技巧补充

gridview yii2中的按钮

yii2之GridView小部件

Yii2.0 GridView 的强大功能

如何在 Yii2 Gridview 中自定义默认数据确认对话框