File: treetable.md | Updated: 11/15/2025
Introducing PrimeReact v11 Alpha 🥁Learn More
SearchK
10.9.7
FEATURES
API
THEMING
PASS THROUGH
TreeTable is used to display hierarchical data in tabular format.
Import#
import { TreeTable } from 'primereact/treetable';
import { Column } from 'primereact/column';
Copy
Basic#
TreeTable requires a collection of TreeNode instances as a value and Column components as children for the representation. The column with the element to toggle a node should have expander enabled.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Dynamic Columns#
Columns can be created programmatically.
| Name | Type | Size | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }}>
{columns.map((col, i) => (
<Column key={col.field} field={col.field} header={col.header} expander={col.expander} />
))}
</TreeTable>
Copy
Controlled#
Expansion state is controlled with expandedKeys and onToggle properties. The expandedKeys should be an object whose keys refer to the node key and values represent the expanded state e.g. {'0-0': true}.
Toggle Applications
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<Button onClick={toggleApplications} label="Toggle Applications" />
<TreeTable value={nodes} expandedKeys={expandedKeys} onToggle={(e) => setExpandedKeys(e.value)} className="mt-4" tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Template#
Custom content at header, body and footer sections are supported via templating. The toggler can be customized with the togglerTemplate property.
File Viewer
| Name | Size | Type | | | --- | --- | --- | --- | | Applications | 100kb | Folder | | | Cloud | 20kb | Folder | | | Desktop | 150kb | Folder | | | Documents | 75kb | Folder | | | Downloads | 25kb | Folder | | | Main | 50kb | Folder | | | Other | 5kb | Folder | | | Pictures | 150kb | Folder | | | Videos | 1500kb | Folder | |
Reload
<TreeTable value={nodes} header={header} footer={footer} togglerTemplate={togglerTemplate} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
<Column body={actionTemplate} headerClassName="w-10rem" />
</TreeTable>
Copy
Paginator#
Pagination is enabled by adding paginator property and defining rows per page.
| Name | Size | Type | | --- | --- | --- | | Item 0 | 484kb | Type 0 | | Item 1 | 598kb | Type 1 | | Item 2 | 705kb | Type 2 | | Item 3 | 94kb | Type 3 | | Item 4 | 438kb | Type 4 |
12345
5
5
<TreeTable value={nodes} paginator rows={5} rowsPerPageOptions={[5, 10, 25]} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Paginator UI is customized using the paginatorTemplate property. Each element can also be customized further with your own UI to replace the default one, refer to the Paginator component for more information about the advanced customization options.
| Name | Size | Type | | --- | --- | --- | | Item 0 | 128kb | Type 0 | | Item 1 | 845kb | Type 1 | | Item 2 | 428kb | Type 2 | | Item 3 | 452kb | Type 3 | | Item 4 | 158kb | Type 4 |
5
5
1 to 5 of 50
<TreeTable value={nodes} paginator rows={5} rowsPerPageOptions={[5, 10, 25, 50]}
paginatorTemplate="RowsPerPageDropdown FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink"
currentPageReportTemplate="{first} to {last} of {totalRecords}"
paginatorLeft={paginatorLeft} paginatorRight={paginatorRight} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Sort#
Sorting on a column is enabled by adding the sortable property.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander sortable></Column>
<Column field="size" header="Size" sortable></Column>
<Column field="type" header="Type" sortable></Column>
</TreeTable>
Copy
Multiple columns can be sorted by defining sortMode as multiple. This mode requires metaKey (e.g. ⌘) to be pressed when clicking a header.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} sortMode="multiple" tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander sortable></Column>
<Column field="size" header="Size" sortable></Column>
<Column field="type" header="Type" sortable></Column>
</TreeTable>
Copy
Filter#
Filtering is enabled by adding the filter property to a Column. The filterMode specifies the filtering strategy, in lenient mode when the query matches a node, children of the node are not searched further as all descendants of the node are included. On the other hand, in strict mode when the query matches a node, filtering continues on all descendants. A general filled called globalFilter is also provided to search all columns that support filtering.
Lenient
Strict
| Name | Size | Type | | --- | --- | --- | | | | | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<SelectButton value={filterMode} onChange={(e) => setFilterMode(e.value)} options={filterOptions} />
<TreeTable value={nodes} globalFilter={globalFilter} header={header} filterMode={filterMode} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander filter filterPlaceholder="Filter by name"></Column>
<Column field="size" header="Size" filter filterPlaceholder="Filter by size"></Column>
<Column field="type" header="Type" filter filterPlaceholder="Filter by type"></Column>
</TreeTable>
Copy
Selection#
Single node selection is configured by setting selectionMode as single along with selectionKeys and onSelectionChange properties to manage the selection value binding.
By default, metaKey press (e.g. ⌘) is necessary to unselect a node however this can be configured with disabling the metaKeySelection property. In touch enabled devices this option has no effect and behavior is same as setting it to false.
MetaKey
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<InputSwitch checked={metaKey} onChange={(e) => setMetaKey(e.value)} />
<TreeTable value={nodes} selectionMode="single" selectionKeys={selectedNodeKey}
onSelectionChange={(e) => setSelectedNodeKey(e.value)} metaKeySelection={metaKey} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
More than one node is selectable by setting selectionMode to multiple. By default in multiple selection mode, metaKey press (e.g. ⌘) is necessary to add to existing selections however this can be configured with disabling the metaKeySelection property. Note that in touch enabled devices, TreeTable always ignores metaKey.
In multiple selection mode, value binding should be a key-value pair where key is the node key and value is a boolean to indicate selection.
{
'0-0': true,
'0-1-0': true
}
Copy
MetaKey
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<InputSwitch checked={metaKey} onChange={(e) => setMetaKey(e.value)} />
<TreeTable value={nodes} selectionMode="multiple" selectionKeys={selectedNodeKeys}
onSelectionChange={(e) => setSelectedNodeKeys(e.value)} metaKeySelection={metaKey} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Selection of multiple nodes via checkboxes is enabled by configuring selectionMode as checkbox.
In checkbox selection mode, value binding should be a key-value pair where key is the node key and value is an object that has checked and partialChecked properties to represent the checked state of a node.
{
'0-0': {
partialChecked: false,
checked: true
}
}
Copy
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} selectionMode="checkbox" selectionKeys={selectedNodeKeys}
onSelectionChange={(e) => setSelectedNodeKeys(e.value)} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
TreeTable provides onSelect and onUnselect events to listen selection events.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} selectionMode="single" selectionKeys={selectedNodeKey}
onSelectionChange={(e) => setSelectedNodeKey(e.value)} metaKeySelection={false}
onSelect={onSelect} onUnselect={onUnselect} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Column Group#
Columns can be grouped within a Row component and groups can be displayed at header and footer using headerColumnGroup, footerColumnGroup properties. Number of cells and rows to span are defined with the colSpan and rowSpan properties of a Column.
| Brand | Sale Rate | | | | | --- | --- | --- | --- | --- | | Sales | | Profits | | | --- | --- | --- | --- | --- | | Last Year | This Year | Last Year | This Year | | --- | --- | --- | --- | --- | | Totals: | | | $506,202 | $531,020 | | Bliss | 51% | 40% | $54,406.00 | $43,342 | | Fate | 83% | 96% | $423,132 | $312,122 | | Ruby | 38% | 5% | $12,321 | $8,500 | | Sky | 49% | 22% | $745,232 | $650,323 | | Comfort | 17% | 79% | $643,242 | 500,332 | | Merit | 52% | 65% | $421,132 | $150,005 | | Violet | 82% | 12% | $131,211 | $100,214 | | Dulce | 44% | 45% | $66,442 | $53,322 | | Solace | 90% | 56% | $765,442 | $296,232 | | Essence | 75% | 54% | $21,212 | $12,533 |
<TreeTable value={nodes} headerColumnGroup={headerGroup} footerColumnGroup={footerGroup} tableStyle={{ minWidth: '50rem' }}>
<Column field="brand" expander />
<Column field="lastYearSale" />
<Column field="thisYearSale" />
<Column field="lastYearProfit" />
<Column field="thisYearProfit" />
</TreeTable>
Copy
Lazy Load#
Lazy mode is handy to deal with large datasets, instead of loading the entire data, small chunks of data is loaded by invoking corresponding callbacks everytime paging, sorting and filtering occurs. Sample below imitates lazy loading data from a remote datasource using an in-memory list and timeouts to mimic network connection.
Enabling the lazy property and assigning the logical number of rows to totalRecords by doing a projection query are the key elements of the implementation so that paginator displays the UI assuming there are actually records of totalRecords size although in reality they are not present on page, only the records that are displayed on the current page exist.
In addition, only the root elements should be loaded, children can be loaded on demand using onExpand callback.
| Name | Size | Type | | --- | --- | --- |
<TreeTable value={nodes} lazy paginator totalRecords={totalRecords}
first={first} rows={rows} onPage={onPage} onExpand={onExpand} loading={loading} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Edit#
Incell editing is enabled by defining input elements with editor property of a Column.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander style={{ height: '3.5rem' }}></Column>
<Column field="size" header="Size" editor={sizeEditor} cellEditValidator={requiredValidator} style={{ height: '3.5rem' }}></Column>
<Column field="type" header="Type" editor={typeEditor} style={{ height: '3.5rem' }}></Column>
</TreeTable>
Copy
Scroll#
Adding scrollable property along with a scrollHeight for the data viewport enables vertical scrolling with fixed headers.
| Name | Size | Type | | --- | --- | --- |
| | | | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} scrollable scrollHeight="200px">
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Horizontal scrolling is enabled when the total width of columns exceeds table width.
| Name | Size | Type 2 | Size 2 | Type 3 | Size 3 | | --- | --- | --- | --- | --- | --- |
| | | | | | | | --- | --- | --- | --- | --- | --- | | Applications | 100kb | Folder | 100kb | Folder | 100kb | | Cloud | 20kb | Folder | 20kb | Folder | 20kb | | Desktop | 150kb | Folder | 150kb | Folder | 150kb | | Documents | 75kb | Folder | 75kb | Folder | 75kb | | Downloads | 25kb | Folder | 25kb | Folder | 25kb | | Main | 50kb | Folder | 50kb | Folder | 50kb | | Other | 5kb | Folder | 5kb | Folder | 5kb | | Pictures | 150kb | Folder | 150kb | Folder | 150kb | | Videos | 1500kb | Folder | 1500kb | Folder | 1500kb |
<TreeTable value={nodes} scrollable scrollHeight="200px">
<Column field="name" header="Name" expander style={{ width: '250px' }}></Column>
<Column field="size" header="Size" style={{ width: '250px' }}></Column>
<Column field="type" header="Type 2" style={{ width: '250px' }}></Column>
<Column field="size" header="Size 2" style={{ width: '250px' }}></Column>
<Column field="type" header="Type 3" style={{ width: '250px' }}></Column>
<Column field="size" header="Size 3" style={{ width: '250px' }}></Column>
</TreeTable>
Copy
A column can be fixed during horizontal scrolling by enabling the frozen property on a Column. The location is defined with the alignFrozen that can be left or right.
Name
| | | --- | | Applications | | Cloud | | Desktop | | Documents | | Downloads | | Main | | Other | | Pictures | | Videos |
| Size | Type | Size | Type | Size | Type | | --- | --- | --- | --- | --- | --- |
| | | | | | | | --- | --- | --- | --- | --- | --- | | 100kb | Folder | 100kb | Folder | 100kb | Folder | | 20kb | Folder | 20kb | Folder | 20kb | Folder | | 150kb | Folder | 150kb | Folder | 150kb | Folder | | 75kb | Folder | 75kb | Folder | 75kb | Folder | | 25kb | Folder | 25kb | Folder | 25kb | Folder | | 50kb | Folder | 50kb | Folder | 50kb | Folder | | 5kb | Folder | 5kb | Folder | 5kb | Folder | | 150kb | Folder | 150kb | Folder | 150kb | Folder | | 1500kb | Folder | 1500kb | Folder | 1500kb | Folder |
<TreeTable value={nodes} scrollable frozenWidth="200px" scrollHeight="250px">
<Column field="name" header="Name" expander frozen style={{ width: '250px', height: '57px' }}></Column>
<Column field="size" header="Size" style={{ width: '250px', height: '57px' }} columnKey="size_0"></Column>
<Column field="type" header="Type" style={{ width: '250px', height: '57px' }} columnKey="type_0"></Column>
<Column field="size" header="Size" style={{ width: '250px', height: '57px' }} columnKey="size_1"></Column>
<Column field="type" header="Type" style={{ width: '250px', height: '57px' }} columnKey="type_1"></Column>
<Column field="size" header="Size" style={{ width: '250px', height: '57px' }} columnKey="size_2"></Column>
<Column field="type" header="Type" style={{ width: '250px', height: '57px' }} columnKey="type_2"></Column>
</TreeTable>
Copy
Column Resize#
Columns can be resized with drag and drop when resizableColumns is enabled. Default resize mode is _fit_that does not change the overall table width.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} resizableColumns showGridlines tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Setting columnResizeMode as expand changes the table width as well.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} resizableColumns showGridlines columnResizeMode="expand" tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Reorder#
Order of the columns can be changed using drag and drop when reorderableColumns is present.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} reorderableColumns tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Column Toggle#
Column visibility based on a condition can be implemented with dynamic columns, in this sample a MultiSelect is used to manage the visible columns.
Size
Type
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} header={header} tableStyle={{ minWidth: '50rem' }}>
<Column key="name" field="name" header="Name" expander />
{visibleColumns.map((col) => (
<Column key={col.field} field={col.field} header={col.header} />
))}
</TreeTable>
Copy
Conditional Style#
Particular rows and cells can be styled based on conditions. The rowClassName receives a row data as a parameter to return a style class for a row whereas cells are customized using the body template.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<TreeTable value={nodes} rowClassName={rowClassName} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size" body={sizeTemplate}></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Context Menu#
TreeTable has exclusive integration with ContextMenu using the onContextMenu event to open a menu on right click alont with_contextMenuSelection_ and onContextMenuSelectionChange properties to control the selection via the menu.
| Name | Size | Type | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder | | Main | 50kb | Folder | | Other | 5kb | Folder | | Pictures | 150kb | Folder | | Videos | 1500kb | Folder |
<ContextMenu model={menu} ref={cm} onHide={() => setSelectedNodeKey(null)} />
<TreeTable value={nodes} expandedKeys={expandedKeys} onToggle={(e) => setExpandedKeys(e.value)} contextMenuSelectionKey={selectedNodeKey}
onContextMenuSelectionChange={(event) => setSelectedNodeKey(event.value)} onContextMenu={(event) => cm.current.show(event.originalEvent)} tableStyle={{ minWidth: '50rem' }}>
<Column field="name" header="Name" expander></Column>
<Column field="size" header="Size"></Column>
<Column field="type" header="Type"></Column>
</TreeTable>
Copy
Stateful#
Stateful table allows keeping the state such as page, sort and filtering either at local storage or session storage so that when the page is visited again, table would render the data using the last settings.
Change the state of the table e.g paginate or expand rows, navigate away and then return to this table again to test this feature. The setting is set as session with the stateStorage property so that Table retains the state until the browser is closed. Other alternative is local referring to localStorage for an extended lifetime.
| Name | Size | Type | | --- | --- | --- | | | | | | --- | --- | --- | | Applications | 100kb | Folder | | Cloud | 20kb | Folder | | Desktop | 150kb | Folder | | Documents | 75kb | Folder | | Downloads | 25kb | Folder |
12
5
5
<TreeTable value={nodes} stateKey={'tree-table-state-demo-session'} stateStorage={'session'}>
<Column field="name" header="Name" expander filter filterPlaceholder="Filter by name"></Column>
<Column field="size" header="Size" filter filterPlaceholder="Filter by size"></Column>
<Column field="type" header="Type" filter filterPlaceholder="Filter by type"></Column>
</TreeTable>
Copy
Accessibility#
TreeTable uses a treegrid element whose attributes can be extended with the tableProps option. This property allows passing aria roles and attributes like aria-label and aria-describedby to define the table for readers. Default role of the table is table. Header, body and footer elements use rowgroup, rows use row role, header cells have columnheader and body cells use cell roles. Sortable headers utilizer aria-sort attribute either set to "ascending" or "descending".
Row elements manage aria-expanded for state along with aria-posinset, aria-setsize and aria-level attribute to define the hierachy.
When selection is enabled, aria-selected is set to true on a row. In checkbox mode, the built-in checkbox component use checkbox role with aria-checked state attribute.
Editable cells use custom templating so you need to manage aria roles and attributes manually if required.
Paginator is a standalone component used inside the TreeTable, refer to the paginator for more information about the accessibility features.
| Key | Function | | --- | --- | | tab | Moves through the headers. | | enter | Sorts the column. | | space | Sorts the column. |
| Key | Function | | --- | --- | | tab | Moves focus to the first selected node when focus enters the component, if there is none then first element receives the focus. If focus is already inside the component, moves focus to the next focusable element in the page tab sequence. | | shift + tab | Moves focus to the last selected node when focus enters the component, if there is none then first element receives the focus. If focus is already inside the component, moves focus to the previous focusable element in the page tab sequence. | | enter | Selects the focused treenode. | | space | Selects the focused treenode. | | down arrow | Moves focus to the next treenode. | | up arrow | Moves focus to the previous treenode. | | right arrow | If node is closed, opens the node otherwise moves focus to the first child node. | | left arrow | If node is open, closes the node otherwise moves focus to the parent node. |
Import
Basic
Dynamic Columns
Controlled
Template
Paginator
Basic
Template
Sort
Single Column
Multiple Columns
Filter
Selection
Single
Multiple
Checkbox
Events
Column Group
Lazy Load
Edit
Scroll
Vertical
Horizontal
Frozen Columns
Column Resize
Fit Mode
Expand Mode
Reorder
Column Toggle
Conditional Style
Context Menu
Stateful
Accessibility
PrimeReact 10.9.7 by PrimeTek