tags:

views:

369

answers:

3

Hi,

I want to combine pagination with filtering. Since I have a lot of filters I do not want to send them per GET request, since the URLs get really ugly.

Since django pagination uses GET request to pass the page parameters, I do not know how I can combine these two approaches.

Any idea?

Great add-on would be: How can I combine this approach with table sort? :-)

Edit:

Actually it should work like the pagination of stackoverflow - user questions. If a user clicks on a page number one is shown the correct page, without showing the get parameters in the url.

This is the url called. http://stackoverflow.com/api/userquestions.html?page=2&pagesize=10&userId=237690&sort=Recent

But the url shown in the browser is neat and short. Seems to be ajax. Anybody an idea how to implement this? :)

If the URL is not shown in the browser`s address bar, I do not care about whether it is beautiful or not.

Edit: The solution:

Make an ajax update with all filter parameters passed to the view. This should help you get started with implementing ajax for your site: link

Thus the GET parameters never show up in the address bar.

A: 

maybe you can use the urs, something like:

http://oursite.com/something/filter1/filter2/3/

the doc -> http://docs.djangoproject.com/en/1.1/topics/http/urls/

diegueus9
Thanks. I think thats a good idea for 3-5 filters. But I have about 15.
Tom Tom
+2  A: 

have you checked the paginate application for django? it may help you a lot, use it all the time :D

http://code.google.com/p/django-pagination/

PirosB3
Great app, especially since you just have to change some things in your template. But nevertheless the page param is still processed as a GET variable. I suppose that I will lose my filter params that are send with POST using this approach, like I do in using standard django pagination.
Tom Tom
but if you refresh just the block that is paginated with ajax those GET urls will never appear in the address bar :)
Jiaaro
create a custom view that filters, then renders a template which has pagination loaded, you will request this view with AJAX and replace the current "results" div...dont know if you understand what im saying, not very good at explaining :(Post any doubts
PirosB3
Yes that was the solution. Updating only the part with ajax. Following this example should bring anybody up to get rid of ugly GET params in the URL:) http://www.nomadjourney.com/2009/01/using-django-templates-with-jquery-ajax/
Tom Tom
A: 

I figured out two solutions:

  1. Instead of using just hyperlinks use it inside a POST form, i dont have any example now but i remember have used that for REST functions in Ruby on rails
  2. Save the query info in a session.

Hope this help.

Sergio