Package org.patternfly.dataprovider
This package provides a unified interface for binding data to PatternFly components like data lists and tables.
The DataProvider class manages items, filtering, sorting, pagination, and selection,
automatically updating bound displays when state changes.
Key Classes
DataProvider- Central class for managing items with support for filtering, sorting, paging, and selectionDisplay- Interface implemented by components to receive data and state updatesPageInfo- Holds pagination state (page size, current page, total items)SelectionInfo- Tracks selected items and selection stateSortInfo- Manages sort order and comparator for itemsItemDisplay- Simplified display interface for components showing a single item
Usage Pattern
The typical workflow involves creating a DataProvider, binding it to one or more
Display components, and then manipulating the data:
// Create a data provider with an identifier function
DataProvider<User> dataProvider = new DataProvider<>(user -> user.id());
// Bind it to a display component (e.g., DataList)
DataList<User> dataList = dataList(dataProvider);
dataProvider.bindDisplay(dataList);
// Update items - this automatically updates all bound displays
dataProvider.update(users);
// Add filtering
dataProvider.addFilter("active", user -> user.isActive());
// Configure sorting
dataProvider.sort(new SortInfo<>(Comparator.comparing(User::name)));
// Navigate pages
dataProvider.gotoNextPage();
Features
Item Management
The data provider maintains three collections of items:
- All items - The complete dataset
- Filtered items - Items matching active filters
- Visible items - Current page of filtered items
Filtering
Multiple filters can be registered by ID and combined using predicates. When filters change, the data provider automatically recalculates filtered and visible items.
Sorting
Items are sorted using a Comparator. Sort changes are immediately reflected in bound displays.
Pagination
Automatic pagination with configurable page size. The PageInfo class
tracks current page, total pages, and item counts.
Selection
Support for single and multi-selection with selection events. The SelectionInfo
maintains the set of selected items and provides methods to query selection state.
- See Also:
-
ClassDescriptionDataProvider<T>Holds items and state for components like data lists and tables.Display<T>Displays items managed by a
DataProvider.ItemDisplay<E extends HTMLElement, T>Reusable class for typed components to customize the item ID, string value and display.Holds the selected items in aDataProvider.SortInfo<T>Holds the current sort option in aDataProvider.