Reputation: 235
I would like to overload only some buttons in action columns, but when I try to do it, the default button does not work
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
(...)
[
'class' => 'yii\grid\ActionColumn',
'headerOptions'=> ['style'=>'width: 70px;'],
'template' => '{view} {update} {delete}',
'buttons' => [
'view' => function ($url, $model) {
(...)
},
'update' => function ($url, $model) {
(...)
}
],
'urlCreator' => function ($action, $model, $key) {
if ($action === 'view') {
(...)
}
else if ($action === 'update') {
(...)
}
}
],
],
]); ?>
Using the code above, the 'delete' action doesn't work, the code generated is:
<a title="Elimina" aria-label="Elimina" data-confirm="...?" data-method="post" data-pjax="0">
<span class="glyphicon glyphicon-trash">
</span>
</a>
So, "delete" action is not sent and index page is re-load,
Can you help me?
Upvotes: 5
Views: 6291
Reputation: 5867
This part is causing the issue:
'urlCreator' => function ($action, $model, $key) {
if ($action === 'view') {
(...)
}
else if ($action === 'update') {
(...)
}
}
You did not specify url сreation for delete
action button, that's why it does nothing when you click on it. Add condition into urlCreator
callback for delete
to generate url.
Upvotes: 3