Help

Paginated record is not working

Topic Labels: Sync
99 2
cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to retrieve data with pagination, but its not returning the value.

export default async function fetchData() {
  let data = []
  base('table-name-here')
    .select({
      pageSize: 3,
      view: 'Grid view',
    })
    .eachPage(
      function page(records, fetchNextPage) {
        data = [...data, ...records]

        // fetchNextPage();
        console.log(data) // this shows result as expected
        return data // this doesn't work
      },
      function done(err) {
        if (err) {
          console.error(err)
          return
        }
      }
    )
}

when I call this function from frontend I can see the values from console.log statement, but it doesn’t return the data array.

2 Replies 2

Hi @Farhan_Farooq,
You have to add the offset to your fetch.

Pagination

The server returns one page of records at a time. Each page will contain pageSize records, which is 100 by default.

If there are more records, the response will contain an offset. To fetch the next page of records, include offset in the next request’s parameters.

Pagination will stop when you’ve reached the end of your table. If the maxRecords parameter is passed, pagination will stop once you’ve reached this maximum.

I am not even calling the fetchNextPage function, console log shows data from first page but even that data is not available to consume in frontend. Can you share the resource regarding offset?
Thank you