@patternfly/react-data-view 6.3.0 → 6.4.0-prerelease.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/dist/cjs/DataViewTable/DataViewTable.d.ts +6 -1
  2. package/dist/cjs/DataViewTable/DataViewTable.js +21 -1
  3. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
  4. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.js +46 -6
  5. package/dist/cjs/DataViewTableBasic/DataViewTableBasic.test.js +47 -9
  6. package/dist/cjs/DataViewTableHead/DataViewTableHead.d.ts +2 -0
  7. package/dist/cjs/DataViewTableHead/DataViewTableHead.js +5 -4
  8. package/dist/cjs/DataViewTableTree/DataViewTableTree.d.ts +2 -0
  9. package/dist/cjs/DataViewTableTree/DataViewTableTree.js +28 -1
  10. package/dist/cjs/DataViewTableTree/DataViewTableTree.test.js +4 -0
  11. package/dist/cjs/DataViewTh/DataViewTh.d.ts +32 -0
  12. package/dist/cjs/DataViewTh/DataViewTh.js +222 -0
  13. package/dist/cjs/DataViewTh/index.d.ts +2 -0
  14. package/dist/cjs/DataViewTh/index.js +23 -0
  15. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.d.ts +26 -0
  16. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.js +229 -0
  17. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.d.ts +1 -0
  18. package/dist/cjs/DataViewTreeFilter/DataViewTreeFilter.test.js +171 -0
  19. package/dist/cjs/DataViewTreeFilter/index.d.ts +2 -0
  20. package/dist/cjs/DataViewTreeFilter/index.js +23 -0
  21. package/dist/cjs/Hooks/selection.d.ts +1 -0
  22. package/dist/cjs/Hooks/selection.js +5 -1
  23. package/dist/cjs/Hooks/selection.test.js +48 -0
  24. package/dist/cjs/InternalContext/InternalContext.d.ts +2 -0
  25. package/dist/cjs/index.d.ts +6 -0
  26. package/dist/cjs/index.js +10 -1
  27. package/dist/dynamic/DataViewTh/package.json +1 -0
  28. package/dist/dynamic/DataViewTreeFilter/package.json +1 -0
  29. package/dist/dynamic-modules.json +62 -0
  30. package/dist/esm/DataViewTable/DataViewTable.d.ts +6 -1
  31. package/dist/esm/DataViewTable/DataViewTable.js +21 -1
  32. package/dist/esm/DataViewTableBasic/DataViewTableBasic.d.ts +13 -0
  33. package/dist/esm/DataViewTableBasic/DataViewTableBasic.js +48 -8
  34. package/dist/esm/DataViewTableBasic/DataViewTableBasic.test.js +45 -10
  35. package/dist/esm/DataViewTableHead/DataViewTableHead.d.ts +2 -0
  36. package/dist/esm/DataViewTableHead/DataViewTableHead.js +5 -4
  37. package/dist/esm/DataViewTableTree/DataViewTableTree.d.ts +2 -0
  38. package/dist/esm/DataViewTableTree/DataViewTableTree.js +29 -2
  39. package/dist/esm/DataViewTableTree/DataViewTableTree.test.js +4 -0
  40. package/dist/esm/DataViewTh/DataViewTh.d.ts +32 -0
  41. package/dist/esm/DataViewTh/DataViewTh.js +215 -0
  42. package/dist/esm/DataViewTh/index.d.ts +2 -0
  43. package/dist/esm/DataViewTh/index.js +2 -0
  44. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.d.ts +26 -0
  45. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.js +225 -0
  46. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.d.ts +1 -0
  47. package/dist/esm/DataViewTreeFilter/DataViewTreeFilter.test.js +166 -0
  48. package/dist/esm/DataViewTreeFilter/index.d.ts +2 -0
  49. package/dist/esm/DataViewTreeFilter/index.js +2 -0
  50. package/dist/esm/Hooks/selection.d.ts +1 -0
  51. package/dist/esm/Hooks/selection.js +5 -1
  52. package/dist/esm/Hooks/selection.test.js +48 -0
  53. package/dist/esm/InternalContext/InternalContext.d.ts +2 -0
  54. package/dist/esm/index.d.ts +6 -0
  55. package/dist/esm/index.js +6 -0
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/generate-fed-package-json.js +18 -0
  58. package/generate-index.js +2 -2
  59. package/package.json +12 -12
  60. package/patternfly-docs/content/extensions/data-view/examples/DataView/DataView.md +10 -4
  61. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableExpandableExample.tsx +108 -0
  62. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableInteractiveExample.tsx +148 -0
  63. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableResizableColumnsExample.tsx +155 -0
  64. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableStickyExample.tsx +90 -0
  65. package/patternfly-docs/content/extensions/data-view/examples/Table/DataViewTableTreeExample.tsx +1 -0
  66. package/patternfly-docs/content/extensions/data-view/examples/Table/Table.md +113 -14
  67. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/SelectionExample.tsx +14 -3
  68. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md +10 -2
  69. package/patternfly-docs/content/extensions/data-view/examples/Toolbar/TreeFilterExample.tsx +248 -0
  70. package/patternfly-docs/patternfly-docs.config.js +4 -1
  71. package/release.config.js +1 -1
  72. package/src/DataViewCheckboxFilter/__snapshots__/DataViewCheckboxFilter.test.tsx.snap +0 -2
  73. package/src/DataViewFilters/__snapshots__/DataViewFilters.test.tsx.snap +0 -2
  74. package/src/DataViewTable/DataViewTable.tsx +51 -28
  75. package/src/DataViewTable/__snapshots__/DataViewTable.test.tsx.snap +17 -25
  76. package/src/DataViewTableBasic/DataViewTableBasic.test.tsx +54 -12
  77. package/src/DataViewTableBasic/DataViewTableBasic.tsx +104 -10
  78. package/src/DataViewTableBasic/__snapshots__/DataViewTableBasic.test.tsx.snap +30 -30
  79. package/src/DataViewTableHead/DataViewTableHead.tsx +24 -23
  80. package/src/DataViewTableHead/__snapshots__/DataViewTableHead.test.tsx.snap +15 -15
  81. package/src/DataViewTableTree/DataViewTableTree.test.tsx +9 -0
  82. package/src/DataViewTableTree/DataViewTableTree.tsx +35 -1
  83. package/src/DataViewTableTree/__snapshots__/DataViewTableTree.test.tsx.snap +977 -28
  84. package/src/DataViewTextFilter/__snapshots__/DataViewTextFilter.test.tsx.snap +0 -3
  85. package/src/DataViewTh/DataViewTh.tsx +342 -0
  86. package/src/DataViewTh/index.ts +2 -0
  87. package/src/DataViewToolbar/__snapshots__/DataViewToolbar.test.tsx.snap +0 -10
  88. package/src/DataViewTreeFilter/DataViewTreeFilter.test.tsx +222 -0
  89. package/src/DataViewTreeFilter/DataViewTreeFilter.tsx +361 -0
  90. package/src/DataViewTreeFilter/__snapshots__/DataViewTreeFilter.test.tsx.snap +199 -0
  91. package/src/DataViewTreeFilter/index.ts +2 -0
  92. package/src/Hooks/selection.test.tsx +65 -1
  93. package/src/Hooks/selection.ts +6 -1
  94. package/src/InternalContext/InternalContext.tsx +2 -0
  95. package/src/index.ts +9 -0
