2017-04-26 155 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

如果你讀了我寫的之後,「井」你知道,即時通訊意識到 –