Reputation: 73
I was trying to create a custom action column in the index and wrote this code:
[
'class' => 'yii\grid\ActionColumn',
'contentOptions' => ['style' => 'width:50px;'],
'header'=>'',
'template' => '{view} {update}',
'buttons' =>
[
//view button
'view' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'View'),
]);
},
'update' => function ($url, $model) {
if (Yii::$app->user->can('change-offer'))
{
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
'title' => Yii::t('app', 'Update'),
]);
}
},
'delete' => function ($url, $model) {
if (Yii::$app->user->can('delete-offer'))
{
return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, [
'title' => Yii::t('app', 'Delete'),
'data-confirm' => 'Are you sure you want to delete this item?',
'data-method' => 'post',
]);
}
},
],
'urlCreator' => function ($action, $model, $key, $index) {
if ($action === 'view') {
return Url::to(['offer/view', 'id'=>$model->id]);
}
if ($action === 'update') {
return Url::to(['offer/update', 'id'=>$model->id]);
}
if ($action === 'delete') {
return Url::to(['offer/delete', 'id'=>$model->id]);
}
}
],
Delete and Update are working ok but view is opening without refreshing the page in the Index page. I updated my code as follows and added the 'data-method' => 'post' to the view button and it seems to help.
'view' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'View'),
'data-method' => 'post',
]);
},
Is it a bug in the GridView or am I doing something wrong?
Upvotes: 2
Views: 2967
Reputation: 25312
You may disable pjax for a specific link inside the container by adding
data-pjax="0"
attribute to this link.
So, you should simply try this :
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'View'),
'data-pjax' => '0',
]);
Read more : http://www.yiiframework.com/doc-2.0/yii-widgets-pjax.html
Upvotes: 8