动作栏中的Yii2网格检视下拉式按钮

ni65a41a  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(159)

我想让我的动作列按钮在我的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;
                }
            },
        ],

这就是

我已经跟随了许多在所以或任何来源,但没有对我工作。

hjzp0vay

hjzp0vay1#

buttons是一个呈现函数数组,只需在此处呈现下拉列表并删除urlCreator部分。
urlCreator用于为模板中的默认按钮构建URL,因此通过使用正确的URL呈现下拉列表,您将不再需要它。

'template' => '{actions}',
'buttons' => [
    'actions' => function ($url, $model) {
        //return you dropdown here
    }
],

只是不关心$url参数,在函数内部创建URL。

相关问题