Yii2如何在网格中添加新的动作按钮

时间:2015-03-11 11:11:12

标签: php yii2

我有以下网格。

    $gridColumns = [
                'class'=>'kartik\grid\ActionColumn',
                'headerOptions'=>['class'=>'kartik-sheet-style'],
                'template' => '{delete}{my_button}', 
            ],

    echo GridView::widget([
            'dataProvider'=> $dataProvider,
            'columns' => $gridColumns,
            'filterModel' => $filterModel,
            ],
        ]);

我想添加template一个新的操作按钮,例如{my_button}

1 个答案:

答案 0 :(得分:7)

您只需在列中添加buttons参数,例如: :

'template' => '{my_button}', 
'buttons' => [
    'my_button' => function ($url, $model, $key) {
        return Html::a('My Action', ['my-action', 'id'=>$model->id]);
    },
]

了解详情:http://www.yiiframework.com/doc-2.0/yii-grid-actioncolumn.html#$buttons-detail