Package org.patternfly.dataprovider


package org.patternfly.dataprovider
Data provider API for managing items and state in data-driven components.

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 selection
  • Display - Interface implemented by components to receive data and state updates
  • PageInfo - Holds pagination state (page size, current page, total items)
  • SelectionInfo - Tracks selected items and selection state
  • SortInfo - Manages sort order and comparator for items
  • ItemDisplay - 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: