Yii Framework Forum: CGridView Paging with Filter - GET data error - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView Paging with Filter - GET data error Rate Topic: ***** 1 Votes

#1 User is offline   gavinfonseca 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 02-June 09

Posted 29 February 2012 - 04:52 AM

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.
Smile and the world smiles with you. :)
0

#2 User is offline   Narretz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 20-August 11

Posted 25 May 2012 - 03:34 PM

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

#3 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,121
  • Joined: 05-January 12
  • Location:Morocco

Posted 26 May 2012 - 12:03 AM

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?
0

#4 User is offline   Narretz 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 20-August 11

Posted 26 May 2012 - 12:23 PM

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?
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users