@@ -0,0 +1,155 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
3
+ import { Button } from '@patternfly/react-core';
4
+ import { ActionsColumn } from '@patternfly/react-table';
5
+
6
+ interface Repository {
7
+ id: number;
8
+ name: string;
9
+ branches: string | null;
10
+ prs: string | null;
11
+ workspaces: string;
12
+ lastCommit: string;
13
+ }
14
+
15
+ const repositories: Repository[] = [
16
+ {
17
+ id: 1,
18
+ name: 'Repository one',
19
+ branches: 'Branch one',
20
+ prs: 'Pull request one',
21
+ workspaces: 'Workspace one',
22
+ lastCommit: 'Timestamp one'
23
+ },
24
+ {
25
+ id: 2,
26
+ name: 'Repository two',
27
+ branches: 'Branch two',
28
+ prs: 'Pull request two',
29
+ workspaces: 'Workspace two',
30
+ lastCommit: 'Timestamp two'
31
+ },
32
+ {
33
+ id: 3,
34
+ name: 'Repository three',
35
+ branches: 'Branch three',
36
+ prs: 'Pull request three',
37
+ workspaces: 'Workspace three',
38
+ lastCommit: 'Timestamp three'
39
+ },
40
+ {
41
+ id: 4,
42
+ name: 'Repository four',
43
+ branches: 'Branch four',
44
+ prs: 'Pull request four',
45
+ workspaces: 'Workspace four',
46
+ lastCommit: 'Timestamp four'
47
+ },
48
+ {
49
+ id: 5,
50
+ name: 'Repository five',
51
+ branches: 'Branch five',
52
+ prs: 'Pull request five',
53
+ workspaces: 'Workspace five',
54
+ lastCommit: 'Timestamp five'
55
+ },
56
+ {
57
+ id: 6,
58
+ name: 'Repository six',
59
+ branches: 'Branch six',
60
+ prs: 'Pull request six',
61
+ workspaces: 'Workspace six',
62
+ lastCommit: 'Timestamp six'
63
+ }
64
+ ];
65
+
66
+ const rowActions = [
67
+ {
68
+ title: 'Some action',
69
+ onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
70
+ },
71
+ {
72
+ title: <div>Another action</div>,
73
+ onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
74
+ },
75
+ {
76
+ isSeparator: true
77
+ },
78
+ {
79
+ title: 'Third action',
80
+ onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
81
+ }
82
+ ];
83
+
84
+ // you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
85
+ const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
86
+ { id, cell: workspaces, props: { favorites: { isFavorited: true } } },
87
+ {
88
+ cell: (
89
+ <Button href="#" variant="link" isInline>
90
+ {name}
91
+ </Button>
92
+ )
93
+ },
94
+ branches,
95
+ prs,
96
+ workspaces,
97
+ lastCommit,
98
+ { cell: <ActionsColumn items={rowActions} />, props: { isActionCell: true } }
99
+ ]);
100
+
101
+ const ouiaId = 'TableExample';
102
+
103
+ export const ResizableColumnsExample: FunctionComponent = () => {
104
+ const onResize = (
105
+ _e: React.MouseEvent | MouseEvent | React.KeyboardEvent | KeyboardEvent | TouchEvent,
106
+ id: string | number | undefined,
107
+ width: number
108
+ ) => {
109
+ // eslint-disable-next-line no-console
110
+ console.log(`resized column id: ${id} width to: ${width.toFixed(0)}px`);
111
+ };
112
+
113
+ const columns: DataViewTh[] = [
114
+ null,
115
+ 'Repositories',
116
+ {
117
+ cell: 'Branches',
118
+ resizableProps: {
119
+ isResizable: true,
120
+ onResize,
121
+ resizeButtonAriaLabel: 'Resize repositories column'
122
+ },
123
+ props: { id: 'repositories' }
124
+ },
125
+ {
126
+ cell: 'Pull requests',
127
+ resizableProps: {
128
+ isResizable: true,
129
+ onResize,
130
+ resizeButtonAriaLabel: 'Resize pull requests column'
131
+ },
132
+ props: { info: { tooltip: 'More information' }, id: 'pull-requests' }
133
+ },
134
+ {
135
+ cell: 'This is a really long title',
136
+ resizableProps: {
137
+ isResizable: true,
138
+ onResize,
139
+ resizeButtonAriaLabel: 'Resize this is a really long title column'
140
+ },
141
+ props: { info: { tooltip: 'More information' }, id: 'this-is-a-really-long-title' }
142
+ },
143
+ {
144
+ cell: 'Last commit',
145
+ resizableProps: {
146
+ isResizable: true,
147
+ onResize,
148
+ resizeButtonAriaLabel: 'Resize last commit column'
149
+ },
150
+ props: { sort: { sortBy: {}, columnIndex: 4 }, id: 'last-commit' }
151
+ }
152
+ ];
153
+
154
+ return <DataViewTable isResizable aria-label="Repositories table" ouiaId={ouiaId} columns={columns} rows={rows} />;
155
+ };
@@ -0,0 +1,90 @@
1
+ import { FunctionComponent } from 'react';
2
+ import { DataViewTable, DataViewTr, DataViewTh } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
3
+ import { ExclamationCircleIcon } from '@patternfly/react-icons';
4
+ import { Button } from '@patternfly/react-core';
5
+ import { ActionsColumn } from '@patternfly/react-table';
6
+
7
+ interface Repository {
8
+ id: number;
9
+ name: string;
10
+ branches: string | null;
11
+ prs: string | null;
12
+ workspaces: string;
13
+ lastCommit: string;
14
+ contributors: string;
15
+ stars: string;
16
+ forks: string;
17
+ }
18
+
19
+ const repositories: Repository[] = [
20
+ { id: 1, name: 'Repository one', branches: 'Branch one', prs: 'Pull request one', workspaces: 'Workspace one', lastCommit: 'Timestamp one', contributors: '25 contributors', stars: '1.2k stars', forks: '340 forks' },
21
+ { id: 2, name: 'Repository two', branches: 'Branch two', prs: 'Pull request two', workspaces: 'Workspace two', lastCommit: 'Timestamp two', contributors: '45 contributors', stars: '3.5k stars', forks: '890 forks' },
22
+ { id: 3, name: 'Repository three', branches: 'Branch three', prs: 'Pull request three', workspaces: 'Workspace three', lastCommit: 'Timestamp three', contributors: '200 contributors', stars: '15k stars', forks: '2.1k forks' },
23
+ { id: 4, name: 'Repository four', branches: 'Branch four', prs: 'Pull request four', workspaces: 'Workspace four', lastCommit: 'Timestamp four', contributors: '80 contributors', stars: '5.7k stars', forks: '1.2k forks' },
24
+ { id: 5, name: 'Repository five', branches: 'Branch five', prs: 'Pull request five', workspaces: 'Workspace five', lastCommit: 'Timestamp five', contributors: '60 contributors', stars: '4.3k stars', forks: '780 forks' },
25
+ { id: 6, name: 'Repository six', branches: 'Branch six', prs: 'Pull request six', workspaces: 'Workspace six', lastCommit: 'Timestamp six', contributors: '300 contributors', stars: '22k stars', forks: '4.5k forks' },
26
+ { id: 7, name: 'Repository seven', branches: 'Branch seven', prs: 'Pull request seven', workspaces: 'Workspace seven', lastCommit: 'Timestamp seven', contributors: '12 contributors', stars: '567 stars', forks: '120 forks' },
27
+ { id: 8, name: 'Repository eight', branches: 'Branch eight', prs: 'Pull request eight', workspaces: 'Workspace eight', lastCommit: 'Timestamp eight', contributors: '98 contributors', stars: '7.8k stars', forks: '1.5k forks' },
28
+ { id: 9, name: 'Repository nine', branches: 'Branch nine', prs: 'Pull request nine', workspaces: 'Workspace nine', lastCommit: 'Timestamp nine', contributors: '33 contributors', stars: '2.1k stars', forks: '456 forks' },
29
+ { id: 10, name: 'Repository ten', branches: 'Branch ten', prs: 'Pull request ten', workspaces: 'Workspace ten', lastCommit: 'Timestamp ten', contributors: '150 contributors', stars: '11k stars', forks: '2.8k forks' },
30
+ { id: 11, name: 'Repository eleven', branches: 'Branch eleven', prs: 'Pull request eleven', workspaces: 'Workspace eleven', lastCommit: 'Timestamp eleven', contributors: '67 contributors', stars: '5.2k stars', forks: '980 forks' },
31
+ { id: 12, name: 'Repository twelve', branches: 'Branch twelve', prs: 'Pull request twelve', workspaces: 'Workspace twelve', lastCommit: 'Timestamp twelve', contributors: '41 contributors', stars: '3.1k stars', forks: '670 forks' }
32
+ ];
33
+
34
+ const rowActions = [
35
+ {
36
+ title: 'Some action',
37
+ onClick: () => console.log('clicked on Some action') // eslint-disable-line no-console
38
+ },
39
+ {
40
+ title: <div>Another action</div>,
41
+ onClick: () => console.log('clicked on Another action') // eslint-disable-line no-console
42
+ },
43
+ {
44
+ isSeparator: true
45
+ },
46
+ {
47
+ title: 'Third action',
48
+ onClick: () => console.log('clicked on Third action') // eslint-disable-line no-console
49
+ }
50
+ ];
51
+
52
+ const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit, contributors, stars, forks }) => [
53
+ { id, cell: workspaces, props: { favorites: { isFavorited: true } } },
54
+ { cell: <Button href='#' variant='link' isInline>{name}</Button>, props: { isStickyColumn: true, hasRightBorder: true, hasLeftBorder: true, modifier: "nowrap" } },
55
+ { cell: branches, props: { modifier: "nowrap" } },
56
+ { cell: prs, props: { modifier: "nowrap" } },
57
+ { cell: workspaces, props: { modifier: "nowrap" } },
58
+ { cell: lastCommit, props: { modifier: "nowrap" } },
59
+ { cell: contributors, props: { modifier: "nowrap" } },
60
+ { cell: stars, props: { modifier: "nowrap" } },
61
+ { cell: forks, props: { modifier: "nowrap" } },
62
+ { cell: <ActionsColumn items={rowActions}/>, props: { isActionCell: true } },
63
+ ]);
64
+
65
+ const columns: DataViewTh[] = [
66
+ null,
67
+ { cell: 'Repositories', props: { isStickyColumn: true, modifier: 'fitContent', hasRightBorder: true, hasLeftBorder: true } },
68
+ { cell: <>Branches<ExclamationCircleIcon className='pf-v6-u-ml-sm' color="var(--pf-t--global--color--status--danger--default)"/></>, props: { width: 20 } },
69
+ { cell: 'Pull requests', props: { width: 20 } },
70
+ { cell: 'Workspaces', props: { info: { tooltip: 'More information' }, width: 20 } },
71
+ { cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 }, width: 20 } },
72
+ { cell: 'Contributors', props: { width: 20 } },
73
+ { cell: 'Stars', props: { width: 20 } },
74
+ { cell: 'Forks', props: { width: 20 } },
75
+ null, // Actions column header
76
+ ];
77
+
78
+ const ouiaId = 'TableStickyExample';
79
+
80
+ export const StickyExample: FunctionComponent = () => (
81
+ <div style={{ height: '400px', width: '800px', overflow: 'auto' }}>
82
+ <DataViewTable
83
+ aria-label='Sticky repositories table'
84
+ ouiaId={ouiaId}
85
+ columns={columns}
86
+ rows={rows}
87
+ isSticky
88
+ />
89
+ </div>
90
+ );
@@ -4,6 +4,7 @@ import { DataViewTable, DataViewTh, DataViewTrTree } from '@patternfly/react-dat
4
4
  import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
