Whole Gridview Table In Another Model - Filters

I have a model called Person_Event , in which I’m showing the CgridView of the model Person and the column filters are not working.

I tried to use “related model filters” (http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview/) but it doesn’t worked since i don’t show several columns in another model’s grid , but the whole grid of the model Person.

In order to be able to show the grid from the beginning I had to change those 2 lines:



from $model to Person::model().

I thought that it is enough and that the search of the Person model will be called , but it isn’t.

Any ideas why?

You can define the filter for each column.

Below is the code I have:

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














			'filter'=>CHtml::listData($model->findAllBySql('SELECT reference_number

				FROM employee

				GROUP BY reference_number ORDER BY reference_number'), 'reference_number', 'reference_number'),




I have 2 columns where I put a dropDown filter. The filter input is working well , but the rows are not being filtered , so I guess it doesn’t come to the Person’s search method. . .

Other suggestions?

Then check your Person::model()->search() code, and see if you did compare the correct filter inputted.

This is the Person’s search function. I marked by arrows the 4 fields I want to filter:

	public function search($param = array())


		$criteria=new CDbCriteria($param);



		$criteria->compare('first_name',$this->first_name,true); //<-------

		$criteria->compare('last_name',$this->last_name,true); //<-------







		$criteria->compare('level_id',$this->level_id);                 //<------


		$criteria->compare('status_id',$this->status_id, true);














		return new CActiveDataProvider($this, array(









                'desc'=>'tblJobs.type DESC',








And this is person’s CgridView which is in the _form of Person_Event model:

<?php $this->widget('ext.selgridview.SelGridView', array(


	'selectableRows' =>2,

	'dataProvider'=>Person::model()->search(array('join'=>'INNER JOIN tbl_person_job ON tbl_person_job.person_id=id AND tbl_person_job.job_id=1','condition'=>'status_id="active"')),




				'id' => 'selectedIds',






			'htmlOptions'=>array('style' => 'text-align: center;'),




			'htmlOptions'=>array('style' => 'text-align: center;'),	




			'htmlOptions'=>array('style' => 'text-align: center;'),	





			'htmlOptions'=>array('style' => 'text-align: center;'),

			'filter'=>CHtml::listData(Person::model()->findAll(array('order'=>'level_id DESC')),'level_id','level_id'),




			'htmlOptions'=>array('style' => 'text-align: center;'),	



)); ?>

So far - no success. . . :(

Any ideas what am I missing?

I’m also have the same problem… :-[

please help us !

you can remove join tbl_person_job table by relationship, then use with() in your CDbCriteria,

'dataProvider'=>Person::model()->search(array('join'=>'INNER JOIN tbl_person_job ON tbl_person_job.person_id=id AND tbl_person_job.job_id=1','condition'=>'status_id="active"')),

because you defined


When $criteria->together is set true, only a single SQL will be executed for a relational AR query, even if the primary table is limited and the relationship between a foreign table and the primary table is many-to-one.

And also if you defined inner join, most case it only return the record row valid in both table.

That means each person must have job. Otherwise your search result will return null.

Sometimes, it’s not always code issue, maybe a data issue probably.

Did that. Moreover I later removed the job criteria entirely and set the search back to stock - still the table I got wasn’t reacting to the filters . . . .