Help writing JS code for pagination

:thinking: based on these docs it looks like you might need to add a page parameter to your headers.

Setting up server-side pagination on a table just means that you'll get the data from your server at the moment you switch to a new page on your table instead of getting all of the data beforehand. Depending on how many rows you have this can help quite a bit with performance, but whether or not it's the right solution also depends on what you want to do with the data in your app.

Getting all of the results together actually requires a bit more code than setting up server-side pagination for a table but it is doable! You'll want to create a separate JavaScript query - from there you can run a loop that queries each page of your data.

const maxPages = 100; //set this to whatever you what the upper limit of pages to be
const results = [];

for(let i = 1; i <= maxPages; i++){
   //fetch the current page of data
   const pageData = await query1.trigger({additionalScope: {page: i}});

   //at the page's order data to your results
   results.push(...pageData.orderData);

   //check to see if the status is not 206 and if so, exit the loop
   if(pageData.status !== 206) break;
}

return results;

In query1 itself, you'll want to pass {{ page }} to the page header. It will show a warning since it won't be defined until the moment you trigger the query using additionalScope as shown above. You can read a more general description of additionalScope here!

The collected results should then be available in the JavaScript query's data property.

Let me know if that works and/or raises any additional questions :slightly_smiling_face: