0

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

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Well, Im actually avoiding that, extending the Gridview class because it's used without those properties elsewhere. Well, while waiting for more ideas to pop up, maybe I'll copy the class file and customize it and use it. Thanks man
You do know that you can use your own GridView in one place and default GridView in other one?
if you read what I wrote after "Well" you'd know that Im aware of that
I've read it and that is why I've added my comment. Avoiding class extending because there is version of this widget without customized properties used somewhere else makes no sense.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.