Reputation: 153
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?
i have also visited below links but didn't find any solution https://www.the-swamp.info/blog/pagination-google-app-engine/
https://cloud.google.com/appengine/docs/standard/python/datastore/query-cursors
Upvotes: 2
Views: 1614
Reputation: 8202
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.
Upvotes: 3