No filter box at CGridView

Hi!

I have two AR classes, User and Domain. They are connected by the relations() function of the User class:




'domain'=>array(self::BELONGS_TO,'Domain','domainId'),



A list of users with their related domain should be displayed in a CGridView. The related action is defined as




public function actionManage()

	{

		$model = new User('search');

		$model->with('domain');

		

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['User']))

			$model->attributes=$_GET['User'];	

		$this->render('manage',array('model'=>$model));

	}



and the Grid itself as




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

	'id'=>'user-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'username',

		'domain.name:text:Domain',

		array(

			'header'=>'Domain',

			'name'=>'domain.name',

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

			'filter'=>array('domain1','domain2')

		),

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



I created the column for the domain name using two different ways - but none of them generates a search box - the box is generated only for the first column.

I tried to add the filter argument (as read in the documentation) to generate a Drop Down List, but this didn’t help either.

Did I forget something or what else can I do to get the filter box?

Thanks in advance!

I think that CGridView cannot understand what property of the model should use.

Try adding a new property to the model on user, named domainName, add to safe attributes and add the addCondition in the function search.

Then in the cgridView:




                array(

                        'header'=>'Domain',

                        'name'=>'domainName',

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

                        'filter'=>array('domain1','domain2')

                ),



This should work.