How to paginate large data set

I would like to go to specific page for example page:3 of some data set i set in the doc that you can do this to go to the next page

import { REDACTEDObjecType } from "@carlos-test-app/sdk";
import { isOk, Osdk, PageResult, Result } from "@osdk/client";

const firstPage: Result<PageResult<Osdk.Instance<REDACTEDObjecType>>>
    = await client(REDACTEDObjecType).fetchPageWithErrors({ $pageSize: 30 });

if (isOk(firstPage)) {
    const secondPage: Result<PageResult<Osdk.Instance<REDACTEDObjecType, never, "name">>>
    // You can also down select properties to only get the properties you need from the object
    = await client(REDACTEDObjecType).fetchPageWithErrors({ $select: ["name"], $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });

    const objects = isOk(secondPage) ? [...firstPage.value.data, ...secondPage.value.data] : firstPage.value.data;
    const object = objects[0];
}

 // If you want to get rids, you need to add a flag to specifically request for it. Note how the return type now includes $rid rather than never
const secondPageWithRids: Result<PageResult<Osdk.Instance<REDACTEDObjecType, "$rid", "name">>>
    = await client(REDACTEDObjecType).fetchPageWithErrors({ $select: ["name"], $includeRid:true, $pageSize: 30, $nextPageToken: firstPage.value.nextPageToken });

// To fetch a page without a result wrapper, use fetchPage with a try/catch instead
try {
    const firstPage: PageResult<Osdk.Instance<REDACTEDObjecType>>
        = await client(REDACTEDObjecType).fetchPage({ $pageSize: 30 });
    const secondPage: PageResult<Osdk.Instance<REDACTEDObjecType>>
     = await client(REDACTEDObjecType).fetchPage({ $pageSize: 30, $nextPageToken: firstPage.nextPageToken });
    const objects = [...firstPage.data, ...secondPage.data];
    const object = objects[0];
}
catch (e) {
    console.error(e);
}

I would like to know if you can go directly to something like page 4.

Hi! With the OSDK APIs you would need to page through with nextPageTokens to get to a desired page, however, if you have your results sorted in some way you could perhaps refine your search query to include results that would be on that third page. For example, if sorted by date, you could try and refine the date window to some point further in the past.

Is this something that will be changed its a little odd and a very common thing to do. With either a page value or an offset value to get to the date that the user might what/need. Is there a way to add this with a custom function or something else that can be done other then just filtering the data?

Basically the API do not let you jump to a specific page, but you mentions jumping to a date that the user needs - if your app run some aggregate query bucket by date, it can show the user the optional dates your data has and then when the date is selected you can use where on the date column with either $eq or $let .
HTH,

I understand that there a filters to drill down on the data but I have a large data set with over 10k of rows to display in a table with many different columns and date is just one filter set that I have. We were looking to use table pagination something like this 1, 2, 3, ... 10, 11, 12, so on.

Is there anything that we can do that would let us do that?

1 Like