Skip to main content

Table

warning

measureRowsCount prop will soon be deprecated. Please use new width props instead.

Table is an arrangement of data in rows and columns.

Use Data Tables to display large information in an organized way through rows and columns, so that users can scan, compare and sort data. Also, table automatically truncates long text in header, column and footer cells.

Example

Live Editor
Result
Loading...

Usage

Table component should be placed in a container with a fixed height. The Table component will fill all the available space of the container.

// MyComponent.js

function YourComponent() {
return (
<div style={{ height: 300 }}>
<Table />
</div>
);
}

Adjusting Header Cell Size

The table supports automatic column width measurement according to the longest cell width within the specified number of rows. Use measureRowsCount to specify the number of rows in the table to be measured. The table will include the Header and Footer rows in the measurements as well.

info

If you specify width or max-width value for the column, Cells will take the specified width instead of measured width.

Live Editor
Result
Loading...

Auto rows height

When autoRowsHeight prop is used, rows in the table will grow in respect to their content on first render.

info

To remeasure or recalculate the rows at runtime when a cell height grows, use the measureRows function passed to Cell render prop.

In the example below, typing in any of the ComboBox will grow the table row, measureRows function has been used to remeasure the rows height.

Live Editor
Result
Loading...

Column Resizing

The Table supports the column resizing function. You can use isResizable prop for making desired columns resizable. If you want to limit resizable column width value, you can use for the column maxWidth property.

Live Editor
Result
Loading...

Column Initial Widths

initialMinWidth is a special property (unlike minWidth) which allows you to set an initial min-width for a column & resize it below the specified value

note

Using width or minWidth together with this property will override its default behavior

Live Editor
Result
Loading...

Column Resize Callback

You can use the onColumnResized callback property to get the new width of the column that was resized. The callback will be passed a column argument which is of type TableColumn

Live Editor
Result
Loading...

Custom backgroundColor for the Cells

The prop getCellProps allows you to apply style conditionally as below.

Live Editor
Result
Loading...

Custom Cell Renderer

There are Header, Footer, Cell property within the column configuration. With them you can define the custom render function for the header, the footer and a table cell accordingly.

Live Editor
Result
Loading...

Custom Cell Renderer on Row Hover

If you want to update your custom Cell component when the row it belongs to changes, you can use the getHoveredRowId method to get the id of the row currently being hovered.

Live Editor
Result
Loading...

Custom Minimum Width for Columns

The table supports a custom minimum width option for desired columns. You can use the minWidth property for each column to change the minimum width value. If you do not use the minWidth property for the column, column will take the minWidth 150px width value by default.

Live Editor
Result
Loading...

Custom Maximum Width for Columns

The table supports a custom maximum width option for desired columns. You can use the maxWidth property for each column to change the maximum width value. If you do not use the maxWidth property for the column, column will take the maxWidth 500px width value by default.

Live Editor
Result
Loading...

DND Column Re-ordering

The Table supports the drag-and-drop column re-ordering function. You can use isDraggable prop for making desired columns draggable for re-ordering.

Live Editor
Result
Loading...

DND Column Re-ordering Callback

You can use onColumnRearrange callback property to get an ordered array of column accessors as a first argument and perform any action after column is rearranged.

Live Editor
Result
Loading...

Empty State

You can add an Empty State by using prop emptyState. It is shown if there is no data.

Live Editor
Result
Loading...

Expandable row

You can use this feature to have expandable rows. To do this you need to add subRows in data like the example.

Live Editor
Result
Loading...

You can use the toggleRowExpanded or toggleAllRowsExpanded function passed to the Cell render prop to toggle one or all expandable table rows respectively.

In the example below, we call toggleRowExpanded(rowId, false) after deleting a row in the table to fix an issue that occurs when an expanded row is deleted and the next row is automatically expanded.

Live Editor
Result
Loading...

First and Last Column padding

You can align first and last columns using the firstColumnLeftPadding & lastColumnRightPadding props under visualProperties.

Live Editor
Result
Loading...

Global Filter

You can use this feature to globally search through all columns in the table. You can use this disableGlobalFilter feature to disable filtering for a specific column

