Jun 03, 2024 10:07 AM
I'm using the Airtable Node SDK and the type for `offset` is `number` but it throws an error of "INVALID_OFFSET_VALUE". Passing a `string` also throws an error "Error: Airtable: invalid parameters for `select`".
Also, I don't get the `offset` string from the response when using the SDK.
Is it possible to do pagination with the SDK? I see there's a function for `.select().eachPage()` but I'm not sure how to use it to implement pagination.
If requesting via Fetch, I get the `offset` string from the response and I'm able to send it to the next request and get the next page, but how do I navigate backwards? I would need to store in a hash map ( { 0: null, 1: 'first_page/offset_string', ... } ) ?
Another question is: Is it possible to implement a "normal" pagination? Like, navigate to an specific page, navigate backwards, etc.?
Jun 11, 2024 02:10 AM - edited Jun 11, 2024 10:38 PM
@BeUni_Tecnologimary kay in touch wrote:I'm using the Airtable Node SDK and the type for `offset` is `number` but it throws an error of "INVALID_OFFSET_VALUE". Passing a `string` also throws an error "Error: Airtable: invalid parameters for `select`".
Also, I don't get the `offset` string from the response when using the SDK.
Is it possible to do pagination with the SDK? I see there's a function for `.select().eachPage()` but I'm not sure how to use it to implement pagination.
If requesting via Fetch, I get the `offset` string from the response and I'm able to send it to the next request and get the next page, but how do I navigate backwards? I would need to store in a hash map ( { 0: null, 1: 'first_page/offset_string', ... } ) ?
Another question is: Is it possible to implement a "normal" pagination? Like, navigate to an specific page, navigate backwards, etc.?
Hello,
You're right, the Airtable Node SDK currently (as of June 2024) doesn't have built-in support for pagination using an offset value. Here's a breakdown of your questions and approaches:
1. INVALID_OFFSET_VALUE Error:
The offset parameter in .select() expects a number, not a string. Supplying a string will cause the "invalid parameters" error.
2. Pagination with .eachPage():
You're on the right track with .eachPage(). This function is designed for iterating through paginated Airtable responses.
Here's how to use it for pagination:
const base = airtable.base('yourBaseId');
const table = base('yourTableName');
const pageSize = 100; // Adjust as needed
table.select({
pageSize
})
.eachPage(
(records, fetchNextPage) => {
// Process the current page of records (array)
console.log(records);
// Check if there's a next page
if (fetchNextPage) {
fetchNextPage(); // Fetch the next page
}
},
(err) => {
if (err) {
console.error(err);
}
}
);
This code fetches pages of pageSize records and calls fetchNextPage when available.
Navigating Backwards:
Unfortunately, the SDK doesn't provide a direct way to navigate backwards. The .eachPage() approach iterates forward only.
If you need true backward navigation, consider storing the returned record IDs or another unique identifier in your application state and using them for specific record retrieval.
4. "Normal" Pagination:
The SDK doesn't currently offer functionality to navigate to a specific page number.
You can achieve a similar effect by adjusting the pageSize in .eachPage() to simulate page sizes. Keep track of the processed records and manually calculate the "page number" based on the retrieved records and pageSize.
I hope the information may help you.
Jul 03, 2024 02:34 AM
Jul 03, 2024 02:35 AM
Sep 16, 2024 06:32 AM
With its pagination methods, such as.eachPage(), the Airtable Node SDK abstracts offset management.
The API of Airtable does not explicitly support traditional pagination features, such as navigating to a specific page or reversing. Consequently, you will be required to manually manage this by storing fetched pages or offset values.
To implement pagination with the Airtable Node SDK, it is necessary to iterate through pages using.eachPage() and manage navigation requirements (such as reversing navigation) locally. MyKohlsCard Login