在yii2中向网格视图添加按钮 [英] add a button to grid view in yii2
本文介绍了在yii2中向网格视图添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是yii2的新开发人员! 我做了一个GridView,代码如下所示:
i'm a new yii2 developer ! i made a GridView and the code is shown below :
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\ActionColumn'],
['class' => 'yii\grid\CheckboxColumn'],
['class' => 'yii\grid\SerialColumn'],
'id',
'countryCode',
'countryName',
'currencyCode',
],
]); ?>
<?php Pjax::end(); ?>
输出的屏幕截图: 输出
现在我想让一列包含一些按钮,并且该按钮例如用于打开页面或其他东西! 我的问题是如何创建该列?
now i want to have a column contain some button and that button for example open a page or somthing else ! my problem is how can i create that column ?
推荐答案
您还可以像这样将按钮(或任意多个)添加到现有操作列中
You can also add the button (or as many as you like) to the existing action column like this
<?= GridView::widget([
::
::
'columns' => [
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {update} {delete} {myButton}', // the default buttons + your custom button
'buttons' => [
'myButton' => function($url, $model, $key) { // render your custom button
return Html::a(..);
}
]
]
::
::
'currencyCode'
]
]); ?>
这篇关于在yii2中向网格视图添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文