Filtering A Model For Cgridview

How can i filter a model inside my controller for CGridView and let user search it through the CGridView search?

If i filter like this




		$model=new MyObject('search');

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

		

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

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

		

		$dataProvider = new CActiveDataProvider($model, array(

			

		  'criteria'=>array(

		  	"join"=>"LEFT JOIN other_table ON other_table.field=field",

			'condition'=>" other_field = ".$id." ",

			

		  ),


		  

      	));



and load the cgridview like this




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

	'id'=>'corsi-grid',

	'dataProvider'=>$corsi_frequentati[1], // $dataProvider

	'filter'=>$corsi_frequentati[0], // $model



I can’t filter it later

Take a look at this link

Thanks, but my CGridView is inside a view of another model. Will it work?

Ok, i found a solution (thanks to Topher from http://stackoverflow.com/questions/19112405/yii-cgridview-dataprovider-and-filter )

"




...

$model->setAttributes($attr);


$newDataProvider=$model->search();

$myDataProvider->criteria->mergeWith($newDataProvider->criteria);


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

...



"