-
-
Notifications
You must be signed in to change notification settings - Fork 686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support reverse pagination (previous page, has-previous-items) #916
Comments
Yes, this would be nice! I using Datasette v0.56 and don't see a previous page button. |
I found one example of an implementation of reversed keyset pagination here: https://github.com/tvainika/objection-keyset-pagination/blob/cb21a493c96daa6e63c302efae6718d09aa11661/index.js#L74-L79 |
I think my ideal implementation for this would be to reverse the order, grab the previous page-size-plus-one items, then return a The alternative would be to have a |
Let's figure out the SQL for this. The most complex case is probably this one: https://latest.datasette.io/fixtures/compound_three_primary_keys?_next=a%2Ch%2Cr select pk1, pk2, pk3, content from compound_three_primary_keys where ((pk1 > :p0)
or
(pk1 = :p0 and pk2 > :p1)
or
(pk1 = :p0 and pk2 = :p1 and pk3 > :p2)) order by pk1, pk2, pk3 limit 101 Where Given the above, how would I figure out the correct previous link? It should be https://latest.datasette.io/fixtures/compound_three_primary_keys?_next=a%2Cd%2Cv - |
I tried flipping the direction of the sort and the comparison operators and got this: https://latest.datasette.io/fixtures?sql=select+pk1%2C+pk2%2C+pk3%2C+content+from+compound_three_primary_keys+where+%28%28pk1+%3C+%3Ap0%29%0D%0A++or%0D%0A%28pk1+%3D+%3Ap0+and+pk2+%3C+%3Ap1%29%0D%0A++or%0D%0A%28pk1+%3D+%3Ap0+and+pk2+%3D+%3Ap1+and+pk3+%3C+%3Ap2%29%29+order+by+pk1+desc%2C+pk2+desc%2C+pk3+desc+limit+1+offset+99&p0=a&p1=h&p2=r select pk1, pk2, pk3, content from compound_three_primary_keys where ((pk1 < :p0)
or
(pk1 = :p0 and pk2 < :p1)
or
(pk1 = :p0 and pk2 = :p1 and pk3 < :p2)) order by pk1 desc, pk2 desc, pk3 desc limit 1 offset 99 Which returned |
Same query again with |
Relevant code is some of the most complex in all of Datasette. datasette/datasette/views/table.py Lines 530 to 594 in 0a7621f
And datasette/datasette/views/table.py Lines 743 to 771 in 0a7621f
I'll need to think hard about how to refactor this out into something more understandable before implementing previous links. |
I need this for
datasette-graphql
for full compatibility with the way Relay likes to paginate - using cursors for paginating backwards as well as for paginating forwards.The text was updated successfully, but these errors were encountered: