yii2-创建GridView自定义“模型/样式”对于所有GridView并调用样式



我已经在yii2中自定义了我的gridview,以某种方式显示列,标题和pager

'dataProvider' => $dataProvider, 
    //'filterModel' => $searchModel,
    'filterSelector' => 'select[name="per-page"]',
    'tableOptions'=> ['class'=>'table datatable-header-footer datatable-header-footer'],
    'showFooter' => true,
    'layout'=>"{items}nn{summary}nn<div class='text-right'>{pager}</div>n",
    //'summary' => "{begin} - {end} {count} {totalCount} {page} {pageCount}",
    'summary' => " <br/> Affichage de {begin} à {end} des {totalCount} lignes <br/> <br/>",
    'formatter' => ['class' => 'yiii18nFormatter','nullDisplay' => ' - '],
    'pager' => [
        'nextPageLabel' => '→',
         'prevPageLabel' => '←',
        'firstPageLabel' => true,
        'maxButtonCount' => 5,
        'lastPageLabel'  => true
    ],
    'columns' => [
       // ['class' => 'yiigridSerialColumn'],
        //'id', ...
['class' => 'yiigridActionColumn',
        'contentOptions' => ['style' => 'width:10%;'],
        'header'=>'Actions',
        'template' => '{all}',
        'buttons' => [
            'all' => function ($url, $model, $key) {
                return ButtonDropdown::widget([
                    'encodeLabel' => false,  
                    'label' => 'Choisir',
                    'dropdown' => [
                        'encodeLabels' => false,   
                        'items' => [
                            [
                                'label' => Yii::t('yii', '<i class="icon-search4"></i> Details'),
                                'url' => ['view', 'id' => $key],
                            ],
                            [
                                'label' => Yii::t('yii', '<i class="icon-pencil5"></i> Modifier'),
                                'url' => ['update', 'id' => $key],
                                'visible' => true,   
                            ],
                            [
                                'label' => Yii::t('yii', '<i class="icon-list"></i> Annonces'),
                                'url' => ['annonces', 'agence_id' => $key],
                                'visible' => true,   
                            ],
                            [
                                'label' => Yii::t('yii', '<i class="icon-list2"></i> Agents'),
                                'url' => ['professionnels', 'agence_id' =>$key],
                                'visible' => true,   
                            ],
                            [
                                'label' => Yii::t('yii', '<i class="icon-bin"></i> Supprimer'),
                                'linkOptions' => [
                                    'data' => [
                                        'method' => 'post',
                                        'confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
                                    ],
                                ],
                                'url' => ['delete', 'id' => $key],
                                'visible' => true,   // same as above
                            ],
                        ],
                        'options' => [
                            'class' => 'dropdown-menu-right', // right dropdown
                        ],
                    ],
                    'options' => [
                        'class' => 'btn-default',
                        'style' => 'padding-left: 5px; padding-right: 5px;',   // btn-success, btn-info, et cetera
                    ],
                    'split' => true,     
                ]);

im想知道是否有一种创建GridView"样式"的方法,因此我可以致电并将此样式应用于项目中的每个GridView!

是的,使用自己的gridview类扩展,设置所有属性,覆盖所需的任何东西,而不是默认的gridview。

最新更新