views:

87

answers:

2

What is the best way of doing a pagination? I would also need to save the current page, so that when I click a link it would save the page I was on. So if I'm on page 2 of the pagination and click one link and then get back to pagination page it would remember that I was on page 2.

I get the results/data from Json request where I have offset and limit possibility.

$.getJSON(base_url+'/ajax/get_news/4/!OFFSET!/!LIMIT!/true', func...

Where !LIMIT! is how many results it shows and !OFFSET! is, well offset :D When I click a link, it makes that request, it goes throught the results and appends the result into page.

What is best way to save the page, cookies? Should I get all the results and then do the pagination somehow or do new request when user change page?

Some tutorial or "hands on" example would be awesome. Normal instructions/guides are difficult to undestand since my first language isn't english.

+1  A: 

It appears you have two questions:

1) How to save page state (what page you are on): If the application must continue to use an ajax, then you should look at storing the state in the url as discribed here:

http://ajaxpatterns.org/Unique_URLs

2) Regarding where to do the pagination, I think it would depend on the size of the data to paginate. If it is small and you are not worried about the data changing on between paging, do it all in javascript. Otherwise, do it server-side.

Samir G
great link! Also led me to this jQuery plugin: http://benalman.com/projects/jquery-bbq-plugin/
Ryley
I dont get much from this and I think this is not what I was after. Could anyone help please?
Thom Eriksson
A: 

Okey I should use the !OFFSET! and !LIMIT! to do the pagination. I just need change those numbers with pagination links (1 2 3 4 pages etc) to get the pagination to work I believe. But I dont know where to start :/

Thom Eriksson