TanStackT
TanStack3y ago
7 replies
colossal-harlequin

v3 Virtual List in Tanstack Table v8

Having issues where I am getting a large amount of bottom padding when scrolling when there are more items.

Used this as a reference: https://github.com/Rayologist/next-template/blob/8b934ff38d69afa488fc7411c24c56933e01d072/src/components/Table/index.tsx#L173

    const tableContainerRef = useRef<HTMLDivElement>(null)
    const virtualizer = useVirtualizer({
        count: rows.length,
        getScrollElement: () => tableContainerRef.current,
        estimateSize: () => 50,
        // overscan: 100,
    })

    const { getTotalSize, getVirtualItems } = virtualizer
    const virtualRows = getVirtualItems()
    const totalSize = getTotalSize()

    const paddingTop = virtualRows.length > 0 ? virtualRows?.[0]?.start || 0 : 0
    const paddingBottom =
        virtualRows.length > 0
            ? totalSize - (virtualRows?.[virtualRows.length - 1]?.end || 0)
            : 0


    return (
        <ScrollArea ref={tableContainerRef} className='border'>
            <Table>
                <TH />
                <TB />
            </Table>
            <div
                data-testid='!!data-table-pagination'
                className='sticky bottom-0 z-10 py-2 bg-white '
            >
                <DataTablePagination table={table} />
            </div>
        </ScrollArea>
    )
image.png
image.png
GitHub
NextJS template: Typescript, Mantine, Zod, React Hook Form, @tanstack/react-table, and @tanstack/react-virtual - Rayologist/next-template
next-template/src/components/Table/index.tsx at 8b934ff38d69afa488f...
Was this page helpful?