The data view table component renders your data into columns and rows within a PatternFly table component. You can easily customize and configure the table with these additional data view components and props.
Configuring rows and columns
To define rows and columns for your table, use these props:
columns
: Defines the column heads of the table. Each item in the array can be aReactNode
for simple heads, or an object with the following properties:cell
: Content to display in the column head.props
(optional): (ThProps
) to pass to the<Th>
component, such aswidth
,sort
, and other table head cell properties.
rows
: Defines the rows to be displayed in the table. Each item in the array can be either an array ofDataViewTd
for simple rows, or an object with the following properties:row
: Content to display in each cell in the row.id
(optional): Unique identifier for the row that's used for matching selected items.props
(optional): (TrProps
) to pass to the<Tr>
component, such asisHoverable
,isRowSelected
, and other table row properties.
It is also possible to disable row selection using the isSelectDisabled
function, which can be passed to the wrapping DataView
component through the selection
prop.
Table example
Repositories | Branches | Pull requests | Workspaces | |||
---|---|---|---|---|---|---|
Branch one | Pull request one | Workspace one | Timestamp one | |||
Branch two | Pull request two | Workspace two | Timestamp two | |||
Branch three | Pull request three | Workspace three | Timestamp three | |||
Branch four | Pull request four | Workspace four | Timestamp four | |||
Branch five | Pull request five | Workspace five | Timestamp five | |||
Branch six | Pull request six | Workspace six | Timestamp six |
Tree table
A tree table includes expandable rows and custom icons for leaf and parent nodes.
To enable a tree table, pass the isTreeTable
flag to the <DataViewTable>
component.
Tree table rows have to be defined with following keys:
row
: Defines the content for each cell in the row.id
: Unique identifier for the row that's used for matching selected items.children
(optional): Defines the children rows.
To update a row's icon to reflect its expansion state, pass collapsedIcon
, expandedIcon
, and leafIcon
to <DataViewTable>
.
To disable row selection, pass the isSelectDisabled
function to selection
prop of the wrapping <DataView>
component .
Tree table example
Repositories | Branches | Pull requests | Workspaces | Last commit |
---|---|---|---|---|
Repository one | Branch one | Pull request one | Workspace one | Timestamp one |
Repository two | Branch two | Pull request two | Workspace two | Timestamp two |
Repository three | Branch three | Pull request three | Workspace three | Timestamp three |
Repository four | Branch four | Pull request four | Workspace four | Timestamp four |
Repository five | Branch five | Pull request five | Workspace five | Timestamp five |
Repository six | Branch six | Pull request six | Workspace six | Timestamp six |
Sorting
The following example demonstrates how to enable sorting functionality within a data view. This implementation supports dynamic sorting by column and persists the sort state in the page's URL via React Router.
Sorting example
Repository one | Branch one | Pull request one | Workspace one | Timestamp one |
Repository two | Branch two | Pull request two | Workspace two | Timestamp two |
Repository three | Branch three | Pull request three | Workspace three | Timestamp three |
Repository four | Branch four | Pull request four | Workspace four | Timestamp four |
Repository five | Branch five | Pull request five | Workspace five | Timestamp five |
Repository six | Branch six | Pull request six | Workspace six | Timestamp six |
Sorting state
The useDataViewSort
hook manages the sorting state of a data view and provides an easy way to handle sorting logic, such as synchronization with URL parameters and the definition of default sorting behavior.
Initial values:
initialSort
object to set defaultsortBy
anddirection
values:sortBy
: Key of the initial column to sort.direction
: Default sorting direction (asc
ordesc
).
searchParams
(optional): Object to manage URL-based synchronization of sort state.setSearchParams
(optional): Function to update the URL parameters when sorting changes.defaultDirection
: Used to set the default direction when no direction is specified.- Customizable parameter names for the URL:
sortByParam
: Name of the URL parameter for the column key.directionParam
: Name of the URL parameter for the sorting direction. TheuseDataViewSort
hook integrates seamlessly with React Router to manage the sort state via URL parameters. Alternatively, you can useURLSearchParams
andwindow.history.pushState
APIs, or other routing libraries. If URL synchronization is not configured, the sort state is managed internally within the component.
Return values:
sortBy
: Key of the column currently being sorted.direction
: Current sorting direction (asc
ordesc
).onSort
: Function to handle sorting changes programmatically or via user interaction.
States
The data view table allows you to react to the activeState
of the data view (such as empty
, error
, loading
). You can use the headStates
and bodyStates
props to define the table head and body for a given state.
Empty
When there is no data to render in the data view, you can instead display an empty state.
You can create your empty state by passing a PatternFly empty state to the empty
key of headStates
or bodyStates
.
Repositories | Branches | Pull requests | Workspaces | Last commit |
---|---|---|---|---|
No data foundThere are no matching data to be displayed. |
Error
When there is a data connection or retrieval error, you can display an error state.
The error state will be displayed when the data view activeState
value is error
.
You can create your error state by passing either the component groups extension's error state or a PatternFly empty state to the error
key of headStates
or bodyStates
.
Repositories | Branches | Pull requests | Workspaces | Last commit |
---|---|---|---|---|
Unable to load dataThere was an error retrieving data. Check your connection and reload the page. |
Loading
To indicate that data is loading, you can display a loading state.
The loading state will be displayed when the data view activeState
value is loading
.
You can create your loading state by passing either the component groups extension's skeleton table or a customized PatternFly empty state to the loading
key of headStates
or bodyStates
.
Repositories | Branches | Pull requests | Workspaces | Last commit |
---|---|---|---|---|
Props
DataViewTableBasic
Name | Type | Default | Description |
---|---|---|---|
columnsrequired | DataViewTh[] | Columns definition | |
rowsrequired | DataViewTr[] | Current page rows | |
bodyStates | Partial<Record<DataViewState | string, React.ReactNode>> | Table body states to be displayed when active | |
headStates | Partial<Record<DataViewState | string, React.ReactNode>> | Table head states to be displayed when active | |
ouiaId | string | 'DataViewTableBasic' | Custom OUIA ID |
DataViewTableTree
Name | Type | Default | Description |
---|---|---|---|
columnsrequired | DataViewTh[] | Columns definition | |
rowsrequired | DataViewTrTree[] | Current page rows | |
bodyStates | Partial<Record<DataViewState | string, React.ReactNode>> | Table body states to be displayed when active | |
collapsedIcon | React.ReactNode | null | Optional icon for the collapsed parent rows |
expandedIcon | React.ReactNode | null | Optional icon for the expanded parent rows |
headStates | Partial<Record<DataViewState | string, React.ReactNode>> | Table head states to be displayed when active | |
leafIcon | React.ReactNode | null | Optional icon for the leaf rows |
ouiaId | string | 'DataViewTableTree' | Custom OUIA ID |
DataViewTrTree
Name | Type | Default | Description |
---|---|---|---|
idrequired | string | ||
children | DataViewTrTree[] |
DataViewTrObject
Name | Type | Default | Description |
---|---|---|---|
rowrequired | DataViewTd[] | Array of rows | |
id | string | Unique identifier of a row | |
props | TrProps | Props passed to Tr |