Ok, here is my code:
this is the first dropdownlist
<div class="row" style="margin:auto">
<?php echo 'Seleccione Seccion'; ?>
<?php echo CHtml::dropDownList('Secciones',$_GET['Secciones'],CHtml::listData(Secciones::model()->findAll(),'secciones','secciones'),array(
'prompt'=>'Seleccione Seccion',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('SeccionesD'),
'update'=>'#Asignaciona_codigoal',
'data'=>array('Secciones'=>'js:this.value')
)));?>
</div>
this is the dropdownlist that gets populated when i change the first one:
<?php echo $form->label($model,'codigoal'); ?>
<?php echo $form->dropDownList($model,'codigoal',CHtml::listData(Alumno::model()->findAllbySql('SELECT Codigo, concat( Nombres, " ", Apellidos ) AS Nombres FROM tbalumnos order by Apellidos'),'Codigo','Nombres'),array('prompt'=>'Seleccione Alumno','class'=>'dDList'));?>
When I select something from this second dropdowlist it triggers this javascript:
Yii::app()->clientScript->registerScript('search', "
$('.dDList').change(function(){
this.form.submit();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('asignaciona-grid', {
data: $(this).serialize()
});
return true;
});
");
This is the code from my controller:
public function actionSeccionesD()
{
$nombreS=$_POST['Secciones'];
$sqlQ='SELECT Codigo, concat( Nombres, " ", Apellidos ) AS Nombres FROM tbalumnos where seccion ="' . $nombreS . '" order by Apellidos';
$contar = Alumno::model()->findAllBySql($sqlQ);
$data=CHtml::listData($contar,'Codigo','Nombres');
echo CHtml::tag('option',array('value'=>''),CHtml::encode('Seleccione Alumno'),true);
foreach($data as $value=>$name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
And this is the grid that I want to refresh when I select from the first dropdownlist:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'asignaciona-grid',
'dataProvider'=>$model->search(),
'summaryText'=>'',
'columns'=>array(
'codigom0.nombre',
array
(
'class'=>'CButtonColumn',
'template'=>'{delete}',
'deleteConfirmation'=>'Borrar la asignacion de la materia?'
)),
'enablePagination'=>false,
));
If I use ‘success’ on my ajax to refresh the grid, it doesnt work because I still have a $_GET variable that points to my model and the grid uses that to search, so what I want to do is unset that variable, but I think I cant do that because then I would be using both a post and a get request on the same page, any ideas? I think the only way would be to hide the grid completely.