You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> For the most up-to-date documentation and code examples, consult both PatternFly.org and the official GitHub repository. When using AI tools, leverage context7 to fetch the latest docs from these sources.
191
+
> For the most up-to-date documentation and code examples, consult both PatternFly.org and the official GitHub repository. When using AI tools, leverage context7 to fetch the latest docs from these sources.
-**[Component API](https://github.com/patternfly/patternfly-react/tree/main/packages/react-core/src/components/ChipGroup)** - ChipGroup component API for tags
PatternFly Data View provides a standardized way to present and interact with tabular or list-based data, following PatternFly design and accessibility guidelines.
153
+
The `@patternfly/react-data-view` component is a powerful, opinionated tool for building consistent data-driven tables and lists. It composes standard PatternFly components like `Table`, `Toolbar`, and `Pagination` into a single, streamlined API.
161
154
162
-
### Installation
163
-
```bash
164
-
npm install @patternfly/react-data-view
165
-
```
155
+
### When to Use Data View
156
+
- ✅ **Use for standard list pages**: When you need to display a list of resources with common functionality like filtering, sorting, selection, and actions.
157
+
- ✅ **To enforce consistency**: Use it across your application to ensure all data tables look and behave the same.
158
+
- ❌ **Not for highly custom layouts**: If your layout deviates significantly from a standard table or list view, composing individual PatternFly components may be a better approach.
- **Provide stable data and columns**: For performance, memoize the `data` and `columns` props passed to `DataView`, especially if they are derived from other state.
187
+
```jsx
188
+
constcolumns=useMemo(() => [...], []);
189
+
constdata=useMemo(() => [...], [sourceData]);
207
190
208
-
### Directory Structure
209
-
```
210
-
src
211
-
|-DataView
212
-
|-index.ts
213
-
|-DataView.tsx
214
-
```
191
+
<DataView data={data} columns={columns} />
192
+
```
215
193
216
-
### OUIA ID Convention
217
-
For testing, use the component name as the default OUIA ID, and for subcomponents, use `ComponentName-element-specification`.
218
-
```ts
219
-
ouiaId="DataView-actions-button"
220
-
```
194
+
- **Leverage the built-in toolbar**: `DataView` includes a `Toolbar` with filtering capabilities. Provide filter configurations instead of building your own toolbar from scratch.
221
195
222
-
### Testing & Linting
223
-
- Add unit tests to `DataView.test.tsx`
224
-
- Add Cypress component/E2E tests to `cypress/component/DataView.cy.tsx` and `cypress/e2e/DataView.spec.cy.ts`
225
-
- Run tests and linting:
226
-
```bash
227
-
npm run test
228
-
npm run lint
229
-
```
196
+
- **Use the provided action resolver**: For row actions, use the `onRowAction` prop and provide an action resolver function. This ensures actions are handled consistently.
230
197
231
-
### Accessibility
232
-
- Provide proper ARIA labels and roles
233
-
- Ensure keyboard navigation and screen reader support
A production example of PatternFly Data View usage can be found in the OpenShift Console codebase. It's an excellent resource for seeing how `DataView` is integrated with live Kubernetes data and Redux for state management.
255
201
256
-
<DataView.../>
202
+
- **[DataViewPodList.tsx on GitHub](https://github.com/openshift/console/blob/79d29bca8440a5ad82b5257bb0f37bc24384eb0e/frontend/public/components/data-view-poc/DataViewPodList.tsx)**
257
203
258
-
### DataView component example label
204
+
Key integration patterns from this example include:
205
+
- Integrating Data View with live Kubernetes data and application state.
206
+
- Passing dynamic data and columns to the component.
207
+
- Handling loading, error, and empty states in a production context.
208
+
- Using PatternFly composable components for custom row rendering and actions.
209
+
- Connecting Data View to Redux or other state management solutions.
259
210
260
-
```js file="./DataViewExample.tsx"```
261
-
```
211
+
> For advanced usage, review the linked file to see how Data View is composed with other PatternFly and application-specific components.
262
212
263
-
### References
213
+
> **Note:** Always consult the latest PatternFly Data View documentation and demo source code for the most up-to-date usage patterns and best practices.
264
214
- [PatternFly React Data View GitHub](https://github.com/patternfly/react-data-view)
265
-
- [PatternFly Data View NPM](https://www.npmjs.com/package/@patternfly/react-data-view)
266
-
267
-
> **Note:** Always consult the latest PatternFly Data View documentation and demo source code for up-to-date usage patterns and best practices.
268
-
269
-
### Real-World Example: OpenShift Console
270
-
271
-
A production example of PatternFly Data View usage can be found in the OpenShift Console codebase:
272
-
- [DataViewPodList.tsx on GitHub](https://github.com/openshift/console/blob/79d29bca8440a5ad82b5257bb0f37bc24384eb0e/frontend/public/components/data-view-poc/DataViewPodList.tsx)
273
-
274
-
**Key integration patterns and best practices from this example:**
275
-
- Integrates Data View with live Kubernetes data (pods) and application state.
276
-
- Demonstrates how to pass dynamic data and columns to the Data View component.
277
-
- Shows how to handle loading, error, and empty states in a real product context.
278
-
- Illustrates the use of PatternFly composable components for custom row rendering and actions.
279
-
- Provides a template for connecting Data View to Redux or other state management solutions.
280
-
281
-
> For advanced usage, review the linked file to see how Data View is composed with other PatternFly and application-specific components.
215
+
- [PatternFly Data View NPM](https://www.npmjs.com/package/@patternfly/react-data-view)
PatternFly provides powerful props for controlling column widths and making headers and columns "sticky" for better usability with wide or long tables.
68
+
69
+
### Column Width Control
70
+
Use the `width` modifier on the `<Th>` component to specify column widths as a percentage of the table's total width.
71
+
72
+
- ✅ **Use `width(percentage)`**: Best for flexible, responsive layouts.
73
+
- ❌ **Avoid fixed pixel widths**: Can break responsiveness.
In addition to setting explicit widths, you can control how text behaves within cells using the `modifier` prop on `<Th>` and `<Td>` components. This influences column dimensions and text overflow.
95
+
96
+
Key text modifiers include:
97
+
-**`truncate`**: Truncates text with an ellipsis.
98
+
-**`wrap`**: Forces text to wrap, which is useful for long header text.
99
+
-**`nowrap`**: Prevents text from wrapping.
100
+
-**`breakWord`**: Forces long, unbreakable strings (like URLs) to break.
101
+
-**`fitContent`**: Shrinks the column to fit its content.
102
+
103
+
For detailed usage and code examples, see the official PatternFly documentation and the example in the PatternFly React repository.
104
+
105
+
-[**Controlling Text in Tables (PatternFly Docs)**](https://www.patternfly.org/components/table/controlling-text)
106
+
-[**TableControllingText.tsx Example on GitHub**](https://github.com/patternfly/patternfly-react/blob/main/packages/react-table/src/components/Table/examples/TableControllingText.tsx)
107
+
108
+
### Sticky Headers and Columns
109
+
For tables that scroll horizontally or vertically, you can make the header, specific columns, or the action column "sticky."
110
+
111
+
-**`isStickyHeader`**: Add this prop to the `<Table>` component to make the header row stick to the top during vertical scrolling.
112
+
-**`isSticky`**: Add this prop to a `<Th>` or `<Td>` component to make an entire column sticky during horizontal scrolling. This is commonly used for the first column (e.g., selection checkbox or ID), or last column (e.g. columns containing actions menus).
113
+
114
+
```jsx
115
+
// ✅ Sticky header, first column, and action column
0 commit comments