5
5
  import { FolderIcon, FolderOpenIcon, LeafIcon } from '@patternfly/react-icons';
6
6
 
7
+
7
8
  interface Repository {
8
9
  name: string;
9
10
  branches: string | null;
@@ -12,10 +12,19 @@ source: react
12
12
  # If you use typescript, the name of the interface to display props for
13
13
  # These are found through the sourceProps function provided in patternfly-docs.source.js
14
14
  sortValue: 3
15
- propComponents: ['DataViewTableBasic', 'DataViewTableTree', 'DataViewTrTree', 'DataViewTrObject']
15
+ propComponents:
16
+ [
17
+ 'DataViewTableBasic',
18
+ 'DataViewTableTree',
19
+ 'DataViewTrTree',
20
+ 'DataViewTrObject',
21
+ 'DataViewTh',
22
+ 'DataViewThResizableProps'
23
+ ]
16
24
  sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Table/Table.md
17
25
  ---
18
- import { FunctionComponent, useMemo } from 'react';
26
+
27
+ import { FunctionComponent, useMemo, useState } from 'react';
19
28
  import { BrowserRouter, useSearchParams } from 'react-router-dom';
20
29
  import { Button, EmptyState, EmptyStateActions, EmptyStateBody, EmptyStateFooter } from '@patternfly/react-core';
21
30
  import { CubesIcon, FolderIcon, FolderOpenIcon, LeafIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
@@ -28,7 +37,9 @@ import { DataView, DataViewState } from '@patternfly/react-data-view/dist/dynami
28
37
  The **data view table** component renders your data into columns and rows within a [PatternFly table](/components/table) component. You can easily customize and configure the table with these additional [data view components and props](/extensions/data-view/table#props).
29
38
 
30
39
  ## Configuring rows and columns
40
+
31
41
  To define rows and columns for your table, use these props:
42
+
32
43
  - `columns`: Defines the column heads of the table. Each item in the array can be a `ReactNode` for simple heads, or an object with the following properties:
33
44
  - `cell`: Content to display in the column head.
34
45
  - `props` (optional): (`ThProps`) to pass to the `<Th>` component, such as `width`, `sort`, and other table head cell properties.
@@ -39,21 +50,102 @@ To define rows and columns for your table, use these props:
39
50
 
40
51
  It is also possible to disable row selection using the `isSelectDisabled` function, which can be passed to the wrapping `DataView` component through the `selection` prop.
41
52
 
53
+ If you want to have all expandable nodes open on initial load pass the `expandAll` prop to the DataViewTable component
54
+
42
55
  ### Table example
56
+
43
57
  ```js file="./DataViewTableExample.tsx"
44
58
 
45
59
  ```
46
60
 
61
+ ## Expandable rows
62
+
63
+ To add expandable content to table cells, pass an array of `ExpandableContent` objects to the `expandedRows` prop of the `<DataViewTable>` component. Each expandable content object defines which cell can be expanded and what content to display when expanded.
64
+
65
+ The `ExpandableContent` interface is defined as:
66
+
67
+ ```typescript
68
+ interface ExpandableContent {
69
+ /** The ID of the row containing the expandable cell (must match the id property in the row data) */
70
+ rowId: number;
71
+ /** The column index (0-based) that should be expandable */
72
+ columnId: number;
73
+ /** The content to display when the cell is expanded */
74
+ content: ReactNode;
75
+ }
76
+ ```
77
+
78
+ When a cell has expandable content:
79
+ - A compound expand toggle button appears in the cell
80
+ - Clicking the toggle expands the row to show the additional content below
81
+ - Only one expanded cell is shown per row at a time
82
+ - Clicking another expandable cell in the same row switches the expanded content
83
+
84
+ ### Expandable rows example
85
+
86
+ ```js file="./DataViewTableExpandableExample.tsx"
87
+
88
+ ```
89
+
90
+ ## Sticky header and columns
91
+
92
+ To enable sticky headers and columns, set the `isSticky` prop to `true` on the `<DataViewTable>` component. This keeps the table header and designated columns visible when scrolling.
93
+
94
+ To make specific columns sticky, add the `isStickyColumn` property to the column's `props` in the column definition:
95
+
96
+ ```typescript
97
+ const columns: DataViewTh[] = [
98
+ { cell: 'Column Name', props: { isStickyColumn: true } }
99
+ ];
100
+ ```
101
+
102
+ When sticky headers and columns are enabled:
103
+ - The table header remains visible when scrolling vertically
104
+ - Columns marked with `isStickyColumn: true` remain visible when scrolling horizontally
105
+ - The table is wrapped in `OuterScrollContainer` and `InnerScrollContainer` components to enable sticky behavior
106
+ - Sticky columns can have additional styling like borders using `hasRightBorder` or `hasLeftBorder` props
107
+
108
+ ### Sticky header and columns example
109
+
110
+ ```js file="./DataViewTableStickyExample.tsx"
111
+
112
+ ```
113
+
114
+ ### Interactive example
115
+ - Interactive example show how the different composable options work together.
116
+ - By toggling the toggles you can switch between them and observe the behaviour
117
+
118
+ ```js file="./DataViewTableInteractiveExample.tsx"
119
+
120
+ ```
121
+
122
+ ### Resizable columns
123
+
124
+ To allow a column to resize, add `isResizable` to the `DataViewTable` element, and pass `resizableProps` to each applicable header cell. The `resizableProps` object consists of the following fields:
125
+
126
+ - `isResizable` - indicates that the column is resizable
127
+ - `resizeButtonAriaLabel` - an accessible name for the resizable column's resize button. This must be passed in if the column is resizable.
128
+ - `onResize` - a callback that will return the source event and the new width of the column
129
+ - `width` - a default width value for a column
130
+ - `minWidth` - the minimum width a column may shrink to
131
+ - `increment` - how many pixels the column will move left or right for keyboard navigation
132
+ - `shiftIncrement` - how many pixels the column will move left or right while shift is held for keyboard navigation
133
+ - `screenReaderText` - text that will be announced when a column is resized
134
+
135
+ ```js file="./DataViewTableResizableColumnsExample.tsx"
136
+
137
+ ```
138
+
47
139
  ## Tree table
48
140
 
49
- A tree table includes expandable rows and custom icons for leaf and parent nodes.
141
+ A tree table includes expandable rows and custom icons for leaf and parent nodes.
50
142
  To enable a tree table, pass the `isTreeTable` flag to the `<DataViewTable>` component.
51
143
 
52
-
53
144
  Tree table rows have to be defined with following keys:
54
- - `row`: Defines the content for each cell in the row.
55
- - `id`: Unique identifier for the row that's used for matching selected items.
56
- - `children` (optional): Defines the children rows.
145
+
146
+ - `row`: Defines the content for each cell in the row.
147
+ - `id`: Unique identifier for the row that's used for matching selected items.
148
+ - `children` (optional): Defines the children rows.
57
149
 
58
150
  To update a row's icon to reflect its expansion state, pass `collapsedIcon`, `expandedIcon`, and `leafIcon` to `<DataViewTable>`.
59
151
 
@@ -66,17 +158,21 @@ To disable row selection, pass the `isSelectDisabled` function to `selection` pr
66
158
  ```
67
159
 
68
160
  ## Sorting
161
+
69
162
  The following example demonstrates how to enable sorting functionality within a data view. This implementation supports dynamic sorting by column and persists the sort state in the page's URL via [React Router](https://reactrouter.com/).
70
163
 
71
164
  ### Sorting example
165
+
72
166
  ```js file="./SortingExample.tsx"
73
167
 
74
168
  ```
169
+
75
170
  ### Sorting state
76
171
 
77
172
  The `useDataViewSort` hook manages the sorting state of a data view and provides an easy way to handle sorting logic, such as synchronization with URL parameters and the definition of default sorting behavior.
78
173
 
79
174
  **Initial values:**
175
+
80
176
  - `initialSort` object to set default `sortBy` and `direction` values:
81
177
  - `sortBy`: Key of the initial column to sort.
82
178
  - `direction`: Default sorting direction (`asc` or `desc`).
@@ -86,44 +182,47 @@ The `useDataViewSort` hook manages the sorting state of a data view and provides
86
182
  - Customizable parameter names for the URL:
87
183
  - `sortByParam`: Name of the URL parameter for the column key.
88
184
  - `directionParam`: Name of the URL parameter for the sorting direction.
89
- The `useDataViewSort` hook integrates seamlessly with [React Router](https://reactrouter.com/) to manage the sort state via URL parameters. Alternatively, you can use `URLSearchParams` and `window.history.pushState` APIs, or other routing libraries. If URL synchronization is not configured, the sort state is managed internally within the component.
185
+ The `useDataViewSort` hook integrates seamlessly with [React Router](https://reactrouter.com/) to manage the sort state via URL parameters. Alternatively, you can use `URLSearchParams` and `window.history.pushState` APIs, or other routing libraries. If URL synchronization is not configured, the sort state is managed internally within the component.
90
186
 
91
187
  **Return values:**
188
+
92
189
  - `sortBy`: Key of the column currently being sorted.
93
190
  - `direction`: Current sorting direction (`asc` or `desc`).
94
191
  - `onSort`: Function to handle sorting changes programmatically or via user interaction.
95
192
 
96
193
  ## States
97
194
 
98
- The data view table allows you to react to the `activeState` of the data view (such as `empty`, `error`, `loading`). You can use the `headStates` and `bodyStates` props to define the table head and body for a given state.
195
+ The data view table allows you to react to the `activeState` of the data view (such as `empty`, `error`, `loading`). You can use the `headStates` and `bodyStates` props to define the table head and body for a given state.
99
196
 
100
197
  ### Empty
101
- When there is no data to render in the data view, you can instead display an empty state.
102
198
 
103
- You can create your empty state by passing a [PatternFly empty state](/components/empty-state) to the `empty` key of `headStates` or `bodyStates`.
199
+ When there is no data to render in the data view, you can instead display an empty state.
200
+
201
+ You can create your empty state by passing a [PatternFly empty state](/components/empty-state) to the `empty` key of `headStates` or `bodyStates`.
104
202
 
105
203
  ```js file="./DataViewTableEmptyExample.tsx"
106
204
 
107
205
  ```
108
206
 
109
207
  ### Error
208
+
110
209
  When there is a data connection or retrieval error, you can display an error state.
111
210
 
112
211
  The error state will be displayed when the data view `activeState` value is `error`.
113
212
 
114
- You can create your error state by passing either the [component groups extension's error state](/component-groups/error-state) or a [PatternFly empty state](/components/empty-state) to the `error` key of `headStates` or `bodyStates`.
213
+ You can create your error state by passing either the [component groups extension's error state](/extensions/component-groups/error-state) or a [PatternFly empty state](/components/empty-state) to the `error` key of `headStates` or `bodyStates`.
115
214
 
116
215
  ```js file="./DataViewTableErrorExample.tsx"
117
216
 
118
217
  ```
119
218
 
120
219
  ### Loading
220
+
121
221
  To indicate that data is loading, you can display a loading state.
122
222
 
123
223
  The loading state will be displayed when the data view `activeState` value is `loading`.
124
224
 
125
- You can create your loading state by passing either the [component groups extension's skeleton table](/component-groups/skeleton-table) or a customized [PatternFly empty state](/components/empty-state) to the `loading` key of `headStates` or `bodyStates`.
126
-
225
+ You can create your loading state by passing either the [component groups extension's skeleton table](/extensions/component-groups/skeleton-table) or a customized [PatternFly empty state](/components/empty-state) to the `loading` key of `headStates` or `bodyStates`.
127
226
 
128
227
  ```js file="./DataViewTableLoadingExample.tsx"
129
228
 
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useDataViewSelection } from '@patternfly/react-data-view/dist/dynamic/Hooks';
3
3
  import { BulkSelect, BulkSelectValue } from '@patternfly/react-component-groups/dist/dynamic/BulkSelect';
4
+ import { Button } from '@patternfly/react-core';
4
5
  import { DataView } from '@patternfly/react-data-view/dist/dynamic/DataView';
5
6
  import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
6
7
  import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
@@ -30,13 +31,18 @@ const ouiaId = 'LayoutExample';
30
31
 
31
32
  export const BasicExample: React.FunctionComponent = () => {
32
33
  const selection = useDataViewSelection({ matchOption: (a, b) => a[0] === b[0] });
33
- const { selected, onSelect } = selection;
34
+ const { selected, onSelect, setSelected } = selection;
34
35
 
35
36
  const handleBulkSelect = (value: BulkSelectValue) => {
36
37
  value === BulkSelectValue.none && onSelect(false);
37
38
  value === BulkSelectValue.all && onSelect(true, rows);
38
39
  };
39
40
 
41
+ // Example: Select first two rows programmatically using setSelected
42
+ const handleSelectFirstTwo = () => {
43
+ setSelected(rows.slice(0, 2));
44
+ };
45
+
40
46
  return (
41
47
  <DataView selection={selection}>
42
48
  <DataViewToolbar
@@ -49,9 +55,14 @@ export const BasicExample: React.FunctionComponent = () => {
49
55
  selectedCount={selected.length}
50
56
  onSelect={handleBulkSelect}
51
57
  />
52
- }
58
+ }
59
+ actions={
60
+ <Button variant="secondary" onClick={handleSelectFirstTwo}>
61
+ Select First Two
62
+ </Button>
63
+ }
53
64
  />
54
65
  <DataViewTable aria-label='Repositories table' ouiaId={ouiaId} columns={columns} rows={rows} />
55
66
  </DataView>
56
67
  );
57
- }
68
+ }
@@ -12,7 +12,7 @@ source: react
12
12
  # If you use typescript, the name of the interface to display props for
