CGridView pagination and filtering

Hi,

I have a problem with filtering my CGridView.

I filter the data from a CActiveForm and all works fine unless I start paginate the grid.

when I go to page number 2 the filter doesn’t work more.

from bugzilla the generated url for the search (username=p) on the first page is:

http://localhost/siteMVC2/index.php/admin/user/admin?User[Username]=p&User[DB]=&User[IsActive]=&ajax=user-grid (it works well)

on page number 2 the same search gives the following url:

http://localhost/siteMVC2/index.php/admin/user/admin/User[Username]//User[DB]//User[IsActive]//ajax/user-grid/User_page/2?ajax=user-grid&User[Username]=p&User[DB]=&User[IsActive]=

the results aren’t filetered.

any help would be appreciated.

problem resolved following the suggestion in:

http://www.yiiframework.com/forum/index.php?/topic/10825-cgridview-filters-with-pagination/page__p__53248__hl__CgridView+page+filter#entry53248

It was a routing problem. Using the grid from a module needs adding the folloowing rule to urlManager:


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

Thanks for figuring that one out for me! I was having a painful time until I found this thread. Nice work! It should be noted that this problem only occurred for me when using the grid from a module AND setting the urlFormat to PATH.

As off Yii 1.1.8 this workaround doesn’t work anymore, at least for my config:




   'urlManager' => array(

  	'urlFormat' => 'path',

  	'caseSensitive'=>true,

  	'rules' => array (

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

  	),

   ),

But it seems that passing explicitly the ajaxUrl in the widget inclusion solves the problem:


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

	'id' => 'whois-grid',

	// blah blah blah

   'ajaxUrl'=>Yii::app()->createUrl('/module/controller/action'),

   // ...