Cgridview-Missing The Filters Functionality After Switching Pages[Solved]

Hello,

Why CGridView filters misses its functionality after switching pages(pager)?

Hi

Did you modify something of generated code?

Yes,




	public function getAllAds()

	{

    	$criteria=new CDbCriteria;


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

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

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

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

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

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

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

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

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

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

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


    	$criteria->compare('user.username', $this->username,true);

    	$criteria->compare('subCategory.name', $this->subCategoryName,true);

    	$criteria->compare('category.name', $this->categoryName,true);


    	$criteria->with=array('user','subCategory','category');

    	//$criteria->together=true;


    	$sort = new CSort();

    	$sort->attributes = array(

        	'username'=>array(

            	'asc'=>'user.username',

            	'desc'=>'user.username',

        	),

        	'subCategoryName'=>array(

            	'asc'=>'subCategory.name',

            	'desc'=>'subCategory.name',

        	),

        	'categoryName'=>array(

            	'asc'=>'category.name',

            	'desc'=>'category.name',

        	),

        	'title',

        	'create_date',

        	'expiration_date',

    	);


    	return new CActiveDataProvider($this, array(

        	'criteria'=>$criteria,

        	'sort'=>$sort,

    	));

	}






<?php

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

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

	'filter'=>$model,

	'summaryText'=>'',

	//'rowCssClassExpression'=>'$data->getRowCssClass($data->type, $data->status)',

	'cssFile'=>false,

	'columns'=>array(

    	array(

        	'name'=>'title',

    	),

    	array(

        	'name'=>'categoryName',

        	'value'=>'$data->category->name',

        	'header'=>Yii::t('model','Category Name'),

    	),

    	array(

        	'name'=>'subCategoryName',

        	'value'=>'empty($data->sub_category_id) ? null : $data->subCategory->name',

        	'header'=>Yii::t('model','Sub Category'),

    	),

    	array(

        	'name'=>'username',

        	'value'=>'$data->user->username',

        	'header'=>Yii::t('model','Username'),

    	),

    	array(

        	'headerHtmlOptions' => array('class'=>'date'),

        	'name'=>'create_date',

        	'value'=>'Yii::app()->jdate->date("d M y", (int)strtotime($data->create_date))',

        	'filter'=>false,

    	),

    	array(

        	'headerHtmlOptions' => array('class'=>'date'),

        	'name'=>'expiration_date',

        	'value'=>'empty($data->expiration_date) ? null : Yii::app()->jdate->date("d M y",(int) strtotime($data->expiration_date))',

        	'filter'=>false,

    	),

    	array(

        	'name'=>'type',

        	'value'=>'$data->getType((int)$data->type)',

        	'filter'=>array(

            	'1'=>Yii::t('model','Photo Ad'),

            	'2'=>Yii::t('model','Textual Ad'),

        	),

    	),

    	array(

        	'name'=>'status',

        	'value'=>'$data->getStatus((int)$data->status)',

        	'filter'=>array(

            	'0'=>Yii::t('model','notChecked'),

            	'1'=>Yii::t('model','Checked'),

            	'2'=>Yii::t('model','Paid'),

            	'3'=>Yii::t('model','Verified'),

            	'4'=>Yii::t('model','Active'),

            	'5'=>Yii::t('model','Inactive'),

            	'6'=>Yii::t('model','Expired'),

            	'7'=>Yii::t('model','Blocked'),

        	),

        	'cssClassExpression'=>'$data->getRowCssClass($data->type, $data->status)',

    	),

    	array(

        	'name'=>'leaf',

    	),

    	array(

        	'class'=>'CButtonColumn',

        	'header'=>'Operations',

        	'template'=>'{view}/{update}/{delete}<br>{verify}/{block}',

        	"updateButtonImageUrl"=>false,

        	"viewButtonImageUrl"=>false,

        	"deleteButtonImageUrl"=>false,

        	'buttons'=>array(

            	'verify'=>array(

                	'label'=>Yii::t('application','Verify')

            	),

            	'block'=>array(

                	'label'=>Yii::t('application','Block'),

            	),


        	),

    	),

	),

	'pager'=>array(

    	'header'=>'',

    	'footer'=>'',

    	'firstPageLabel' => '<<',

    	'prevPageLabel'  => '<',

    	'nextPageLabel'  => '>',

    	'lastPageLabel'  => '>>',

	),

))

?>



An important thing:

I created the code with Gii and everything was normal. but when generate the code with Gii inside the Module the problem raised !?

[b]Solved

[/b]Solved with add following rule in urlManager rules:


"<module:\w+>/<controller:\w+>/<action:\w+>"=>"<module>/<controller>/<action>"

CGridView filters not working correctly with pagination

Thanks friends.

Although you solved the problem, I thing there is an issue, The urlManager not solves problems, except if you have already add other rules.

If is set ‘urlFormat’=>‘path’ the “<module:\w+>/<controller:\w+>/<action:\w+>”=>"<module>/<controller>/<action>" rule is required. I am pleased to know more :)

urlManager:




		'urlManager'=>array(

			'urlFormat'=>'path',

        	'showScriptName'=>false,

        	'caseSensitive'=>false,

        	'rules'=>array(

            	'site/signin'=>'site/nopage',

            	'site/index'=>'site/nopage',

            	'signin'=>'site/signin',

            	'contact'=>'site/contact',

            	'signup'=>'site/signup',

            	'user/profile/index'=>'site/nopage',

            	'user/profile'=>'user/profile/index',


            	'verify/<type>/<verifyString>'=>'site/verify',


            	'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

            	"<module:\w+>/<controller:\w+>/<action:\w+>"=>"<module>/<controller>/<action>"

        	),

		),



Exactly! url of module action has the url module/controller/action pattern

so, you had to set it since you use urlFormat path

Thank you for the vote! :)