CGridView Filters with Pagination

Got a slight issue here. I enter a value in one of the filter columns and then tab away - the filter is applied. I then use the pager to go to another page - again works fine. I then change the filter value and tab away - but the original filter value remains.

Is anyone else able to replicate this?

Anyone able to replicate this? Is this the intended behaviour or is there a bug somewhere?

Same issue with me…

I reported this issue (http://code.google.com/p/yii/issues/detail?id=1676) but its status is ‘Invalid’ ?

This issue is totally unclear…

If you tab away, then you’re essentially canceling the action, aren’t you?

So the behavior you get is actually the expected.

Or, am I out to lunch? :)

Well you can tab away or u can click away - essentially it’s just a way of submitting the request!

I will list the steps again, hopefully it should be more clear. To reproduce, you will need a large dataset and have pagination and filters enabled in your CGridView.

  1. Enter a value in one of the filter columns, then press tab key. The results should update.

  2. Use the paging buttons to go to another page in the results (the filter value should still be the same).

  3. Change the filter value and then press the tab kay. You will notice that the filter value goes back to your original value and the results don’t update.

Of course, it isn’t.

Click or Enter or Space submits.

Everything else cancels, like tab or escape.

In most UI books anyway.

OK, well where I have said press tab, you can press enter instead. Same thing happens.

Doesn’t happen in my grid.

What actually submits is not tab itself, but up or down arrows.

You can’t change any value by just tabbing.

When you say ‘same thing’ do you mean nothing?

How do you initiate the actual change if you only use tab or enter?

When I change the value of the filter by using the drop down, the change triggers as soon as I change the value.

As expected.

I don’t even get the chance to use my tab key.

And if I enter text into a filter text field, it is commit when I navigate away.

Not because I used tab, but because it’s applied upon exit.

Confusing.B)

I should have mentioned this was in a module…

The problem can be fixed by adding the following UrlRule:


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

Hopefully this might help someone who experiences the same problem!

THANKS… GSTAR

Thanks for figuring that one out for me! I was having a painful time until I found this thread. Nice work!

I don’t know what kind of grid jacmoe uses, but I always press tab to navigate away from a filter and trigger the ajax.

It should be noted that this problem only occurred for me when using the grid from a module AND setting the urlFormat to PATH.

Thank you for sharing your solution. It worked for me.

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'),

   // ...

Works perfectly, thank you very much, MetaYii! :)