This document covers the Table component and its supporting sub-components used for displaying structured data in PatternFly Java. The Table system provides comprehensive support for tabular data display, including features for row selection, hierarchical tree tables, asynchronous data loading, and various cell customization options.
For form input components like buttons and checkboxes, see Form and Input Components. For menu and selection components, see Menu and Selection Components.
The Table component system follows a hierarchical structure with the Table component as the root container and several specialized sub-components for building table structures.
Sources: components/src/main/java/org/patternfly/component/table/Table.java62-119 components/src/main/java/org/patternfly/component/table/Tr.java85-148 components/src/main/java/org/patternfly/component/table/Cell.java33-47
The Table class is the main component implementing BaseComponent<HTMLTableElement, Table>. It serves as the container for all table content and manages selection behavior.
Tables can be instantiated in two primary modes defined by the TableType enum:
| Type | Role Attribute | CSS Modifier | Use Case |
|---|---|---|---|
table | grid | none | Standard tabular data display |
treeTable | treegrid | pf-m-tree-view | Hierarchical data with expand/collapse |
Sources: components/src/main/java/org/patternfly/component/table/Table.java68-100
The Table component supports two selection modes through the SelectionMode enum:
single: Only one row can be selected at a time. Previous selections are cleared when a new row is selected.multi: Multiple rows can be selected simultaneously. A "select all" checkbox appears in the header when configured.Sources: components/src/main/java/org/patternfly/component/table/Table.java175-180 components/src/main/java/org/patternfly/component/table/Table.java245-278
The Tr class represents a table row and implements several key interfaces: HasItems<Cell<?>>, Expandable, HasIdentifier, and ComponentContext. Each row is uniquely identified and can contain multiple cells.
Sources: components/src/main/java/org/patternfly/component/table/Tr.java135-148 components/src/main/java/org/patternfly/component/table/Tr.java441-453
Rows can be made clickable to support row selection via click or keyboard events:
Sources: components/src/main/java/org/patternfly/component/table/Tr.java202-236
The Table component provides comprehensive support for hierarchical tree structures with expandable rows and asynchronous data loading.
Sources: components/src/main/java/org/patternfly/component/table/Tr.java121-133 components/src/main/java/org/patternfly/component/table/Tr.java273-309
Tree tables support asynchronous loading of child rows with loading indicators and error handling:
Sources: components/src/main/java/org/patternfly/component/table/Tr.java311-353 components/src/main/java/org/patternfly/component/table/Tr.java104-120
Tree tables can be reset to reload asynchronous data:
Sources: components/src/main/java/org/patternfly/component/table/Tr.java355-368
The abstract Cell<B> class provides common functionality for both header cells (Th) and data cells (Td). It implements HasIdentifier, ComponentContext, and ElementTextMethods.
Sources: components/src/main/java/org/patternfly/component/table/Cell.java33-89
Header cells are created with the Th class and include support for tooltips and selection checkboxes:
Sources: components/src/main/java/org/patternfly/component/table/Th.java40-117
Data cells are created with the Td class and can be configured for actions or selection:
Sources: components/src/main/java/org/patternfly/component/table/Td.java39-107
The Thead and Tbody classes are container components for table rows:
| Component | Element | Role | Purpose |
|---|---|---|---|
Thead | <thead> | rowgroup | Contains header rows with Th cells |
Tbody | <tbody> | rowgroup | Contains data rows with Td cells |
Both implement HasItems<Tr> and manage collections of Tr components:
Sources: components/src/main/java/org/patternfly/component/table/Thead.java components/src/main/java/org/patternfly/component/table/Tbody.java
The Tbody class maintains an internal map of Tr items indexed by identifier:
Sources: Based on pattern from components/src/main/java/org/patternfly/component/table/Table.java103-118 and Tr integration
Sources: components/src/main/java/org/patternfly/component/table/Table.java components/src/main/java/org/patternfly/component/table/Tr.java
| Method | Parameters | Description |
|---|---|---|
select(String identifier) | identifier | Selects row by identifier |
select(Tr item) | item | Selects specified row |
select(Tr item, boolean selected) | item, selected | Sets selection state of row |
select(Tr item, boolean selected, boolean fireEvent) | item, selected, fireEvent | Sets selection state with event control |
selectAll() | - | Selects all rows (multi-select only) |
selectAll(boolean fireEvent) | fireEvent | Selects all rows with event control |
selectNone() | - | Deselects all rows |
selectNone(boolean fireEvent) | fireEvent | Deselects all rows with event control |
selectedItems() | - | Returns List |
Sources: components/src/main/java/org/patternfly/component/table/Table.java226-328
| Method | Description |
|---|---|
markSelected(boolean selected) | Internal method to update visual selection state |
isSelected() | Returns current selection state |
clickable() | Makes row clickable for selection |
clickable(boolean clickable) | Enables/disables clickable behavior |
Sources: components/src/main/java/org/patternfly/component/table/Tr.java202-236 components/src/main/java/org/patternfly/component/table/Tr.java441-463
| Method | Parameters | Description |
|---|---|---|
addChild(Tr child) | child | Adds static child row |
addChildren(Iterable<T> items, Function<T, Tr> display) | items, display | Adds multiple static children |
addChildren(Function<Tr, Promise<Iterable<Tr>>> children) | children | Configures async child loading |
expand(boolean fireEvent) | fireEvent | Expands row to show children |
collapse(boolean fireEvent) | fireEvent | Collapses row to hide children |
load() | - | Loads async children (returns Promise) |
reset() | - | Resets async state to reload children |
Sources: components/src/main/java/org/patternfly/component/table/Tr.java169-198 components/src/main/java/org/patternfly/component/table/Tr.java273-368
The TitleCell is a specialized cell used as the first cell in tree table rows to display the expand/collapse toggle:
| Method | Parameters | Description |
|---|---|---|
addToggle() | - | Adds the expand/collapse toggle button |
removeToggle() | - | Removes toggle (for leaf nodes) |
expand() | - | Updates toggle visual to expanded state |
collapse() | - | Updates toggle visual to collapsed state |
Sources: Based on components/src/main/java/org/patternfly/component/table/Tr.java282-284 and components/src/main/java/org/patternfly/component/table/Tr.java334-336
Both Tr and Cell components implement ComponentContext, providing a key-value store for associating arbitrary data with table elements:
This allows storing domain objects or metadata directly on table components without requiring separate lookup structures.
Sources: components/src/main/java/org/patternfly/component/table/Tr.java238-242 components/src/main/java/org/patternfly/component/table/Cell.java67-88 core/src/main/java/org/patternfly/core/ComponentContext.java
The table components implement comprehensive ARIA attributes for accessibility:
| Attribute | Value | Applied By |
|---|---|---|
role | grid or treegrid | Table constructor based on TableType |
aria-label | User-defined | table.ariaLabel(String) |
| Attribute | Value | Applied By |
|---|---|---|
role | row | Tr constructor |
aria-level | Integer depth | Automatically set for tree tables |
aria-expanded | true or false | Expandable rows |
aria-setsize | Row count | Tree table parent rows |
aria-posinset | Position | Tree table rows |
aria-label | "Row selected" | Selected rows |
| Attribute | Value | Applied By |
|---|---|---|
role | columnheader | Th constructor |
role | cell or gridcell | Td constructor (gridcell for tree tables) |
scope | col | Th constructor |
tabindex | -1 or 0 | Cell constructor, updated by TooltipToggle |
Sources: components/src/main/java/org/patternfly/component/table/Table.java86-98 components/src/main/java/org/patternfly/component/table/Tr.java136-139 components/src/main/java/org/patternfly/component/table/Th.java63-76 components/src/main/java/org/patternfly/component/table/Td.java60-68 components/src/main/java/org/patternfly/component/table/Table.java111-117
Refresh this wiki