Search order criteria

I want to order search results by using some sort of ajax functions.

For example,

When a user types <bla> into the search textbox and hits the search button, a new page (actionView) displays all items that match the search criteria. (This part works.)

But lower down in the screen there is a dropDownList where you can change the order on how these are displayed.

So far I have (controller)

public function actionView($id)




		$criteria=new CDbCriteria(array(

			'condition'=>'person_id='.$id,

			'order'=>$order,

		));

	

		$dataProvider=new CActiveDataProvider('Sugestion', array(

			'pagination'=>array(

				'pageSize'=>20,

			),

			'criteria'=>$criteria,

		));	

view.php has


<?php 

	$form=$this->beginWidget('CActiveForm', array(

						'action'=>Yii::app()->createUrl($this->route),

						'method'=>'post',

					)); 

        echo CHtml::dropDownList('orden', $select, 

						array('Priority' => 'Priority', 'Date' => 'Date', ));						

        $this->endWidget(); 

        ...

        $this->widget('zii.widgets.CListView', array(

						'dataProvider'=>$dataProvider,

						'itemView'=>'_view',

								)); ?>


?>

I have no idea on how to just send (though Ajax I imagine) the dropDownList item selected and just refresh the CListView.

Thanks in advance

CHtml::dropDownList() accepts a 4th parameter with htmlOptions (see the docs). You can set the onchange attribute there and trigger an update of the listview (give it an id, so you can reference it). Then in your action you need to inspect the $_GET[‘order’] param and update your data provider accordingly. You also may want to add your search term to the data part.


array('onchange'=>"$.fn.yiiListView.update('your-list-id',{ data:{order: $(this).val() }})")

I hope this gives you the idea…