Kaltsoon / sequelize-cursor-pagination

➡️ Cursor-based pagination queries for Sequelize models
87 stars 27 forks source link

` after: pagination.cursors.after` in the option always throw error "pagination was use before it was defined" #32

Closed ngels closed 4 years ago

ngels commented 4 years ago

I want to do pagination with link to specific page like. the front end will look like this

                                  **|<<|1|2|3|4|5|>>|**

click on a number will have as effect bring to the specific page. sequelize-cursor-pagination seems to start always from the first page.

This is my source

const whatIget = await Model.paginate({ limit: 2, desc: true });

To go to the next/previous page i do this

const whatIget = await Model.paginate({ limit: 2, desc: true, after: whatIget.cursors.after });

this line after: whatIget .cursors.after in the option generate error whatIget is invalid, which is normal.

question 1: How jump to a straight page number , for example if the current page is 1, by clicking on 3 reach the page 3

question 2: how to avoid the error generate by this whatIget .cursors.after in the option

Kaltsoon commented 4 years ago

In cursor-based pagination, it is impossible to use the traditional page numbering pagination, because if the user is at page 1 it is impossible to figure out what's the cursor at the end of page 2 (which is required to display the page 3). If you want to support this feature, you should use the traditional offset based pagination instead of cursor-based pagination.