Clistview Sort Dropdown

Is it possible to render the sortable attributes in a dropdownlist, for example:

sort by:

  • popular

  • name (a-z)

  • name (z-a)

  • price (low->high)

  • price (high->low)

Clicking on one of these options should automatically trigger the sorting.

Dear Friend

Let me have a table [b]item/b

Make a drop down:




echo CHtml::dropDownList('sort','',array(

	'popularity DESC'=>"Popular",

	'name ASC'=>'Name(A->Z)',

	'name DESC'=>'Name(Z->A)',

	'price ASC'=>'Price(Low->High)',

	'price DESC'=>'Price(High->Low)'

	

	),array('id'=>'sortDrop'));



Widget:




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

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

	'id'=>'item'

)); ?>



Javascript:




Yii::app()->clientScript->registerScript('specialSort','

	$("body").on("click","#sortDrop",function(){

			$.fn.yiiListView.update("item",{data:{sort:$(this).val()},type:"POST"})	

		});

');



Controller:




public function actionIndex()

	{   

                $sort='popularity DESC';

		if(isset($_POST['sort']))

			$sort=$_POST['sort'];


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

			'criteria'=>array('order'=>$sort)

			));


		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));

	}