Data view toolbar

The data view toolbar component renders a default opinionated data view toolbar above or below the data section.

Data view toolbar can contain pagination, bulk select, filters, actions, or other custom child content. To pass child items to the toolbar, use the toolbar item component or predefined <DataViewToolbar> props for specific use cases.

You can further customize toolbar interactions by referring to the additional documentation:

Toolbar example

1 - 10 of 0

Toolbar actions

To support additional user needs, you can pass relevant actions to the toolbar via actions. Add standard PatternFly actions (like buttons) or choose predefined responsive actions which ensure the responsive behavior of multiple actions in 1 toolbar.

Actions example

1 - 10 of 0

Pagination

To help users navigate data records that span multiple pages, add pagination support to your toolbar.

The data view toolbar can display a pagination using the pagination prop. You can also pass a custom ouiaId to the toolbar for testing purposes. You can also persist pagination values in the URL to make it easier to share or bookmark specific pages of your data.

Pagination state

The useDataViewPagination hook manages the pagination state of the data view.

Initial values:

  • perPage initial value.
  • Optional page initial value.
  • Optional searchParams object.
  • Optional setSearchParams function.

While the hook works seamlessly with the React Router library, you do not need to use it to take advantage of URL persistence. The searchParams and setSearchParams props can be managed using native browser APIs (URLSearchParams and window.history.pushState) or any other routing library of your choice. If you don't pass these two props, the pagination state will be stored internally without the URL usage.

You can also pass custom pageParam or perPageParam names, renaming the pagination parameters in the URL.

The retrieved values are named to match the PatternFly pagination component props.

Return values:

  • Current page number.
  • onSetPage to modify current page.
  • Items perPage value.
  • onPerPageSelect to modify per page value.

Pagination example

This example uses the URL to persist the pagination state.

1 - 5 of 6
RepositoriesBranchesPull requestsWorkspacesLast commit
Repository oneBranch onePull request oneWorkspace oneTimestamp one
Repository twoBranch twoPull request twoWorkspace twoTimestamp two
Repository threeBranch threePull request threeWorkspace threeTimestamp three
Repository fourBranch fourPull request fourWorkspace fourTimestamp four
Repository fiveBranch fivePull request fiveWorkspace fiveTimestamp five
1 - 5 of 6

Selection

To allow users to select data records inside the data view, add selection support that displays a row's selection state.

The data view toolbar can display a bulk selection component by using the predefined component group extension bulk select component.

Selection state

The useDataViewSelection hook manages the selection state of the data view.

Initial values:

  • Optional initialSelected array of record's identifiers selected by default.
  • matchOption function to check if the record is selected.
    • When no matchOption is passed, the Array.prototype.includes() operation is performed on the selected array.

Return values:

  • selected array of currently selected records.
  • isSelected function returning the selection state for the record.
  • onSelect callback to modify the selection state. This accepts the isSelecting flag (indicates if records are being selected or deselected) and items (affected records).

Selection example

Data selection table head cellRepositoriesBranchesPull requestsWorkspacesLast commit
Repository oneBranch onePull request oneWorkspace oneTimestamp one
Repository twoBranch twoPull request twoWorkspace twoTimestamp two
Repository threeBranch threePull request threeWorkspace threeTimestamp three
Repository fourBranch fourPull request fourWorkspace fourTimestamp four
Repository fiveBranch fivePull request fiveWorkspace fiveTimestamp five
Repository sixBranch sixPull request sixWorkspace sixTimestamp six

Filters

To allow users to filter data records in the data view, add filtering support that displays the applied filter chips.

The data view toolbar can include a set of filters by passing a React node to the filters property. You can use the predefined components <DataViewFilters>, <DataViewTextFilter>, and <DataViewCheckboxFilter> to customize and handle filtering directly in the toolbar. The <DataViewFilters> component is a wrapper that allows conditional filtering using multiple attributes. If you need just a single filter, you can use <DataViewTextFilter>, <DataViewCheckboxFilter>, or a different filter component alone. Props of these filter components are listed in the props section of this page.