13
13
  # These are found through the sourceProps function provided in patternfly-docs.source.js
14
14
  sortValue: 2
15
- propComponents: ['DataViewToolbar', 'DataViewFilters', 'DataViewTextFilter', 'DataViewCheckboxFilter']
15
+ propComponents: ['DataViewToolbar', 'DataViewFilters', 'DataViewTextFilter', 'DataViewCheckboxFilter', 'DataViewTreeFilter']
16
16
  sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Toolbar/Toolbar.md
17
17
  ---
18
18
  import { useMemo, useState, useEffect } from 'react';
@@ -26,6 +26,7 @@ import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataView
26
26
  import { DataViewFilters } from '@patternfly/react-data-view/dist/dynamic/DataViewFilters';
27
27
  import { DataViewTextFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTextFilter';
28
28
  import { DataViewCheckboxFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewCheckboxFilter';
29
+ import { DataViewTreeFilter } from '@patternfly/react-data-view/dist/dynamic/DataViewTreeFilter';
29
30
 
30
31
  The **data view toolbar** component renders a default opinionated data view toolbar above or below the data section.
31
32
 
@@ -44,7 +45,7 @@ You can further customize toolbar interactions by referring to the additional do
44
45
  ```
45
46
 
46
47
  ## Toolbar actions
47
- 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](/component-groups/responsive-actions) which ensure the responsive behavior of multiple actions in 1 toolbar.
48
+ 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](/extensions/component-groups/responsive-actions) which ensure the responsive behavior of multiple actions in 1 toolbar.
48
49
 
49
50
  ### Actions example
50
51
 
@@ -105,6 +106,7 @@ The `useDataViewSelection` hook manages the selection state of the data view.
105
106
  - `selected` array of currently selected records.
106
107
  - `isSelected` function returning the selection state for the record.
107
108
  - `onSelect` callback to modify the selection state. This accepts the `isSelecting` flag (indicates if records are being selected or deselected) and `items` (affected records).
109
+ - `setSelected` function to directly set the selected items array. This is useful for programmatically setting a specific selection state without needing to use the `onSelect` callback.
108
110
 
109
111
  ### Selection example
110
112
 
@@ -142,6 +144,12 @@ This example demonstrates the setup and usage of filters within the data view. I
142
144
 
143
145
  ```
144
146
 
147
+ ### Tree filter example
148
+ This example demonstrates the usage of a tree filter with hierarchical data. The tree filter allows users to select items from a nested structure, making it ideal for categorized or grouped filtering options.
149
+
150
+ ```js file="./TreeFilterExample.tsx"
151
+
152
+ ```
145
153
 
146
154
  ## All/selected data switch
147
155
  All/selected data switch allows users to toggle between displaying the entire table (All) and only the rows they have selected (Selected). If the user deselects the last selected row, the filter automatically switches back to All, displaying all table rows again. Until at least one row is selected, a tooltip with guidance is displayed, and the Selected button does not perform any action. The Selected button is intentionally not disabled for accessibility reasons but instead has `aria-disabled` set.