Live Editor
Result
Loading...

Fixed Columns

You can specify sticky field within the column configuration to make the column "stick" either to the left or to the right side of the table.

info

Columns with sticky: 'right' should be placed in the end of the columns array.

Live Editor
Result
Loading...

Flex Table

You can use the flexGrow prop to determine how much space the desired table columns occupy compared to other columns. If you use flexGrow: 1 for one column, the other columns will take flexGrow: 0 by default. You are also able to use it for multiple columns to specify flex-grow order for columns. For different use cases you can look at the examples below. To enable the flex layout feature for the table you need to give flex prop to the Table.

info

If you are using Header Groups and its columns need flexGrow, then Header Group needs flexGrow as well.

info

React-Table does not support flex-layout and column resizing features at the same time. Therefore you are not able to use these features together. We are following the updates on this issue. We will announce it when it will be possible.

info

measureRowsCount prop can't be used with the flex-table.

Live Editor
Result
Loading...

Header Alignment

By default, header cell and column cells are aligned according to align property but there're use-cases when header cell needs a different alignment (e.g. RTL text direction). To align header-cell, alignHeader property can be specified for any column within columns array.

The alignHeader property supports the following options (please refer to the table below which shows all of supported options):

  1. left - default
  2. left-reversed
  3. right
  4. right-reversed
  5. center
  6. center-reversed
  7. space-between
  8. space-between-reversed
Live Editor
Result
Loading...

Header Groups

The example below shows a table with grouped headers.

Live Editor
Result
Loading...

You can also hide the header group title by using prop hideHeaderGroupTitle.

Live Editor
Result
Loading...

Header Menu

The prop headerMenuProps allows you to render a menu that opens on click on the table header title.

Live Editor
Result
Loading...

Hide Header

The prop isWithoutHeader is used for hiding table headers.

Live Editor
Result
Loading...

Hover Highlighting

isHoverable can be used to toggle hover highlighting on table rows. By default, it is set to false.

Live Editor
Result
Loading...

Inline editing in Table

You can have inline editing in Table by using updateData prop and defining custom cell which includes needed editable component such as Input, ComboBox, Checkbox, etc.

Live Editor
Result
Loading...

Here is another example with more editable cells with ComboBox, Checkbox, SegmentedButton and nested Objects:

Live Editor
Result
Loading...

Loading More Data (aka Infinite loading)

Table supports infinite loading by calling onLoadMoreData callback when Table gets scrolled to the end. To integrate infinite loading with React Query please refer to useInfiniteQuery hook and this example.

Live Editor
Result
Loading...

Loading State

You can active a loading state for the table by passing isLoading to be true. This helps users to see a skeleton cell when data is loading.

Also the loader height adapts to the typeScales of cellTypeScale and width is random, and also adapts the column alignments.

Live Editor
Result
Loading...

Page level Scrolling

Use pageLevelScroll prop to let the table manage the window scroll to scroll through the items.

info

align on Table columns prop can't be used with flex and pageLevelScroll at the same time unless the table header takes the full width

Live Editor
Result
Loading...

PopOver on Header Cell

The prop popOverProps renders an button that opens a popOver on the table header. When the methods onClear, onApply and onCancel are passed, the popOver renders a footer with button actions that onClick also close the popOver. You can also pass some of the IconButton props in order to customize it.

Live Editor
Result
Loading...

Row onClick Handler

You can pass a method to the table that would return the Row object on click of a row.

warning
Be mindful of onClick events on the cell content when using this feature.
Check the code for an example of a cell with a button that includes a `e.stopPropagation` call to avoid triggering the row method when the button is clicked.
Live Editor
Result
Loading...

RowSize

The table component is available in two sizes: small and medium.

Live Editor
Result
Loading...

Sorting

The table always shows data in the provided order and the actual sorting functionality should be implemented on your side. You can specify the activeSorting to visually highlight the sorting for a column and onSortingChange to handle clicks within the header cell. onSortingChange will return the columnKey and sorting direction will be determined by the activeSorting you provide. You can disable sorting for a specific column by specifying sortable in the columns array.

