0
我在我的控制器:Yii通過ajax按鈕更新cgridview不起作用。
public function actionFilterClients {
if (Yii::app()->request->isAjaxRequest) {
if (isset($_POST['category_id'])) {
$criteria = new CDbCriteria;
$criteria->condition = "user_id=:user_id";
$criteria->params = array(':user_id' => Yii::app()->user->id);
$criteria->compare('category_id',$_POST['category_id'],true);
$dataProvider = new CActiveDataProvider('Client', array(
'criteria'=>$criteria,
));
$this->renderPartial('transfer_step_3' , array('dataProvider'=>$dataProvider)) ;
}
}
}
以我除其他事項外視圖我有:
<?php $filter=$this->beginWidget('CActiveForm', array(
'id'=>'client-filter-form',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('class'=>'form-horizontal'),
)); ?>
<label for="category_id">View clients in category:</label>
<?php echo CHtml::dropDownList('category_id','',Client::clientCategories(), array('options' => array('2'=>array('selected'=>true)))); ?>
<?php
echo CHtml::ajaxButton(
'Filter Clients',
'filterclients',
array(
'type'=>'POST',
'update' => 'client-grid' ,
'success' =>"function(data) {
\$.fn.yiiGridView.update('client-grid');}",
)
);
?>
<?php $this->endWidget(); ?>
和
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'type'=>'bordered striped condensed',
'id'=>'client-grid',
'ajaxUpdate' => true ,
'rowCssClassExpression'=>'($data->duplicate==2)?"yellow":($data->duplicate==1?"blue":"")',
'dataProvider'=>(isset($dataProvider)?$dataProvider:$clients->moveclients()),
'template'=>"{items}\n{pager}",
'columns'=>array(
array(
'class'=>'CCheckBoxColumn',
'selectableRows'=>2,
'id'=>'clients',
),
'name',
'surname',
'telephone',
'email',
array(
'header'=>'Category',
'name' => 'category_title',
'type' => 'raw',
'value' => '$data->category->title',
),
),
)); ?>
因爲這是一個多步驟的形式中,cgridview dataprovider默認列出所有客戶端($ clients-> moveclients()列出所有客戶端)。
ajax按鈕將category_id
正確地發佈到客戶端/ filterclients url。
我可以用螢火是actionFilterClients正確返回呈現的HTML(與正確的客戶端)看到,但在GridView不更新......
爲什麼沒有任何想法?
請從您的代碼中刪除此行,看看有什麼需要? '成功'=>「函數(數據)$ .fn.yiiGridView.update('client-grid');}」 –
現在filterclients正確調用,但螢火蟲POST響應爲空 – ImWorkingOnIt
好吧,看起來像isset $ _POST)返回false,因此如果代碼不在裏面。請寫下這些行CVarDumper :: Dump($ _ POST,100,true); die()緊接着你檢查的地方isAjaxRequest –