Yii2 pjax gridview ActionColumn 问题与视图 link

Yii2 pjax gridview ActionColumn issue with a view link

我试图在索引中创建自定义操作列并编写了以下代码:

     [  
            '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 的错误还是我做错了什么?

You may disable pjax for a specific link inside the container by adding data-pjax="0" attribute to this link.

所以,您应该简单地尝试一下:

return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, [
    'title' => Yii::t('app', 'View'),      
    'data-pjax' => '0',
]);

阅读更多:http://www.yiiframework.com/doc-2.0/yii-widgets-pjax.html