|
| 1 | +--- |
| 2 | +section: extensions |
| 3 | +subsection: Data view |
| 4 | +id: Overview |
| 5 | +title: Data view overview |
| 6 | +propComponents: ['DataView'] |
| 7 | +sortValue: 1 |
| 8 | +sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md |
| 9 | +--- |
| 10 | +import { useState, useEffect, useRef, useMemo } from 'react'; |
| 11 | +import { Drawer, DrawerContent, DrawerContentBody } from '@patternfly/react-core'; |
| 12 | +import { CubesIcon } from '@patternfly/react-icons'; |
| 13 | +import { useDataViewPagination, useDataViewSelection, useDataViewFilters, useDataViewSort } from '@patternfly/react-data-view/dist/dynamic/Hooks'; |
| 14 | +import { BulkSelect, BulkSelectValue, ErrorState, ResponsiveAction, ResponsiveActions, SkeletonTableHead, SkeletonTableBody } from '@patternfly/react-component-groups'; |
| 15 | +import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView'; |
| 16 | +import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar'; |
| 17 | +import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable'; |
| 18 | +import { useDataViewEventsContext, DataViewEventsContext, DataViewEventsProvider, EventTypes } from '@patternfly/react-data-view/dist/dynamic/DataViewEventsContext'; |
| 19 | +import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters'; |
| 20 | +import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter'; |
| 21 | +import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter'; |
| 22 | + |
| 23 | +**Note:** Data view lives in its own package [`@patternfly/react-data-view`](https://www.npmjs.com/package/@patternfly/react-data-view) |
| 24 | + |
| 25 | +If you notice a bug, or if you have a suggestion for improving the data view extension or its documentation, please file an issue in the [react-data-view](https://github.com/patternfly/react-data-view/issues) repository. Before doing so, please make sure there is not already a pre-existing issue. |
| 26 | + |
| 27 | +--- |
| 28 | + |
| 29 | +The **data view** extension enables you to display datasets in organized layouts, with data representations and interactive toolbars for actions like selection and pagination. |
| 30 | + |
| 31 | +### Layout |
| 32 | + |
| 33 | +A data view should contain a header, the data representation, and a footer. These parts are organized in a [stack layout](/layouts/stack). |
| 34 | + |
| 35 | +The data view toolbars and sub-components that display the data (like a card view or table) are always passed as `children` to the `<DataView>` component. |
| 36 | + |
| 37 | +```js file="./AbstractLayoutExample.tsx" |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +### Modularity |
| 42 | + |
| 43 | +The extension's modular architecture lets you efficiently create consistent data views, either by using predefined sub-components and hooks, or by defining your own. You can choose the tools that suit your needs and easily replace any part with a custom implementation. |
| 44 | + |
| 45 | +The `<DataViewToolbar>` component extends the [PatternFly toolbar](/components/toolbar) to support the most common needs. For more details, refer to the [data view toolbar](/extensions/data-view/toolbar) examples. You can also use a custom toolbar component if needed for your use case. |
| 46 | + |
| 47 | +Data can be presented using the predefined `<DataViewTable>` component, which is an abstraction above the [PatternFly table](/components/table). For more details, refer to the [data view table](/extensions/data-view/table) examples. If you have more specific data display needs, you can pass a custom implementation as a `<DataView>` child. In the near future, we are also planning to introduce a predefined card view component. |
| 48 | + |
| 49 | +```js file="./PredefinedLayoutFullExample.tsx" |
| 50 | + |
| 51 | +``` |
| 52 | + |
| 53 | +## Events context |
| 54 | + |
| 55 | +The `<DataViewEventsContext>` component is an advanced feature that enables external listening of data view events. In order to share data view context with your other UI components, both your components and your data view should be wrapped with the `<DataViewEventsProvider>`. This is demonstrated in the following example. |
| 56 | + |
| 57 | +### Row click subscription example |
| 58 | +This example uses the `<DataViewEventsProvider>` to display details about a selected row in a [drawer component](/components/drawer). |
| 59 | + |
| 60 | + |
| 61 | +```js file="./EventsExample.tsx" |
| 62 | + |
| 63 | +``` |
0 commit comments