Filter on gridview from related model


I have an application with companies and documents from those companies

With the help of gii i have created an MVC to CRUD companies and documents and customized it to my needs.

One change i made was the ability to show in a gridview in the company view the documents related to that company.

This way when i view a company i can see the companies documents.

I managed to do this using a function in the documents model to fetch the documents from a specified company (See code bellow)

Company View Code

<br /><h2> <?php echo Yii::t('app','These documents belongs to this Company:') ?> </h2>


    $locale = CLocale::getInstance(Yii::app()->language);

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







            	'header'=>Yii::t('app','Document Category'),




                'value'=>'($data->idDoctype0->idDocCategory0->periodic) ?  Yii::t(\'app\',\'Yes\') : Yii::t(\'app\',\'No\')',






            	'header'=>Yii::t('app','Document Type'),








                'header'=>Yii::t('app','File Size (bytes)'),














        'htmlOptions'=>array('style'=>'cursor: pointer;'),

        'selectionChanged'=>"function(id){if ($.fn.yiiGridView.getSelection(id) != '') {window.location='" . Yii::app()->createUrl('client/displayDocument/id') . "' + '/' + $.fn.yiiGridView.getSelection(id);}}",


Documents Model Function

	public function searchByCompanyId($id_company)


		$criteria=new CDbCriteria;


                $criteria->order = "year";


		return new CActiveDataProvider('Documents', array(




I have two problems:


[*]Sorting does not work properly

[*]Filter does not work properly


To use filtering i use:


I see the call being made in web server access log but nothing changes

Help anyone ?

list what you want in the filter. If you want to filter a function that exists in the model, do so:


if not do so:

'filter' => array('yes' => 'YES', 'NO' => 'NO'),

and do it

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

        'id' => 'colaborador-grid',

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

        'filter' => $model,

Maybe this will help GridView Filtering of Relational Data ring-of-relational-data/