I have a dropdown with values that filter the gridview in the same view. When the user selects a value in the dropdown the gridview updates accordingly.
the dropdown:
echo CHtml::dropDownList('program_id', '', $arr2,
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('salesStatement/UpdateAjax'),
'update'=>'#outlet',
'data'=>'js:jQuery(this).serialize()',
'success'=>'function(data) {
$.fn.yiiGridView.update("sales-statement-grid", {data: $(this).serialize()});
}',
)
)
);
the controller:
public function actionUpdateAjax()
{
$outlets = FS::model()->findAll(array(
'select'=>'*',
'condition'=>'is_enabled=:is_enabled',
'params'=>array(':is_enabled'=>1),
));
$arr = array();
foreach($outlets as $value) {
$arr[$value->program_id]=$value->description;
}
$data = array();
if (IsSet($_POST['program_id'])) {
$data["program_id"] = (IsSet($_POST['program_id'])) ? $_POST['program_id'] : 0;
$data["outlet"] = $arr[$_POST['program_id']];
$this->renderPartial('_ajaxContent', $data, false, true);
}
}
on the view I have a div as such:
<div id="outlet" class="well well-small">Current Outlet</div>
and the _ajaxContent.php file:
/*
* set the session variable
*/
Yii::app()->session['cur_program_id'] = $program_id;
/*
* update the label on the view
*/
echo "<h2>$outlet</h2>";
Now the question is: when I comment out the "success" line in the dropdownlist ajax array, the div tag contents get updated fine, but then the gridview does not update. And vice-versa, if the "success" line is not commented out, the gridview updates fine, but the div tag contents do not get updated…