Filter Cgridview

Hello, I have broblem in my Cgridview, I would like make filter working, I create this code Manually the sort columns working fine, but input filter not working!!

Controller

   public function actionBeneficiaireSuivi() {





	$model =new LigneCommande('searchConsultantInfos');


	


	$model->unsetAttributes(); 


	


	$id_consultant = ''; 


	if(isset($_GET['id'])){


		$id_consultant = $_GET['id']; 


		$model->attributes = $id_consultant;


	}


	


	$params =array(


	 'model'=>$model,


	);


	


	$this->render('beneficiaireSuivi', $params);


	


}

In View Page (beneficiaireSuivi)

<?php

Yii::app()->clientScript->registerScript(‘searchConsultantInfos’, "

&#036;('.search-button').click(function(){


	&#036;('.search-form').toggle();


	return false;


});


&#036;('.search-form form').submit(function(){


	//console.log( &#036;(this).serialize() );


	&#036;.fn.yiiGridView.update('consultant-grid', {


		data: &#036;(this).serialize()


	});


	return false;


});

");

?>

<?php echo CHtml::link(Yii::t(‘app’, ‘Advanced Search’),’#’,array(‘class’=>‘search-button’)); ?>

<div class="search-form" style="display:none">

&lt;?php


&#036;this-&gt;renderPartial('_searchBenefSuivi', array(


    'model' =&gt; &#036;model,


));


?&gt;

</div>

<?php

$this->widget(‘zii.widgets.jui.CJuiTabs’, array(

	'tabs'=&gt;array(


	&quot;Liste des béneficiaires&quot;=&gt;array(


		&quot;id&quot;=&gt;&quot;admin&quot;,


		&quot;content&quot;=&gt;&#036;this-&gt;renderPartial('_renderPrestation', array(


				'model'=&gt;&#036;model,


			),


			&#036;this


		)


	),


),


	'options'=&gt;array(


    'collapsible'=&gt;false,


	),


'id'=&gt;'tabs',


'headerTemplate'=&gt;'&lt;li&gt;&lt;a href=&quot;{url}&quot; title=&quot;{title}&quot;&gt;{title}&lt;/a&gt;&lt;/li&gt;',


'htmlOptions'=&gt;array('style'=&gt;'display:none'),

));

?>

In In View Page (_renderPrestation.php)

?php

$pageSize = Yii::app()->user->getState(‘pageSize’,Yii::app()->params[‘defaultPageSize’]);

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

'id'=&gt;'consultant-grid',


'dataProvider' =&gt; &#036;model-&gt;searchConsultantInfos(),


'ajaxUpdate' =&gt; 'child-grid',


'filter' =&gt; &#036;model,


'columns' =&gt; array(


	


	array(


		'name' =&gt; 'LigneCommandeID',


		'value' =&gt; 'CHtml::encode(&#036;data-&gt;LigneCommandeID)',


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


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:80px'),


	),


	


	array(


		'name'=&gt;'NomBenef_search',


		'htmlOptions'=&gt;array('style'=&gt;'text-align:left;'),


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:100px'),


		'value' =&gt; '&#036;data-&gt;refBeneficiaire-&gt;NomBenef',


	),


	array(


		'name'=&gt;'PrenomBenef_search',





		'htmlOptions'=&gt;array('style'=&gt;'text-align:left;'),


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:100px'),


		'value' =&gt; '&#036;data-&gt;refBeneficiaire-&gt;PrenomBenef',


	),


	array(


		'name' =&gt; 'DateEntree',


		'header' =&gt; 'Date Entrée',


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


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:80px'),


		'value' =&gt; 'CHtml::encode(&#036;data-&gt;DateEntree)'


	),


	array(


		'name' =&gt; 'DateSortie',


		'header' =&gt; 'Date Sortie',


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


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:80px'),


		'value' =&gt; 'CHtml::encode(&#036;data-&gt;DateSortie)'


	),


	array(


		'name'=&gt;'FullNumCom_search',


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


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:70px'),


		'value' =&gt; 'CHtml::encode(&#036;data-&gt;refCommande-&gt;FullNumCom)',





	),


	array(


		'name' =&gt; 'RefPrestationID',


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


		'headerHtmlOptions' =&gt; array('style' =&gt; 'width:80px'),


		'value' =&gt; 'CHtml::encode(&#036;data-&gt;refPrestation-&gt;CodePresta)'


	),


	





)

));

?>

AND in Model Page

public function searchConsultantInfos()