You can either pass a value and onChange event to every filter separately, or you can pass values and onChange to the <DataViewFilters> wrapper, which makes them available to its children. Props directly passed to child filters have a higher priority than the "inherited" ones.

Filters state

The useDataViewFilters hook manages the filter state of the data view. It allows you to define default filter values, synchronize filter state with URL parameters, and handle filter changes efficiently.

Initial values:

  • initialFilters object with default filter values (if the filter param allows multiple values, pass an array).
  • Optional searchParams object for managing URL-based filter state.
  • Optional setSearchParams function to update the URL when filters are modified.

The useDataViewFilters hook works well with the React Router library to support URL-based filtering. Alternatively, you can manage the filter state in the URL using URLSearchParams and window.history.pushState APIs, or other routing libraries. If no URL parameters are provided, the filter state is managed internally.

Return values:

  • filters object representing the current filter values.
  • onSetFilters function to update the filter state.
  • clearAllFilters function to reset all filters to their initial values.

Filtering example

This example demonstrates the setup and usage of filters within the data view. It includes text filters for different attributes, the ability to clear all filters, and persistence of filter state in the URL.

1 - 5 of 6
NameBranchPull requestsWorkspaceLast commit
Repository oneBranch onePull request oneWorkspace oneTimestamp one
Repository twoBranch twoPull request twoWorkspace twoTimestamp two
Repository threeBranch threePull request threeWorkspace oneTimestamp three
Repository fourBranch fourPull request fourWorkspace oneTimestamp four
Repository fiveBranch fivePull request fiveWorkspace twoTimestamp five
1 - 5 of 6

Props

DataViewToolbar

extends ToolbarProps
*required
NameTypeDefaultDescription
actionsReact.ReactNodeReact node to display actions
bulkSelectReact.ReactNodeReact node to display bulk select
classNamestringToolbar className
customLabelGroupContentReact.ReactNodeReact node to display custom filter labels
filtersReact.ReactNodeReact node to display filters
ouiaIdstring'DataViewToolbar'Custom OUIA ID
paginationReact.ReactNodeReact node to display pagination

DataViewFilters

extends ToolbarToggleGroupProps
*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent rendered inside the data view
breakpointToolbarToggleGroupProps['breakpoint']'xl'Breakpoint for the toolbar toggle group
onChange(key: string, newValues: Partial<T>) => voidOptional onChange callback shared across filters
ouiaIdstring'DataViewFilters'Custom OUIA ID
toggleIconToolbarToggleGroupProps['toggleIcon']<FilterIcon />Icon for the toolbar toggle group
valuesTOptional values shared across filters

DataViewTextFilter

extends SearchInputProps
*required
NameTypeDefaultDescription
filterIdrequiredstringUnique key for the filter attribute
titlerequiredstringFilter title displayed in the toolbar
onChange(event: React.FormEvent<HTMLInputElement> | undefined, value: string) => voidCallback for when the input value changes
onClearNo type info() => onChange?.(undefined, '')
ouiaIdstring'DataViewTextFilter'Custom OUIA ID
showToolbarItemToolbarFilterProps['showToolbarItem']Controls visibility of the filter in the toolbar
trimValuebooleantrueTrims input value on change
valuestring''Current filter value

DataViewCheckboxFilter

extends MenuProps
*required
NameTypeDefaultDescription
filterIdrequiredstringUnique key for the filter attribute
titlerequiredstringFilter title displayed in the toolbar
onChange(event?: React.MouseEvent, values?: string[]) => voidCallback for updating when item selection changes.
options(DataViewFilterOption | string)[][]Filter options displayed
ouiaIdstring'DataViewCheckboxFilter'Custom OUIA ID
placeholderstringPlaceholder text of the menu
showBadgeboolean!placeholderControls visibility of the selected items badge
showIconboolean!placeholderControls visibility of the filter icon
showToolbarItembooleanControls visibility of the filter in the toolbar
valuestring[][]Array of current filter values
We use cookies on our websites to deliver our online services. Details about how we use cookies and how you may disable them are set out in our Privacy Statement. By using this website you agree to our use of cookies.