Problem With Cgridview, Pagination And Filters

Hello, I don’t know if this is my mistake, a bug, or the widget is intended to work this way.

The problem is my gridview ignores any filter change after changing the page. If, for example, I go to page 2, back to one, and then filter my model’s name to ‘John’, the displayed rows are exactly the same, and the filter input will be blank as before instead of ‘John’

I really need help for this, I have been trying to find out what is wrong and don’t have a clue so far.

Thank you in advance.

see also afterAjaxUpdate attribute in the CGridView class definition. this attribute points to a JS method, IF your CGridView has attached some customized JS functions then you must call them again after pagination or sorting.

<br><br>




'afterAjaxUpdate' =&gt; "function(){  do some stuff after pagination or sorting  }"


<br>or


'afterAjaxUpdate' =&gt; "my_function_name"



<br><br>normally this works fine without using afterAjaxUpdate when using the provided filter mechanism, maybe your are using a customized filtered method or maybe an outdated Jquery version.<br>

Thank you for your reply.

I have no idea how I could fix it with afterAjaxUpdate as I dont know what is breaking it :unsure:

Im not using any special filtering method, just the default, and I dont think its a problem with JQuery.

I don’t know if this is the problem, but I have found something weird.

The URL for filtering normally, in this given example (this one works) is:


index.php/user/user?User%5Bfusername%5D=&UserSearch%5Bfusername%5D=&UserSearch%5Bflat%5D=58.623955&UserSearch%5Bflng%5D=14.880648&UserSearch%5Buser_type%5D=Normal#yw0_tab_1

And after changing pages, the url (which doesn’t work) becomes:


index.php/user/user/index/UserSearch[fusername]//UserSearch[flat]/58.623955/UserSearch[flng]/14.880648/UserSearch[user_type]/Normal/User[fusername]?UserSearch[fusername]=&UserSearch[flat]=58.623955&UserSearch[flng]=14.880648&UserSearch[user_type]=Everything#yw0_tab_1

Is this a normal behaviour?

maybe a outdated jquery version, use the default provided by yiiframework, and…update your framework. try removing your assets and taking a look at your runtime/application.log and to the browser reported errors (control shift i in your browser displays the error console).

I think you can try the ProcessOutput…when page render or renderPartail…

like


$this->render('index',array('model'=>$model,false,true));

I am not sure it’s works or not

It might be a problem with the url manager’s rules.

Try to set the url format to ‘get’ and see if everything goes right.

And you’d be better show your view and controller code.

Okay, thank you for the advice.

Apparently it works normally without the url manager.

Then how can I make it work keeping the url format? If you still need any code just please let me know.

Now that I know what’s wrong, I have found some people had this same problem before and solved it their own way, I’m still surprised this hasn’t been fixed yet (?)

Thread 1

Thrad 2

Thank you all for your help!

EDIT: In case anyone has to fix this, the best solution for me seems to be adding ‘ajaxUrl’ => $this->createUrl(‘whatever’) to the CGridView.

Sorry for the late response.

Good to know that you have solved the problem.

Personally I don’t think it’s a bug in Yii, but I do think that the url rules can be difficult to manage when you have a module. Showing your url rules may help someone. :)