How to make filter in CGridView for field that is related to AcriveRecord?

I have column in my grid:







$this->module->getCategories() returns array.

But filter dropDownField input dont appears. How to fix that?

the arraty should be a ‘name’=>‘value’ array.

Try using

 CHtml::listData($this->module->getCategories(), 'valueField', 'descriptionField')

Where valueField and descriptionField are two fields of the models.

Problem is that isn’t field of model, it is field of related table.

In my model:

 public function relations()


        return array(

            'category'=>array(self::BELONGS_TO, 'MessageCategory', 'category_id'),           



I need to filter list by ‘name’ attribute of related ‘Category’ AR.

CGridView provides posibility to output this values in grid (‘name’=>‘’). But when I add any valid value to ‘filter’ of the column, filter input don’t displays and don’t generate any errors.

Somebody tried to make filter for column which displays value from related ActiveRecord?

For example: If I add ‘filter’=>array(‘1’=>‘first’,‘2’=>‘second’) to any column that displays fields of model passed to CGridView->filter and CGridView->dataProvider, CGridView draws ‘select’ tag with corresponding items. But when I write it in column that displays data from related AR (‘’), CGridView don’t draws ‘select’ tag at the header of this column

Sorry, my question must be: How to make filter in CGridView for field of AcriveRecord that is related to current AR?

Any ideas?

Could you solve this?

I’m stumbling on the same simple problem…

Could someone explain us the step by step way how to do that stuf?