TableVirtuoso
TableVirtuoso
Section titled “TableVirtuoso”TableVirtuoso<
ItemData,Context>(props):ReactElement
A virtualized table component for efficiently rendering large tabular datasets. Renders semantic HTML table markup with support for fixed headers and footers.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
ItemData | any | The type of data items in the table |
Context | any | The type of additional context passed to callbacks |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
props | TableVirtuosoProps<ItemData, Context> & object | TableVirtuosoProps |
Returns
Section titled “Returns”ReactElement
Example
Section titled “Example”tsx- TableVirtuosoProps for available props
- TableVirtuosoHandle for imperative methods
- TableComponents for customizing table elements
TableVirtuosoProps
Section titled “TableVirtuosoProps”The props for the TableVirtuoso component.
- TableVirtuoso for the component
- TableVirtuosoHandle for imperative methods
- TableComponents for customizing table elements
Extends
Section titled “Extends”Omit<VirtuosoProps<Data,Context>,"components"|"headerFooterTag">
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
Data | The type of data items in the table |
Context | The type of additional context passed to callbacks |
Properties
Section titled “Properties”alignToBottom?: boolean
Section titled “alignToBottom?: boolean”Setting alignToBottom to true aligns the items to the bottom of the list if the list is shorter than the viewport.
Use followOutput property to keep the list aligned when new items are appended.
Overrides
Section titled “Overrides”Omit.alignToBottom
atBottomStateChange()?
Section titled “atBottomStateChange()?”
optionalatBottomStateChange: (atBottom) =>void
Called with true / false when the list has reached the bottom / gets scrolled up.
Can be used to load newer items, like tail -f.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
atBottom | boolean |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.atBottomStateChange
atBottomThreshold?: number
Section titled “atBottomThreshold?: number”By default 4. Redefine to change how much away from the bottom the scroller can be before the list is not considered not at bottom.
Overrides
Section titled “Overrides”Omit.atBottomThreshold
atTopStateChange()?
Section titled “atTopStateChange()?”
optionalatTopStateChange: (atTop) =>void
Called with true / false when the list has reached the top / gets scrolled down.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
atTop | boolean |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.atTopStateChange
atTopThreshold?: number
Section titled “atTopThreshold?: number”By default 0. Redefine to change how much away from the top the scroller can be before the list is not considered not at top.
Overrides
Section titled “Overrides”Omit.atTopThreshold
components?: TableComponents<Data, Context>
Section titled “components?: TableComponents<Data, Context>”Use the components property for advanced customization of the elements rendered by the table.
computeItemKey?: ComputeItemKey<Data, Context>
Section titled “computeItemKey?: ComputeItemKey<Data, Context>”If specified, the component will use the function to generate the key property for each list item.
Overrides
Section titled “Overrides”Omit.computeItemKey
context?: Context
Section titled “context?: Context”Additional context available in the custom components and content callbacks
Inherited from
Section titled “Inherited from”Omit.context
customScrollParent?: HTMLElement
Section titled “customScrollParent?: HTMLElement”Pass a reference to a scrollable parent element, so that the table won’t wrap in its own.
Overrides
Section titled “Overrides”Omit.customScrollParent
data?: readonly Data[]
Section titled “data?: readonly Data[]”The data items to be rendered. If data is set, the total count will be inferred from the length of the array.
Overrides
Section titled “Overrides”Omit.data
defaultItemHeight?: number
Section titled “defaultItemHeight?: number”By default, the component assumes the default item height from the first rendered item (rendering it as a “probe”).
If the first item turns out to be an outlier (very short or tall), the rest of the rendering will be slower, as multiple passes of rendering should happen for the list to fill the viewport.
Setting defaultItemHeight causes the component to skip the “probe” rendering and use the property
value as default height instead.
Overrides
Section titled “Overrides”Omit.defaultItemHeight
endReached()?
Section titled “endReached()?”
optionalendReached: (index) =>void
Gets called when the user scrolls to the end of the list. Receives the last item index as an argument. Can be used to implement endless scrolling.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
index | number |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.endReached
firstItemIndex?: number
Section titled “firstItemIndex?: number”Use when implementing inverse infinite scrolling - decrease the value this property
in combination with data or totalCount to prepend items to the top of the list.
Warning: the firstItemIndex should be a positive number, based on the total amount of items to be displayed.
Overrides
Section titled “Overrides”Omit.firstItemIndex
fixedFooterContent?: FixedFooterContent
Section titled “fixedFooterContent?: FixedFooterContent”Set the contents of the table footer.
fixedGroupHeight?: number
Section titled “fixedGroupHeight?: number”Can be used to improve performance if the rendered group header items are of known size. Setting it causes the component to skip measuring group headers. The value is in pixels. This value has no effect if fixedItemHeight is not set.
Inherited from
Section titled “Inherited from”VirtuosoProps.fixedGroupHeight
fixedHeaderContent?: FixedHeaderContent
Section titled “fixedHeaderContent?: FixedHeaderContent”Set the contents of the table header.
fixedItemHeight?: number
Section titled “fixedItemHeight?: number”Can be used to improve performance if the rendered items are of known size. Setting it causes the component to skip item measurements.
Overrides
Section titled “Overrides”Omit.fixedItemHeight
followOutput?: FollowOutput
Section titled “followOutput?: FollowOutput”If set to true, the list automatically scrolls to bottom if the total count is changed.
Set to "smooth" for an animated scrolling.
By default, followOutput scrolls down only if the list is already at the bottom.
To implement an arbitrary logic behind that, pass a function:
tsxOverrides
Section titled “Overrides”Omit.followOutput
heightEstimates?: number[]
Section titled “heightEstimates?: number[]”Use when you have items with widely varying heights and can estimate each item’s height upfront.
Pass an array of estimated heights for each item (by index). This helps the component calculate a more accurate initial total height for the list, reducing layout shifts during initial scrolling.
The estimates don’t need to be exact - they’re used to build the initial size tree before actual measurements are taken. Once items are rendered and measured, their real heights replace the estimates.
Example
Section titled “Example”tsxInherited from
Section titled “Inherited from”horizontalDirection?: boolean
Section titled “horizontalDirection?: boolean”When set, turns the scroller into a horizontal list. The items are positioned with inline-block.
Inherited from
Section titled “Inherited from”Omit.horizontalDirection
increaseViewportBy?: number | { bottom: number; top: number; }
Section titled “increaseViewportBy?: number | { bottom: number; top: number; }”Set the increaseViewportBy property to artificially increase the viewport size, causing items to be rendered before outside of the viewport.
The property causes the component to render more items than the necessary, but can help with slow loading content.
Using { top?: number, bottom?: number } lets you set the increase for each end separately.
Overrides
Section titled “Overrides”Omit.increaseViewportBy
initialItemCount?: number
Section titled “initialItemCount?: number”Use for server-side rendering - if set, the list will render the specified amount of items regardless of the container / item size.
Overrides
Section titled “Overrides”Omit.initialItemCount
initialScrollTop?: number
Section titled “initialScrollTop?: number”Set this value to offset the initial location of the list.
Warning: using this property will still run a render cycle at the scrollTop: 0 list window.
If possible, avoid using it and stick to initialTopMostItemIndex instead.
Overrides
Section titled “Overrides”Omit.initialScrollTop
initialTopMostItemIndex?: number | IndexLocationWithAlign
Section titled “initialTopMostItemIndex?: number | IndexLocationWithAlign”Set to a value between 0 and totalCount - 1 to make the list start scrolled to that item.
Pass in an object to achieve additional effects similar to scrollToIndex.
Overrides
Section titled “Overrides”Omit.initialTopMostItemIndex
isScrolling()?
Section titled “isScrolling()?”
optionalisScrolling: (isScrolling) =>void
Called when the list starts/stops scrolling.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
isScrolling | boolean |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.isScrolling
itemContent?: ItemContent<Data, Context>
Section titled “itemContent?: ItemContent<Data, Context>”Set the callback to specify the contents of the item.
Overrides
Section titled “Overrides”Omit.itemContent
Allows customizing the height/width calculation of Item elements.
The default implementation reads el.getBoundingClientRect().height and el.getBoundingClientRect().width.
Overrides
Section titled “Overrides”Omit.itemSize
itemsRendered()?
Section titled “itemsRendered()?”
optionalitemsRendered: (items) =>void
Called with the new set of items each time the list items are rendered due to scrolling.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
items | ListItem<Data>[] |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.itemsRendered
logLevel?: LogLevel
Section titled “logLevel?: LogLevel”set to LogLevel.DEBUG to enable various diagnostics in the console, the most useful being the item measurement reports.
Ensure that you have “all levels” enabled in the browser console too see the messages.
Inherited from
Section titled “Inherited from”Omit.logLevel
minOverscanItemCount?: number | { bottom: number; top: number; }
Section titled “minOverscanItemCount?: number | { bottom: number; top: number; }”Set the minimum number of items to render before and after the visible viewport boundaries.
This is useful when rendering items with dynamic or very tall content, where the pixel-based
increaseViewportBy may not be sufficient to prevent empty areas during rapid resizing or scrolling.
Using { top?: number, bottom?: number } lets you set the count for each end separately.
Overrides
Section titled “Overrides”Omit.minOverscanItemCount
overscan?: number | { main: number; reverse: number; }
Section titled “overscan?: number | { main: number; reverse: number; }”Set the overscan property to make the component “chunk” the rendering of new items on scroll.
The property causes the component to render more items than the necessary, but reduces the re-renders on scroll.
Setting { main: number, reverse: number } lets you extend the list in both the main and the reverse scrollable directions.
See the increaseViewportBy property for a similar behavior (equivalent to the overscan in react-window).
Overrides
Section titled “Overrides”Omit.overscan
rangeChanged()?
Section titled “rangeChanged()?”
optionalrangeChanged: (range) =>void
Called with the new set of items each time the list items are rendered due to scrolling.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
range | ListRange |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.rangeChanged
restoreStateFrom?: StateSnapshot
Section titled “restoreStateFrom?: StateSnapshot”pass a state obtained from the getState() method to restore the list state - this includes the previously measured item sizes and the scroll location. Notice that you should still pass the same data and totalCount properties as before, so that the list can match the data with the stored measurements. This is useful when you want to keep the list state when the component is unmounted and remounted, for example when navigating to a different page.
Overrides
Section titled “Overrides”Omit.restoreStateFrom
scrollerRef()?
Section titled “scrollerRef()?”
optionalscrollerRef: (ref) =>any
Provides access to the root DOM element
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
ref | HTMLElement | Window | null |
Returns
Section titled “Returns”any
Overrides
Section titled “Overrides”Omit.scrollerRef
scrollIntoViewOnChange()?
Section titled “scrollIntoViewOnChange()?”
optionalscrollIntoViewOnChange: (params) =>false|ScrollIntoViewLocation|null|undefined
Implement this callback if you want to adjust the list position when the list total count changes.
Return a ScrollIntoViewLocation object to scroll to a specific item, or falsey value to avoid scrolling.
Use the context contents if you need to implement custom logic based on the current state of the list.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
params | { context: Context; scrollingInProgress: boolean; totalCount: number; } |
params.context | Context |
params.scrollingInProgress | boolean |
params.totalCount | number |
Returns
Section titled “Returns”false | ScrollIntoViewLocation | null | undefined
Inherited from
Section titled “Inherited from”Omit.scrollIntoViewOnChange
scrollSeekConfiguration?: false | ScrollSeekConfiguration
Section titled “scrollSeekConfiguration?: false | ScrollSeekConfiguration”Use to display placeholders if the user scrolls fast through the list.
Set components.ScrollSeekPlaceholder to change the placeholder content.
Overrides
Section titled “Overrides”Omit.scrollSeekConfiguration
skipAnimationFrameInResizeObserver?: boolean
Section titled “skipAnimationFrameInResizeObserver?: boolean”When set, the resize observer used to measure the items will not use requestAnimationFrame to report the size changes.
Setting this to true will improve performance and reduce flickering, but will cause benign errors to be reported in the console if the size of the items changes while they are being measured.
See https://github.com/petyosi/react-virtuoso/issues/1049 for more information.
Inherited from
Section titled “Inherited from”Omit.skipAnimationFrameInResizeObserver
startReached()?
Section titled “startReached()?”
optionalstartReached: (index) =>void
Called when the user scrolls to the start of the list.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
index | number |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.startReached
topItemCount?: number
Section titled “topItemCount?: number”Set the amount of items to remain fixed at the top of the table.
Overrides
Section titled “Overrides”Omit.topItemCount
totalCount?: number
Section titled “totalCount?: number”The total amount of items to be rendered.
Overrides
Section titled “Overrides”Omit.totalCount
totalListHeightChanged()?
Section titled “totalListHeightChanged()?”
optionaltotalListHeightChanged: (height) =>void
Called when the total list height is changed due to new items or viewport resize.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
height | number |
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”Omit.totalListHeightChanged
useWindowScroll?: boolean
Section titled “useWindowScroll?: boolean”Uses the document scroller rather than wrapping the list in its own.
Overrides
Section titled “Overrides”Omit.useWindowScroll
TableVirtuosoHandle
Section titled “TableVirtuosoHandle”Exposes the TableVirtuoso component methods for imperative control. Access via ref on the TableVirtuoso component.
- TableVirtuoso for the component
- TableVirtuosoProps for available props
Extends
Section titled “Extends”BaseTableVirtuosoHandle
Methods
Section titled “Methods”getState()
Section titled “getState()”getState(
stateCb):void
Obtains the internal size state of the component, so that it can be restored later. This does not include the data items.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
stateCb | StateCallback | Callback that receives the state snapshot |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseTableVirtuosoHandle.getState
scrollBy()
Section titled “scrollBy()”scrollBy(
location):void
Scrolls the component by the specified amount.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
location | ScrollToOptions | The scroll offset options |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseTableVirtuosoHandle.scrollBy
scrollIntoView()
Section titled “scrollIntoView()”scrollIntoView(
location):void
Scrolls the specified item into view if it’s not already visible.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
location | number | FlatScrollIntoViewLocation | The item index or scroll into view location options |
Returns
Section titled “Returns”void
scrollTo()
Section titled “scrollTo()”scrollTo(
location):void
Scrolls the component to the specified position.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
location | ScrollToOptions | The scroll position options |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseTableVirtuosoHandle.scrollTo
scrollToIndex()
Section titled “scrollToIndex()”scrollToIndex(
location):void
Scrolls the component to the specified item index.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
location | number | FlatIndexLocationWithAlign | The item index or location with alignment options |
Returns
Section titled “Returns”void
TableComponents
Section titled “TableComponents”Customize the TableVirtuoso rendering by passing a set of custom components.
Example
Section titled “Example”tsxTableVirtuosoProps.components for usage in TableVirtuoso
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
Data | unknown | The type of data items in the table |
Context | unknown | The type of additional context passed to components |
Properties
Section titled “Properties”EmptyPlaceholder?: ComponentType<ContextProp<Context>>
Section titled “EmptyPlaceholder?: ComponentType<ContextProp<Context>>”Set to render a custom UI when the list is empty.
FillerRow?: ComponentType<FillerRowProps & ContextProp<Context>>
Section titled “FillerRow?: ComponentType<FillerRowProps & ContextProp<Context>>”Set to render an empty item placeholder.
Group?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>
Section titled “Group?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>”Set to customize the group item wrapping element. Use only if you would like to render list from elements different than a tr.
Scroller?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "tabIndex" | "children"> & RefAttributes<HTMLDivElement> & object & ContextProp<Context>>
Section titled “Scroller?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "tabIndex" | "children"> & RefAttributes<HTMLDivElement> & object & ContextProp<Context>>”Set to customize the outermost scrollable element. This should not be necessary in general, as the component passes its HTML attribute props to it.
ScrollSeekPlaceholder?: ComponentType<ScrollSeekPlaceholderProps & ContextProp<Context>>
Section titled “ScrollSeekPlaceholder?: ComponentType<ScrollSeekPlaceholderProps & ContextProp<Context>>”Set to render an item placeholder when the user scrolls fast. See the scrollSeek property for more details.
Table?: ComponentType<TableProps & ContextProp<Context>>
Section titled “Table?: ComponentType<TableProps & ContextProp<Context>>”Set to customize the wrapping table element.
TableBody?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "className" | "style" | "children"> & RefAttributes<HTMLTableSectionElement> & object & ContextProp<Context>>
Section titled “TableBody?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "className" | "style" | "children"> & RefAttributes<HTMLTableSectionElement> & object & ContextProp<Context>>”Set to customize the items wrapper. Default is tbody.
TableFoot?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "style" | "children"> & RefAttributes<HTMLTableSectionElement> & ContextProp<Context>>
Section titled “TableFoot?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "style" | "children"> & RefAttributes<HTMLTableSectionElement> & ContextProp<Context>>”Set to render a fixed footer at the bottom of the table (tfoot). use [[fixedFooterContent]] to set the contents
TableHead?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "style" | "children"> & RefAttributes<HTMLTableSectionElement> & ContextProp<Context>>
Section titled “TableHead?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, "style" | "children"> & RefAttributes<HTMLTableSectionElement> & ContextProp<Context>>”Set to render a fixed header at the top of the table (thead). use [[fixedHeaderContent]] to set the contents
TableRow?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>
Section titled “TableRow?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>”Set to customize the item wrapping element. Default is tr.
FillerRowProps
Section titled “FillerRowProps”Passed to the Components.FillerRow custom component
Properties
Section titled “Properties”height
Section titled “height”number
The height of the filler row in pixels
FixedFooterContent
Section titled “FixedFooterContent”FixedFooterContent = () =>
React.ReactNode|null
Callback type for rendering fixed footer content in a table. The footer remains visible at the bottom of the viewport.
Example
Section titled “Example”tsxTableVirtuosoProps.fixedFooterContent for usage
FixedHeaderContent
Section titled “FixedHeaderContent”FixedHeaderContent = () =>
React.ReactNode|null
Callback type for rendering fixed header content in a table. The header remains visible at the top of the viewport.
Example
Section titled “Example”tsxTableVirtuosoProps.fixedHeaderContent for usage
TableBodyProps
Section titled “TableBodyProps”TableBodyProps =
Pick<React.ComponentProps<"tbody">,"children"|"className"|"style"> &React.RefAttributes<HTMLTableSectionElement> &object
Passed to the TableComponents.TableBody custom component
Type Declaration
Section titled “Type Declaration”data-testid
Section titled “data-testid”string
TableProps
Section titled “TableProps”TableProps =
Pick<React.ComponentProps<"table">,"children"|"style">
TableRootProps
Section titled “TableRootProps”TableRootProps =
Omit<React.HTMLProps<HTMLTableElement>,"data"|"ref">