Pjax gridview yii2 中的不同控制器动作

Different controller action in Pjax gridview yii2

我有 gridviewpjax 在它的 Actioncolumn 按钮上,我调用了不同的 controller 操作。

例如,我的 gridview 在 event index 页面上,它的控制器是 EventController,但是在那个 gridview 的 actioncolumn 按钮之一上,我正在调用 CheckinController 操作.

只有在我不使用 Pjax 时才能正常工作,否则它只会刷新 gridviewurl 也会发生变化,但不会刷新页面

这里是 event gridview

的代码
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<div class="common-button">
<p>
    <?= Html::a('Create Event', ['create'], ['class' => 'btn btn-danger']) ?>
</p>
</div>



<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'rowOptions'=> function($modal, $key, $index, $grid) {

        if ($modal->is_active == '0') {
            return ['class' => 'danger action-tr' ];
        } else
            return ['class' => 'success action-tr'];

    },
    'columns' => [
        [
            'attribute' => 'interest_id',
            'label' => 'Event Category',
            'value' => 'interest.area_intrest',
        ],
        'title',
        'description:html',
        'location',
        'start_date',
        [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{checkin/index} {view} {update} {delete} ',
            'contentOptions' => ['class'=>'action-td'],
            'buttons' => [
                'checkin/index' => function ($url) {
                    return Html::a('<span class="glyphicon glyphicon-user"></span>', $url);
                },
            ]
        ],
    ]
]);
 ?>

您应该在 actionColumn 按钮的锚标记选项中添加 [ 'data-pjax' => true ]

喜欢,

    [
            'class' => 'yii\grid\ActionColumn',
            'template' => '{checkin/index} {view} {update} {delete} ',
            'contentOptions' => ['class'=>'action-td'],
            'buttons' => [
                'checkin/index' => function ($url) {
                    return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, ['data-pjax' => true]);
                },
            ]
    ],