search as text input for a foreign field in CGridView

I have a column which I show on CGridView like this


 array(

'type'=>'raw',

'value'=>'CHtml::link($data->residence->address1, array("residence/update", "id"=>$data->id));',

'name'=>'residence_id',

),

I also tried this:




public function search() {

        $criteria = new CDbCriteria;


        $criteria->compare('address1', $this->residence_id);

        $criteria->with=array('residence'=>array('select'=>'address1'));


        return new CActiveDataProvider(get_class($this), array(

            'criteria' => $criteria,

        ));

    }

In the residence the address1 is in the safe list.

But I cannot use the ajax filter on the header to enter values from the address1 field.

How can I implement so search should use that foreign relation field on the search?

Try this :




array(

	'type'=>'raw',

	'value'=>'CHtml::link($data->residence->address1, array("residence/update", "id"=>$data->id));',

	'name'=>'residence_id',

	'filter' => CHtml::textField("adresse",(isset($_GET['adresse']) ? $_GET['adresse'] : "")),

),



In your search function in the model : (you must put the name of your table : TABLE)




if(isset($_GET['adresse']) && trim($_GET['adresse'])!="")

      $criteria->addSearchCondition('TABLE.address1',$_GET['adresse']);



Thanks, actually I just had to add the true flag to the compare

[color=#1C2837][size=2][color=#000000]criteria[/color][color=#666600]->[/color][color=#000000]compare[/color][color=#666600]([/color][color=#008800]‘address1’[/color][color=#666600],[/color][color=#000000] $this[/color][color=#666600]->[/color][color=#000000]residence_id, true[/color][color=#666600]);[/color][/size][/color]