CGridView searching on relation

Hello, I have a CGridView and one of the columns has a dropdown list as a filter for an attribute that is a relation. The relation is:




'engine' => array(self::BELONGS_TO,'Engines','eid','order'=>'name'),



And the CGridView column looks like this:




array(

        'name' => 'eid',

        'header' => 'Engine',

	'filter' => CHtml::listData($engines, 'id', 'name'),

	'value' => '$data->engine->name',

),



The filter is a drop down list of all of the engines. This works just fine, but my problem is that I want to filter the column by name (engine.name) and not id (eid or engine.id). I want to be able to select an engine from the drop down list and then it filters the CGridView by that engine name and not its id. I tried changing the code to:




array(

        'name' => 'eid', //or 'name' => 'engine.name'

        'header' => 'Engine',

	'filter' => CHtml::listData($engines, 'name', 'name'),

	'value' => '$data->engine->name',

),



but either the filter drop down completely disappears or it just plain doesn’t work. Any help is appreciated, thanks.

Check whether this can help you: http://www.yiiframework.com/forum/index.php?/topic/16095-cgridview-filtering-related-tables/page__view__findpost__p__79861

Fouss, explains at the bottom most how to use it with relations

Thanks, his response worked (almost). When I translated his solution with my specific parameters I came up with:




array(

	'name' => 'engine',

	'filter' => CHtml::listData(Engines::model()>findAll(),'name','name'),

	'value' => '$data->engine->name',

),



Unfortunately, when I selected an item in the drop down it just showed the ajax loading gif and then nothing happened. However, when I changed the name attribute of the column to name instead of engine, it worked!




array(

	'name' => 'name', //instead of 'engine'

	'filter' => CHtml::listData(Engines::model()>findAll(),'name','name'),

	'value' => '$data->engine->name',

),



Thanks!

Crap, I just realized that even though the filter is working properly now, I can’t sort by the header when clicking on it. Any suggestions? Thanks.