【问题标题】:Different controller action in Pjax gridview yii2Pjax gridview yii2中的不同控制器动作
【发布时间】:2015-09-15 04:29:55
【问题描述】:

我在pjax 中有gridview 在其Actioncolumn 按钮上,我正在调用不同的controller 操作。

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

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

这是eventgridview的代码

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

【问题讨论】:

  • 尝试在按钮的锚标签中使用[data-pjax =&gt; false]
  • @gamitg 喜欢这样吗? return Html::a('&lt;span class="glyphicon glyphicon-user"&gt;&lt;/span&gt;', $url,['data-pjax' =&gt; false]); 那行不通。如果语法错误,我正在寻找正确的语法。
  • 尝试使用['data-pjax' =&gt; true]进行更改。

标签: gridview yii yii2 yii2-advanced-app


【解决方案1】:

你应该在actionColumn按钮的锚标签选项中添加[ 'data-pjax' =&gt; 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]);
                },
            ]
    ],

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多