dongzhihong3940 2017-04-26 10:28
浏览 351

Yii2 - 为所有gridview创建gridview定制“模型/样式”并调用样式

I have customized my gridview in Yii2 to show columns, headers, and pager in a certain way

'dataProvider' => $dataProvider, 
    //'filterModel' => $searchModel,
    'filterSelector' => 'select[name="per-page"]',
    'tableOptions'=> ['class'=>'table datatable-header-footer datatable-header-footer'],
    'showFooter' => true,
    'layout'=>"{items}

{summary}

<div class='text-right'>{pager}</div>
",
    //'summary' => "{begin} - {end} {count} {totalCount} {page} {pageCount}",
    'summary' => " <br/> Affichage de {begin} à {end} des {totalCount} lignes <br/> <br/>",
    'formatter' => ['class' => 'yii\i18n\Formatter','nullDisplay' => ' - '],
    'pager' => [
        'nextPageLabel' => '→',
         'prevPageLabel' => '←',
        'firstPageLabel' => true,
        'maxButtonCount' => 5,
        'lastPageLabel'  => true
    ],
    'columns' => [
       // ['class' => 'yii\grid\SerialColumn'],
        //'id', ...
['class' => 'yii\grid\ActionColumn',
        '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 wondering if there is a way to create a gridview "style" so I can call and apply this style to every gridview in the project !

  • 写回答

1条回答 默认 最新

  • doushaizhen1244 2017-04-26 10:31
    关注

    Yes, extend GridView class with your own, set all properties, override anything you need and use your class instead of default GridView.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100