Yii 2.0 GridView Demo Code

Yii 2.0 GridView Demo Code, Full cover all basic function in daily coding

 

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
//             ['class' => 'yii\grid\SerialColumn'],

            'au_id',
            'au_displayName',
            [
            'attribute'=>'au_package_id',
            'value'=>function ($data){ return $data->getPackageName();},
            'filter'=>Package::getPackageList()
            ],

            ...

            [
                'class' => 'yii\grid\ActionColumn', 
                'header' => '操作',
                'template' => '{view} {update} {delete} {changeDate}', 
                'buttons'=>[
                     'changeDate' => function ($url, $model, $key) {
                        if (Yii::$app->user->identity->u_id > 10) {
                            return '';
                        }//only show for admin user
                         return Html::a('<i class="glyphicon glyphicon-time"></i>', ['app-user/update-date', 'id'=>$model->au_id], ['title'=>'Change Time', 'target'=>'_blank']);
                     },

                ]
            ],
        ],
    ]); ?>
</div>