我正在使用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结束之后 - 它不会等待,直到来自服务器的响应。单击按钮后立即工作
我做错了什么?
先谢谢
答案 0 :(得分:1)
尝试
'success' => "js:function() { $.fn.yiiGridView.update('user-grid') }"