Search filter missing for added field in CGriedView

Hi,

following the steps described here

http://www.yiiframework.com/forum/index.php?/topic/11892-display-data-from-other-model-by-some-key/

I added in CGridView a foreign key field showing data from a relationed table. All is working fine, a part that this new field has not the search filter box in the header of the table. How can I add it?

Thanks

Without your code there is not much I can do. However, the most common reason for the filter not being shown is that the name attribute is null for the column in question.

In the model i put the tables into relation with




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(

			'azienda'=>Array(self::BELONGS_TO, 'Azienda', 'azienda_id'),

		);

}

In the admin view file i added the field of the related table (zienda.denominazione):




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

	'id'=>'contatti-grid',

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

	'filter'=>$model,

	'columns'=>array(

		'id_contatto',

		'nome',

		'cognome',

		'azienda_id',

                'azienda.denominazione',

		'tstamp',

		'crdate',

				array(

			'class'=>'CButtonColumn',

		),

	),

)); 



What do you mean with "name attribute is null for the column in question"? Where this attribute has to be configured?

Thanks

This is the guide you probably want. Start over there, and follow those steps exactly. In addition, make sure that the field in the related model you’re trying to search on in is safe. If you are still stuck, come back and let us know!

This was exactly what I nedeed!! Now it works!!!

Thanks