2017-04-26 158 views
0

我已经定制了自己在Yii2 GridView控件来显示某种方式Yii2 - 创建GridView控件定制“模式/风格”的所有GridView和调用风格

'dataProvider' => $dataProvider, 
    //'filterModel' => $searchModel, 
    'filterSelector' => 'select[name="per-page"]', 
    'tableOptions'=> ['class'=>'table datatable-header-footer datatable-header-footer'], 
    'showFooter' => true, 
    'layout'=>"{items}\n\n{summary}\n\n<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' => '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,  
       ]); 

我想知道是否列,标头和寻呼机有是创建一个GridView的“风格”这样我就可以打电话,并在项目应用这种风格到每一个GridView的一种方式!

回答

1

是的,扩展的GridView类用自己的,设置的所有属性,覆盖你需要什么,并使用你的类,而不是默认的GridView的。

+0

好吧,我其实避免,因为它是在其他地方没有这些属性用于扩展GridView控件类。那么,在等待更多的想法,弹出,也许我会复制类文件和定制并使用它。感谢的人 –

+0

你知道,你可以在一个地方使用自己的GridView和其他有一个默认的GridView? – Bizley

+0

如果你读了我写的之后,“井”你知道,即时通讯意识到 –