Yii2 GridView on steroids. A module with various modifications and enhancements to one of the most used widgets by Yii developers. The widget contains new additional Grid Columns with enhanced settings to customize the Gridview In Yiiframework 2.0.
Simple GridView In Yii2.0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], 'categoryid', 'categoryname', 'parentid', 'createdon', // 'isactive', ['class' => 'yii\grid\ActionColumn'], ], ]); ?> |
Settings In Gridview
1 2 3 4 5 6 7 8 9 10 | <?php GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], ......... ['class' => 'yii\grid\ActionColumn'], ], 'options'=>['class'=>'grid-view gridview-newclass'], ]); ?> |
Gridview Summary Text, showFooter, showHeader
1 2 3 4 5 6 7 8 9 10 11 12 | <?php GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'summary'=>'', 'showFooter'=>true, 'showHeader' => true, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], ......... ['class' => 'yii\grid\ActionColumn'], ], ]); ?> |
GridView Column: Content Options [class, style etc]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], ......... // format one [ 'attribute'=>'parentid', 'label'=>'Parent Name', 'contentOptions' =>function ($model, $key, $index, $column){ return ['class' => 'tbl_column_name']; }, 'content'=>function($data){ return "value"; } ], // format two [ 'attribute'=>'child_id', 'contentOptions' =>['class' => 'table_class','style'=>'display:block;'], 'content'=>function($data){ return "value"; } ], ......... ['class' => 'yii\grid\ActionColumn'], ], ]); ?> |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Freebies, Php Framework, Tip and tricks, Web development, Yii