{


	


	&#036;criteria = new CDbCriteria;


	


	if(isset(&#036;_GET['id']) &amp;&amp; isset(&#036;_GET['id_presta']) ){


		&#036;criteria-&gt;condition = 'RefConsultantID = :ConsultantId AND RefPrestationID = :PrestationID';


		&#036;criteria-&gt;params = array (


			':ConsultantId' =&gt; &#036;_GET['id'],


			':PrestationID' =&gt; &#036;_GET['id_presta']


		);


		&#036;criteria-&gt;compare('RefConsultantID', &#036;_GET['id'], true);


		&#036;criteria-&gt;compare('RefPrestationID', &#036;_GET['id_presta'], true);


	}


	


	if( isset(&#036;_GET['id_presta']) &amp;&amp; ( &#036;_GET['id_presta'] == '0' || &#036;_GET['id_presta'] =='' ) ){


		&#036;criteria-&gt;condition = 'RefConsultantID = :ConsultantId';


		&#036;criteria-&gt;params = array (


			':ConsultantId' =&gt; &#036;_GET['id']


		);


		&#036;criteria-&gt;compare('RefConsultantID', &#036;_GET['id'], true);


	}








	&#036;criteria-&gt;with=array('refBeneficiaire', 'refCommande');





	&#036;criteria-&gt;together = true;


	


	&#036;criteria-&gt;compare('LigneCommandeID', &#036;this-&gt;LigneCommandeID, true);


	


	&#036;criteria-&gt;compare('refBeneficiaire.NomBenef', &#036;this-&gt;NomBenef_search);


	


	&#036;criteria-&gt;compare('refBeneficiaire.PrenomBenef', &#036;this-&gt;PrenomBenef_search);





	&#036;criteria-&gt;compare('DateEntree',&#036;this-&gt;convertDatetoEn(&#036;this-&gt;DateEntree) );


	


	&#036;criteria-&gt;compare('DateSortie',&#036;this-&gt;convertDatetoEn(&#036;this-&gt;DateSortie) );





	&#036;criteria-&gt;compare( 'refCommande.FullNumCom', &#036;this-&gt;FullNumCom_search );





	&#036;criteria-&gt;compare('DateSortie', ' &gt; '.date(&quot;Y-m-d&quot;) );


	


	&#036;criteria-&gt;group = 'DateEntree, DateSortie';


	


	&#036;sort = new CSort();


	&#036;sort-&gt;attributes = array(


	  'LigneCommandeID'=&gt;array(


	    'asc'=&gt;'LigneCommandeID',


	    'desc'=&gt;'LigneCommandeID desc',


	  ),


	  'NomBenef_search'=&gt;array(


	    'asc'=&gt;'refBeneficiaire.NomBenef',


	    'desc'=&gt;'refBeneficiaire.NomBenef desc',


	  ),


	  'PrenomBenef_search'=&gt;array(


	    'asc'=&gt;'refBeneficiaire.PrenomBenef',


	    'desc'=&gt;'refBeneficiaire.PrenomBenef desc',


	  ),


	  'FullNumCom_search'=&gt;array(


	    'asc'=&gt;'refCommande.FullNumCom',


	    'desc'=&gt;'refCommande.FullNumCom desc',


	  ),


	  'DateEntree'=&gt;array(


	    'asc'=&gt;'DateEntree',


	    'desc'=&gt;'DateEntree desc',


	    'default'=&gt;'desc',


	  ),


	  'DateSortie'=&gt;array(


	    'asc'=&gt;'DateSortie',


	    'desc'=&gt;'DateSortie desc',


	    'default'=&gt;'desc',


	  ),


	);


	


	


	


	return new CActiveDataProvider(get_class(&#036;this), array(


		'pagination'=&gt;array(


			'pageSize'=&gt;10


		),


		'criteria'=&gt;&#036;criteria,


		'sort'=&gt;&#036;sort,


	));


}
  • $model->attributes = $id_consultant;
  • $model->id = $id_consultant;

Thnx marianzburlea, I test this but but that not working, I add this lines Into the “actionBeneficiaireSuivi()” function : And That’s working fine :

public function actionBeneficiaireSuivi() {

$modele->unsetAttributes();

if(isset($_GET[‘LigneCommande’])){

&#036;modele-&gt;attributes = &#036;_GET['LigneCommande'];


		


&#036;modele-&gt;NomBenef_search =  &#036;_GET['LigneCommande']['NomBenef_search'];


&#036;modele-&gt;PrenomBenef_search =  &#036;_GET['LigneCommande']['PrenomBenef_search'];


&#036;modele-&gt;DateEntree =  &#036;_GET['LigneCommande']['DateEntree'];


&#036;modele-&gt;DateSortie =  &#036;_GET['LigneCommande']['DateSortie'];


&#036;modele-&gt;FullNumCom_search =  &#036;_GET['LigneCommande']['FullNumCom_search'];


&#036;modele-&gt;CodePrestation =  &#036;_GET['LigneCommande']['CodePrestation'];


&#036;modele-&gt;Ident_search =  &#036;_GET['LigneCommande']['Ident_search'];

}

}

man, can you format it? it’s a pain to look through it




if(isset($_GET['id']) && isset($_GET['id_presta']) )



you cannot search by one id, so…