You can also provide multiple values with activeSorting prop to visually highlight the active sorting of multiple columns. Please check initialSortingMultiple in the below example.

Live Editor
Result
Loading...

Type Scales

Typescale is the combination of font-size, line-height, and letter-spacing. By default, the type scale of all cells is defined by the size variant of the table. Adding typeScales enforces a distinct type scale for the specific table cell(header, body or footer).

Live Editor
Result
Loading...

UnstickThreshold

This component supports the automatic limitation of fixed columns based on its width. You may need to use a more scrollable area for non-fixed columns when having both fixed and non-fixed columns together in the Table.

Use unstickThreshold to specify the percentage of the limitation for fixed columns. For instance, if unstickThreshold is 30, the Table will change fixed columns to non-fixed when the total width of fixed columns is greater than 30% of the table width.

Live Editor
Result
Loading...

Updating Table with Different Instances

The example below shows a table that re renders with updated columns and data

Live Editor
Result
Loading...

VisualProperties

VisualProperties are used to show visual representation of records. For instance, showing bordered columns or greyBackgroundHeader.

Live Editor
Result
Loading...

Zebra Stripe

You can activate zebra-striping of rows by adding isStriped to the visualProperties. This helps users orient themselves in long and complex tables.

Live Editor
Result
Loading...

Props

NameTypeDefault
data *
The data array that you want to display on the Table. It should be memoized.
Record<string, unknown>[]
columns *
The core columns configuration object for the entire Table. It should be memoized.
TableColumn[]
updateData
The callback to use for updating table data. the use case is inline editing mode of Table which requires updateData callback
Record<string, unknown>[]
measureRowsCount
If measureRowsCount is provided, columns will be automatically adjusting their width based on the longest cell within the range of the provided number. The Table will include the `Header` and `Footer` rows in the measurements as well.
number
activeSorting
The sorting applied to the Table.
ColumnSorting | ColumnSorting[]
onSortingChange
The handler will be called when a user clicks on a header cell
((columnName: string) => void)
rowSize
The size of rows
"small" | "medium"
"small"
visualProperties
Provide visual properties to Table
VisualPropertiesType
pageLevelScroll
If set to true the content of the table will be scrolled by the whole page scrollbar
boolean
false
topOffset
The offset at the top of the page that needs to be considered when page level scrolling is enabled
number
0
unstickThreshold
The maximum percentage value that fixed columns can occupy over the table width. If the total fixed columns width exceeds this value, they will automatically turn into unfixed columns
number
isHoverable
If set to true, the table body rows can show hover state
boolean
false
isHeaderless
If set to true table headers will be hidden
boolean
hideHeaderGroupTitle
If set to true table group header title will be hidden
boolean
false
getHoveredRowId
pass this method to access the id of the row being hovered
((id: string) => void)
onColumnRearrange
Callback prop onColumnRearrange when dropping column on rearrange
((columnsOrder: string[]) => void)
onColumnResized
Callback prop onColumnResized when column is resized
((column: TableColumn) => void)
flex
If set to true table will use flex layout
true
rowOnClickHandler
Handler that returns row data on click
((rowData: RowData) => void)
isLoading
Show loading state of the table
boolean
false
typeScales
Provide type scales for the table head, body and footer
TypeScaleType
searchTerm
Search term to be used to do global filtering of data
string
getFilteredData
callback to get filtered data after global filter is applied
((filteredData?: RowData[]) => void)
getCellProps
callback to get cell props
((cell?: any) => any)
"() => ({})"
loadingMoreDataLabel
Custom label to be shown while loading more data
string
emptyState
The props of Empty State component, it will be shown if there is no data
Omit<EmptyStateProps, "size" | "background" | "iconKey">
isLoadingMoreData
More data is being loaded
boolean
hasMoreData
There's still some data to be loaded
boolean
onLoadMoreData
It's called when user scrolls to the end of table in order to load more data
(() => unknown)
autoRowsHeight
If set to true, table body rows height will grow respectively to content height
boolean
data-{foo}
Data attributes can be used by testing libraries to retrieve components or assert their existence
string
* - the prop is required.