1
我試圖創建索引自定義操作欄和問題寫了這個代碼:Yii2 pjax gridview的ActionColumn與視圖鏈接
[
'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]);
}
}
],
刪除和更新正在確定,但鑑於被打開而無需刷新頁面在索引頁面。我更新了我的代碼,並將 'data-method'=>'post'添加到查看按鈕,這似乎有所幫助。
'view' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
'title' => Yii::t('app', 'View'),
'data-method' => 'post',
]);
},
這是GridView中的錯誤還是我做錯了什麼?
當你點擊視圖按鈕,它會帶你到瀏覽網頁,而不是刷新索引頁。 –
查看頁面的打開是什麼actionView如果你想刷新索引頁...召回指數.. – scaisEdge