0

我正在使用 yii GridView 并创建自定义按钮 - 处理 ajax 请求。

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider' => $dataProvider,
    'id' => 'user-grid',
    'ajaxUpdate' => true,
    'columns'      => array(
        array(
            'name'        => 'date_create',
            'type'        => 'raw',
            'value'       => function($data){
                                return Yii::app()->dateFormatter->format("y/MM/dd",strtotime($data->date_create)).'</br>'.
                                       Yii::app()->dateFormatter->format("HH:mm:ss",strtotime($data->date_create));
                             },
            'htmlOptions' => array('style' => 'white-space: nowrap'),
        ),
        array(
            //'name'        => 'car.model.brand.title',
            'header'      => 'Марка авто',
            //'value'       => 'CHtml::encode($data->car->model->brand->title) . " " . CHtml::encode($data->car->model->title)',
            'htmlOptions' => array('style' => 'white-space: nowrap'),
            'class'       => 'CLinkColumn',
            'urlExpression' => '"/site/car/".$data->id_car',
            'labelExpression' => 'CHtml::encode($data->car->model->brand->title) . " " . CHtml::encode($data->car->model->title)',
        ),
        array(
            'name'   => 'text',
            'value'  => 'CHtml::encode($data->text)',
        ),
        array(
            'class'    => 'CButtonColumn',
            'template' => '{solved}{deleted}',
            'buttons'  => array(
                'solved' => array(
                    'label' => 'Жалоба решена',
                    'url' => 'yii::app()->controller->createurl("admin/adminForms/complaintChangeStatus", array("id" => $data->id,"status" => FormCarComplainStatus::STATUS_SOLVED))',
                    'options' => array (
                            'confirm' => 'Жалоба решена?',
                            'class' => 'btn',
                            'ajax'=>array(
                                'type'=>'POST',
                                'url'=>"js:$(this).attr('href')",
                                'success' => "js:$.fn.yiiGridView.update('user-grid')"
                     )),
                ),
                'deleted' => array(
                    'label' => 'Удалить жалобу',
                    'url' => 'yii::app()->controller->createurl("admin/adminForms/complaintChangeStatus", array("id" => $data->id,"status" => FormCarComplainStatus::STATUS_DELETED))',
                    'options' => array (
                        'class' => 'btn',
                        'confirm' => 'Удалить жалобу?',
                        'ajax'=>array(
                                'type'=>'POST',
                                'url'=>"js:$(this).attr('href')",
                                'success' => "js:$.fn.yiiGridView.update('user-grid')"
                        )),
                )
            ),
            'htmlOptions' => array('width'=>'150px')
        ),
    ),
));

我想在 Ajax 调用结束后更新 GridView 如您所见,我使用 - 'success' => "js:$.fn.yiiGridView.update('user-grid')"

问题是:代码“js:$.fn.yiiGridView.update('user-grid')”在 ajaxCall 结束后无法工作 - 它不会等到响应来自服务器。单击按钮后立即生效

我做错了什么?

预先感谢

4

1 回答 1

1

尝试

'success' => "js:function() { $.fn.yiiGridView.update('user-grid') }"
于 2013-09-12T09:22:02.203 回答