Yii2.0 GridView 新增添加按钮

时间:2022-03-25 15:55:49
<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'parent',
            'lft',
            'rht',
            'name',
            ['class' => 'yii\grid\ActionColumn','header'=>'操作','template' => '{add} {view} {update} {delete}',
                'buttons' => [
                'add' => function ($url, $model, $key) {
                      return  Html::a('<span class="glyphicon glyphicon-plus  btn btn-warning btn-sm"></span>', $url, ['title' => '添加'] ) ;
                     },
                ],
               'headerOptions' => ['width' => '180']
            ],
        ],
]); ?>