Yii2:窗口弹出窗口中的pjax

时间:2015-11-02 13:37:44

标签: php jquery modal-dialog yii2 pjax

首先,对不起我的英语......

我在窗口弹出窗口中有一个CRUD,但是我无法在没有刷新页面的情况下更新ajax成功(插入,更新和删除)中的网格并关闭模态。

成功ajax:

}).done(function(data) {
        $('#div-form').html(data.form);
        if(data.success){
            $.pjax.reload({container:'#pjax-resposta-possivel'});
        }
})

在行动控制器中:

    public function actionSalvarRespostaPossivel()
    {

        $return = [
            'success' => false,
            'form' => null
        ];
        Yii::$app->response->format = Response::FORMAT_JSON;
        $post = Yii::$app->request->post();

        if ($post && $post['RespostaPossivelDetalhes']['id']) {
            $model = RespostaPossivelDetalhes::findOne([
                $post['RespostaPossivelDetalhes']['id']
            ]);
        } else {
            $model = new RespostaPossivelDetalhes();
        }

        if ($model->load($post) && $model->save()) {
            $return['success'] = true;

            $tblcacd_id = $model->tblcacd_id;
            $model = new RespostaPossivelDetalhes();
            $model->tblcacd_id = $tblcacd_id;

        }

        $return['form'] = $this->renderPartial('_formRespostaPossivel', [
            'model' => $model
        ]);

        return $return;
    }

在视图中:

<?php Pjax::begin(['enablePushState' => false, 'id' => 'pjax-resposta-possivel'])?>

<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'emptyCell' => ' ',
        'summary' => "Exibindo {begin} - {end} de {totalCount}.",
        'layout' => "{pager}\n{items}\n{summary}",
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'chave',
            'desc_resposta',
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{update}  {delete}',
                'contentOptions'=>['style'=>'width: 10%;text-align:center;'],
                'buttons' => [
                    'update' => function ($url, $model)
                    {
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', false, [
                            'data-id' => $model->id,
                            'class' => 'btn-update-resposta',
                            'style' => 'cursor:pointer;'
                        ]);
                    },
                    'delete' => function ($url, $model)
                    {
                        return Html::a('<span class="glyphicon glyphicon-trash"></span>', false, [
                            'data-id' => $model->id,
                            'class' => 'btn-delete-resposta',
                            'style' => 'cursor:pointer;'
                            ]);
                    }

                ]
            ],
        ],
    ]); ?>


<?php Pjax::end(); ?>

我可以在不关闭模态的情况下更新网格吗?

由于

0 个答案:

没有答案