CGridView Paging with Filter - GET data error

Hello,

I am using a CGridView (very simple query ‘select * from courses’ ) with paging and filters at the bottom.

The filters work when I don’t use paging. And the paging works fine. However if I first filter the page and then use the paging (eg: go to the 2nd page) and then try to change the filter it doesn’t work.

Steps to simulate:

  • CGridview with enough records for paging to show and filter(s) (eg: list of people with a drop down filter for their gender).

  • Now filter using the drop down (there should be enough records so you can page).

  • Click on Page 2

  • Now filter the drop down again; the filter will reset to the previous filter.

I tried this on most of my pages and using the google web developer tools and noticed that the values in the ajax request are being sent properly (eg if my first filter was “Male” and after paging I’m filtering “Female”; the query string the corresponding value is “Female”). However, if I print the $_GET the corresponding value is of the previous filter(ie it shows as “Male”).

Please help me this is really urgent. Let me know if you would like me to post the code too. Thank you in Advance.

Regards,

Gavin.

Hi gavin,

did you eventually figure out what caused this? I have the same problem, and really no clue what could cause it.

Hi Gavin & Narretz.

I’ve just tried on a working webapp:

  • I have 8 columns in my CGridView

  • Two of them have dropdown filters, the others text fields

  • I have 27 records

  • I filter a column with one of the dropdowns, it gives me 22 records

  • I go page 2

  • I try the filter again and it works

  • I even try the other dropdown to mix the two filters, and it works

Do you have a different use case to reproduce the behavior you’re talking about?

PS We’re talking filters in the grid, right?

edit: Ok, I got it. Problem is when you use urls in path format, and have either a module or subfolders for your controllers the ajax url is wrongly created when filtering after you paged. you have to add an explicit url rule to handle these cases. So I just changed the url rules to:


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

And so on.

Hi bennouna, yes I used the filters in the grid. In my case, it is a textfield, but the behavior is the same.

I could be because I search attributes of related models in the gridview; however, the problem occurs even when I search native model fields or when I remove all additional fields.

I noticed that it works mostly with the default implementation, i.e. what Gii generated, but now I have one admin action where it works, and one where it doesn’t.

Actually, at the moment I think it might be related to the number of results.

I got something: Seems like the url is wrongly serialized or something: Correct:




http://localhost/master/task/admin?Task%5Bid%5D=&Task%5Btype%5D=&Task%5Bcreate_time%5D=&Task%5Bupdate_time%5D=0000&Task_page=1&ajax=task-grid

Wrong:


http://localhost/master/tasks/taskcomplete/admin/TaskComplete%5Bid%5D//TaskComplete%5Btext%5D//TaskComplete%5Bmissing%5D//TaskComplete%5Bquestion%5D//TaskComplete%5Bcreate_time%5D/2012-05/TaskComplete_page/2/ajax/task-complete-grid?ajax=task-complete-grid&TaskComplete%5Bid%5D=&TaskComplete%5Btext%5D=&TaskComplete%5Bmissing%5D=&TaskComplete%5Bquestion%5D=&TaskComplete%5Bcreate_time%5D=2012&TaskComplete_page=1

Note the many extra slashes and apparently all query parameters are repeated?