CGridView filter does not filter data

I am able to sort my data fine. Even the filter shows up sorted. The problem is that the filter does not filter the data! I am calling another active record into the current record. When I select an item from the filter dropdown, nothing happens. Please help!

MODEL:




public $gGeneSymbol_search;


public function rules(){

return array(

array('gGeneSymbol_search', 'safe', 'on'=>'search'));}


public function relations(){

  return array(

    'geneName'=>array(self::BELONGS_TO, 'Gene', 'gene_id'))

}


public function attributeLabels(){

return array(

'gGeneSymbol_search' => 'Gene');}


public function search(){

$criteria->compare('geneName.gGeneSymbol', $this->gGeneSymbol_search, true);

return new CActiveDataProvider($this, array(

  'criteria'=>array( 

    'with'=>array('geneName')),

	'sort'=>array(

	  'attributes'=>array(

             'gGeneSymbol_search'=>array(

	         'asc'=>'geneName.gGeneSymbol',

                 'desc'=>'geneName.gGeneSymbol DESC'),		




VIEW:




	'columns'=>array(

	   array(  

	      'name'=>'gGeneSymbol_search', 

	      'type'=>'raw',

	      'value'=>'$data->geneName->gGeneSymbol',

	     [b]'filter'=>CHtml::listData(Gene::model()->findAll(array('order'=>'gGeneSymbol')), 'gene_id', 'gGeneSymbol')[/b], ),



Thank you!

Hi. Can you include what comes before ‘columns’ in your view?

And please edit your post and use code or php tags around your code.

you first declare $criteria variable and apply your filter, and then you are not passing it to CActiveDataProvider but create new one (in “array()” notation) with only ‘with’ attribute. You should add $criteria->with to the main variable and pass whole criteria obcject to data provider…

redguy - Thank you so much!

tellibus - thanks for the tip on code display.

I’ve changed my code to this below, and now it works!




$criteria->with = array('gGeneSymbol_search'=>array('select'=>'{{Genes}}.*') );

$criteria->compare('t.gene_id',$this->gGeneSymbol_search,false);

						

return new CActiveDataProvider($this, array(

'criteria'=>$criteria,