couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Victor Nicollet <>
Subject Re: pagination questions
Date Wed, 07 Sep 2011 15:12:33 GMT
Hello there,

There is actually a trick : using "descending" you can grab the elements
before the specified document, instead of those after it. So, the parameter
you pass around for paging should be a composed of (key,docid,descending),
and the rules are:

 - If ascending, grab PAGESIZE+1 elements at offset 0, display PAGESIZE of
them, use the (key,docid) of the eleventh with descending=false as the
"next" url and the current (key,docid) with descending=true as the
"previous" url
 - If descending, grab PAGESIZE elements at offset 1, display them all in
reverse order, use the (key,docid) of the tenth with descending=true as the
"previous" url and the current (key,docid) with descending=false as the
"next" url

This should allow you to navigate in any direction you wish without having
to store anything. Ideally, you would abstract all of this away once and use
it every time you need paging...

On 7 September 2011 16:34, bryan rasmussen <>wrote:

> Hi,
> I've been looking at
> and is working
> pretty straightforward for going forward, in discussing how one goes
> to the previous page it says:
> "Populating the link to the previous page is as simple as carrying the
> current startkey over to the next page. If there’s no previous
> startkey, we are on the first page."
> I don't see how that works if I go forward ten times and back six for
> example, unless I save the startkey for each step?
> To be more specific, by the way outlined if I am on page 8 and go to
> page 9 by clicking my NEXT button I know what  my page 8 startkey is
> and I know what my page 9 startkey is, If I am on page 9 and I go to
> page 10 by clicking the next I know what my page 9 startkey is and my
> page 10 startkey. Now I click previous on page 10, I go to page 9
> because I know what page 9s startkey is - but when I click previous on
> page 9 I don't know what page 8s startkey is so I go to the first page
> - is there a way around that other than saving all my startkeys? It is
> not that big a problem for me saving all my startkeys, given that my
> application is ajax based I can just save it as an array.
> Thanks,
> Bryan Rasmussen

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message