How to jump to specific page using Query Cursor?

6 views
Skip to first unread message

Sahibzada via StackOverflow

unread,
May 11, 2017, 3:18:05 AM5/11/17
to gcd-stac...@googlegroups.com

I am developing my website in python(webapp2) and google data store in back end. I have added query cursor for pagination and it's working good but it has only next and previous functions for pagination, the question is that how i will jump to specific page like i am on page 1 and i want to jump to page 3, how i will manage it in Query Cursor?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/43908888/how-to-jump-to-specific-page-using-query-cursor

Paolo Casciello via StackOverflow

unread,
May 11, 2017, 12:48:06 PM5/11/17
to gcd-stac...@googlegroups.com

You can't. Datastore doesn't know the number of results found by your query.

You can however use some tricks to simulate a full pagination. For example one technique is to generate a certain number of cursors in a loop and generating the "last page" one.

Like in the following pseudo-code:

(results, next_curs, more) = model.query....fetch_page(...)

for p in xrange(5):
    # generate cursor for page number 'b' 
    # by using the next_cursor from previous page
    (results, next_curs, more) = model.....fetch_page(cursor=next_cursor,...)

As you don't access the results cursor the performance is somewhat acceptable (depending on your models complexity, query complexity and such). You can tweak it on your data.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/43908888/how-to-jump-to-specific-page-using-query-cursor/43921184#43921184
Reply all
Reply to author
Forward
0 new messages