DB with Tanstack Table

What would be the correct way to connect DB and Tanstack Table for pagination? I have have the collection on 'on-demand' mode.

const [pagination, setPagination] = useState<PaginationState>({
        pageIndex: 0,
        pageSize: PAGE_SIZE,
    });

    const { data, pages, hasNextPage } = useLiveInfiniteQuery(
        (q) =>
            q
                .from({ position: PositionsCollection })
                .orderBy(({ position }) => position.id, "desc"),
        {
            pageSize: pagination.pageSize,
            getNextPageParam: (lastPage) =>
                lastPage.length === pagination.pageSize ? lastPage.length : undefined,
        },
    );

const table = useReactTable({
        data,
        columns,
        getRowId: (row) => row.id.toString(),
        getCoreRowModel: getCoreRowModel(),
        manualPagination: true,
        onPaginationChange: setPagination,
        state: { pagination },
        autoResetPageIndex: false,
        pageCount: -1,
    });


I know I am missing something, but after trying many things I cannot figure it out. Maybe someone has a working example?
Was this page helpful?