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

时间:2015-09-15 04:29:56

标签: gridview yii yii2 yii2-advanced-app

我在gridview中有pjaxActioncolumn按钮上,我调用了不同的controller操作。

例如,我的gridview位于event index页面,其控制器为EventController,但在该网格视图中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);
                },
            ]
        ],
    ]
]);
 ?>

1 个答案:

答案 0 :(得分:1)

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

喜欢,

    [
            '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]);
                },
            ]
    ],