如何在 yii2 中禁用 pjax 的 gridview 更新?

how to disable update in gridview for pjax in yii2?

我是 yii2 的新手,现在我正在创建示例 crud 应用程序。我将 pjax 用于 gridview,它对我来说工作正常,我的问题是当我更新我的行时 pjax 现在也调用我想禁用这个 pjax 更新按钮。我该如何解决这个问题?这是我的代码

<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\PostSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Posts';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="post-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Post', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?php \yii\widgets\Pjax::begin(
            ['id' => 'StickerList', 'timeout' => false, 'enablePushState' => false, 'clientOptions' => ['method' => 'GET']]
        ); ?>
    <?= GridView::widget([
        'dataProvider' => $model->search(),        
        'filterModel' => $model,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            [
                'attribute'=>'PostType',
                'filter'=>Html::activeDropDownList($model, 'PostType',array(""=>"All","1"=>"Status","2"=>"Images","3"=>"Video"),['class'=>'form-control','prompt' => 'Select Post Type']),
            ],
            'PostTitle',
            [
                'header' => 'Artist',
                'attribute' => 'ArtistName',
            ],
            [
                'header' => 'Date Posted',
                'attribute' => 'DatePosted',
                'filter' => false,
            ],
            [
                'header' => '# Likes',
                'attribute' => 'TotalLikes',
                'filter' => false,
            ],
            [
                'header' => '# Comments',
                'attribute' => 'TotalComments',
                'filter' => false,
            ],
            [
                'header' => 'Exclusive',
                'attribute' => 'IsExclusive',
                'filter'=>Html::activeDropDownList($model, 'IsExclusive',array(""=>"All","0"=>"Normal","1"=>"Exclusive"),['class'=>'form-control','prompt' => 'Select Exclusive']),
            ],
            [
                'header' => 'Status',
                'attribute' => 'Status',
                'filter'=>Html::activeDropDownList($model, 'Status',array(""=>"All","1"=>"Active","2"=>"Inactive"),['class'=>'form-control','prompt' => 'Select Status']),
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template'=>'{update}',
                'buttons' => [
                    'update' => function ($url,$model) {
                            $url = Url::toRoute('post/update?id='.$model['PostID']);
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>',$url);
                    },
            ],
            ],
        ],
    ]); ?>
    <?php \yii\widgets\Pjax::end(); ?>

</div>

您需要在更新按钮的锚标记选项中添加[ 'data-pjax' => false ][ 'data-pjax' => '0' ]

例如,

 [
     'class' => 'yii\grid\ActionColumn',
     'template'=>'{update}',
     'buttons' => [
           'update' => function ($url,$model) {
                        $url = Url::toRoute('post/update?id='.$model['PostID']);
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>',$url, ['data-pjax' => '0']);
                    },
     ],
]