我想让我的动作列按钮在我的gridview中成为下拉按钮,这是我的代码
// ... GridView configuration ...
['class' => 'yii\grid\ActionColumn',
'template' => '{sell} {delete}',
'buttons' => [
'sell' => function ($url, $model) {
return Html::a('<button type="button" class="btn btn-success"><i class="glyphicon glyphicon-shopping-cart"></i></button>', $url, [
'title' => Yii::t('app', 'Sell Tickets'),
'data-toggle' => "modal",
'data-target' => "#myModal",
'data-method' => 'post',
]);
},
'delete' => function ($url, $model) {
return Html::a('<button type="button" class="btn btn-danger"><i class="glyphicon glyphicon-remove-sign"></i></button>', $url, [
'title' => Yii::t('app', 'Delete'),
'data-toggle' => "modal",
'data-target' => "#myModal",
'data-method' => 'post',
]);
},
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action == 'sell') {
$url = Url::toRoute(['trip/sell', 'id' => $model->tripScheduleId]);
return $url;
} else {
$url = Url::toRoute(['trip/delete', 'id' => $model->tripScheduleId]);
return $url;
}
},
],
这就是
我已经跟随了许多在所以或任何来源,但没有对我工作。
1条答案
按热度按时间hjzp0vay1#
buttons
是一个呈现函数数组,只需在此处呈现下拉列表并删除urlCreator
部分。urlCreator
用于为模板中的默认按钮构建URL,因此通过使用正确的URL呈现下拉列表,您将不再需要它。只是不关心
$url
参数,在函数内部创建URL。