>
)
}
// Important: Keep the virtualizer and the scroll container ref in the same component.
// The ref must be undefined when createVirtualizer runs (before JSX return),
// so that onMount can set up scroll observers after the element is in the DOM.
function VirtualizedTable(props: {
table: SolidTable
}) {
let tableContainerRef: HTMLDivElement | undefined
const rows = () => props.table.getRowModel().rows
// Important: Keep the row virtualizer in the lowest component possible to avoid unnecessary re-renders.
const rowVirtualizer = createVirtualizer(
{
get count() {
return rows().length
},
estimateSize: () => 33, // estimate row height for accurate scrollbar dragging
getScrollElement: () => tableContainerRef ?? null,
// measure dynamic row height, except in firefox because it measures table border height incorrectly
measureElement:
typeof window !== 'undefined' &&
navigator.userAgent.indexOf('Firefox') === -1
? (element) => element.getBoundingClientRect().height
: undefined,
overscan: 5,
},
)
return (
{/* Even though we're still using semantic table tags, we must use CSS grid and flexbox for dynamic row heights */}
{(headerGroup) => (
{(header) => (
{(
{
asc: ' 🔼',
desc: ' 🔽',
} as Record
)[header.column.getIsSorted() as string] ?? null}
props.rowVirtualizer.measureElement(node)} // measure dynamic row height
style={{
display: 'flex',
position: 'absolute',
transform: `translateY(${props.virtualRow.start}px)`, // this should always be a `style` as it changes on scroll
width: '100%',
}}
>
{(cell) => (