Dropdownlist Filter In Cgridview

Code for CGridView:

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'puzzle-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),


'filter'=&gt;&#036;model,


'columns'=&gt;array(


	'id',


	'group.name',


	array(


		'name'=&gt;'group_id',


		'filter'=&gt;CHtml::listData(PuzzleGroup::model()-&gt;findAll(),'id','name'),


	),


	'category.name',


	'phrase',


	array(


		'name'=&gt;'enabled',


		'filter'=&gt;array('Yes'=&gt;'Yes','No'=&gt;'No'),


	),


	array(


		'class'=&gt;'CButtonColumn',


	),


),

));

//‘group.name’,

?>

Relations between the two tables:

public function relations()

{


	// NOTE: you may need to adjust the relation name and the related


	// class name for the relations automatically generated below.


	return array(


		'tbHints' =&gt; array(self::HAS_MANY, 'TbHints', 'puzzle_id'),


		'group' =&gt; array(self::BELONGS_TO, 'PuzzleGroup', 'group_id'),


		'category' =&gt; array(self::BELONGS_TO, 'PuzzleCategory', 'category_id'),


	);


}

Code for search function:

public function search()

{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.





	&#036;criteria=new CDbCriteria;





	&#036;criteria-&gt;compare('id',&#036;this-&gt;id);


	&#036;criteria-&gt;compare('group_id',&#036;this-&gt;group_id);


	&#036;criteria-&gt;compare('category_id',&#036;this-&gt;category_id);


	&#036;criteria-&gt;compare('phrase',&#036;this-&gt;phrase,true);


	&#036;criteria-&gt;compare('enabled',&#036;this-&gt;enabled,true);


	


	return new CActiveDataProvider(&#036;this, array(


		'criteria'=&gt;&#036;criteria,


	));


}

For the above code can anyone please let me know how to create CGridView for Puzzle with dropdownlist filters containind puzzlegroup name from PuzzleGroup which is related to Puzzle with group_id.

Also i want to display PuzzleGroup name instead of id in the CGridView.

Dear JaswalKiranAvtar

Please try to create a column like this.




columns'=>array(

'id',

array(

'name'=>'group_id',

'value'=>'$data->group->name', //single quotes

'filter'=>CHtml::listData(PuzzleGroup::model()->findAll(),'id','name'),

),



The following wiki is very useful one.

Searching and sorting by related model in CGridView

Regards