CGridView Filters Not Filtering Data

So I am very new to both PHP and Yii but I have been able to generate a useful webapp using CGridView that is fully functional with the exception of the filter bars. When anything is typed the return is the grid of unfiltered results. I have a database with a table filled with transaction information and a table with companies that have completed those transactions.

My Model looks like this:




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('trx_id',$this->trx_id);

		$criteria->compare('entity_company_all_company_id',$this->entity_company_all_company_id);

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

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

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

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

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

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


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,



My view looks like this:




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

    'id'=>'trx-grid',

    'dataProvider'=>$dataprovider,

    'filter'=>$model,

    'pager'=>array(

        'header'=>'',

        'firstPageLabel'=>'<<',

        'prevPageLabel'=>'<',

        'nextPageLabel'=>'>',

        'lastPageLabel'=>'>>',

    ),

    

	//$trxRoundName = $model->trxRound->trx_round_name;

	//$trxEntity = $model->trxEntity->entity_name;

	//$trxIndSegDesc = $model->trxIndSegment->trx_ind_seg_description;

	//$trxType = $model->trxType->trx_type_name;

	

    'columns'=>array(

    

    	array( 'name' => 'entity_company_all_company_id', 

			   'value'=>'$data->entityCompanyAllCompany->company_name', 

			   'header'=> 'Company'),


    	array( 'name' => 'investor_name', 'header'=> 'Investor'),

    	array( 'name' => 'trx_industry', 'header' => 'Industry'),

    	array( 'name' => 'trx_stage', 'header' => 'Series'),

    	array( 'name' => 'trx_amount', 'header' => 'Total Raise (000s)'),

    	array( 'name' => 'trx_date', 'header' => 'Date'),

    	array( 'name' => 'trx_product_stage', 'header' => 'Product Status'),

   		array( 'name' => 'trx_product_description', 'header' => 'Product Description'),

)

));



Any tips would be greatly appreciated.

Otter,

this wiki covers filtering and sorting of CGridViews on the default model (fields in the main table) and the related model (fields in accompanying table):

http://www.yiiframework.com/wiki/323/dynamic-parent-and-child-cgridciew-on-single-view-using-ajax-to-update-child-gridview-via-controller-with-many_many-relation-after-row-in-parent-gridview-was-clicked/#hh7

Still haven’t been able to figure it out. I have updated my model to this:




public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria(array(

		'with'=>'entityCompanyAllCompany'));

		

		

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

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

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


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

				'criteria'=>$criteria,

				'pagination'=>array(

						'pageSize'=>Yii::app()->params['pageSize'],

						'pageVar'=>'page',

						),

				'sort'=>array(

						'defaultOrder'=>'company_name',

						'sortVar'=>'sort',

						'attributes'=>array(

								'company_name',

								'trx_industry',

								'trx_stage',

								'trx_amount',

								'trx_date',

								

								

								),

							),

						));

	}



I have a few of the filters as functional drop down menu’s but the data will never filter based on my selection. Anybody?

Where do you define $dataprovider? May be there is a problem there.

Try to change this line:


 'dataProvider'=>$dataprovider, 

to this line





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



I have done that but it is still not working.

View looks like this:




<?php

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

    'id'=>'trx-grid',

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

    'filter'=>$model,

    'pager'=>array(

        'header'=>'',

        'firstPageLabel'=>'&lt;&lt;',

        'prevPageLabel'=>'&lt;',

        'nextPageLabel'=>'&gt;',

        'lastPageLabel'=>'&gt;&gt;',

    ),



You need to make sure that you also have it in your controller:





	public function actionMyaction()

	{

		$model=new Mymodel('search');

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

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

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


		$this->render('myview',array(

			'model'=>$model,

		));

	}




Fixed! Thank you

Backslider<< Thanks you so much.

please some help, i use my own function and not search, i follow all the steps with the new funtion into the model, into controller and in CGridview, but filters are not working. What i’m missing?