Skip to content

Commit 50f46b1

Browse files
committed
fix(docs): Update DataViewTable docs
1 parent db6f1a2 commit 50f46b1

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ propComponents: ['DataViewToolbar', 'DataViewTable']
1515
sourceLink: https://github.com/patternfly/react-data-view/blob/main/packages/module/patternfly-docs/content/extensions/data-view/examples/Components/Components.md
1616
---
1717
import { BulkSelect } from '@patternfly/react-component-groups';
18+
import { ExclamationCircleIcon } from '@patternfly/react-icons';
1819
import { DataViewToolbar } from '@patternfly/react-data-view/dist/dynamic/DataViewToolbar';
1920
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
2021

@@ -24,7 +25,7 @@ The **data view toolbar** component renders a default opinionated data view tool
2425

2526
Data view toolbar can contain a `pagination`, `bulkSelect` or any other children content passed. The preffered way of passing children toolbar items is using the [toolbar item](/components/toolbar#toolbar-items) component.
2627

27-
### Basic example
28+
### Basic toolbar example
2829

2930
```js file="./DataViewToolbarExample.tsx"
3031

@@ -34,7 +35,9 @@ Data view toolbar can contain a `pagination`, `bulkSelect` or any other children
3435

3536
The **data view table** component renders your columns and rows definition into a [table](/components/table) component.
3637

37-
### Basic example
38+
### Rows and columns customization
39+
40+
This example shows possible formats of `rows` and `columns` passed to the `DataViewTable` which allow you various customizations of the table header and body.
3841

3942
```js file="./DataViewTableExample.tsx"
4043

packages/module/patternfly-docs/content/extensions/data-view/examples/Components/DataViewTableExample.tsx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
2-
import { DataViewTable } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
2+
import { DataViewTable, DataViewTh, DataViewTr } from '@patternfly/react-data-view/dist/dynamic/DataViewTable';
3+
import { ExclamationCircleIcon } from '@patternfly/react-icons';
4+
import { Button } from '@patternfly/react-core';
35

46
interface Repository {
7+
id: number;
58
name: string;
69
branches: string | null;
710
prs: string | null;
@@ -10,17 +13,32 @@ interface Repository {
1013
}
1114

1215
const repositories: Repository[] = [
13-
{ name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
14-
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
15-
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
16-
{ name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
17-
{ name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
18-
{ name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
16+
{ id: 1, name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' },
17+
{ id: 2, name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' },
18+
{ id: 3, name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' },
19+
{ id: 4, name: 'one - 4', branches: 'two - 4', prs: 'null', workspaces: 'four - 4', lastCommit: 'five - 4' },
20+
{ id: 5, name: 'one - 5', branches: 'two - 5', prs: 'three - 5', workspaces: 'four - 5', lastCommit: 'five - 5' },
21+
{ id: 6, name: 'one - 6', branches: 'two - 6', prs: 'three - 6', workspaces: 'four - 6', lastCommit: 'five - 6' }
1922
];
2023

21-
const rows = repositories.map(item => Object.values(item));
24+
// you can also pass props to Tr by returning { row: DataViewTd[], props: TrProps } }
25+
const rows: DataViewTr[] = repositories.map(({ id, name, branches, prs, workspaces, lastCommit }) => [
26+
{ id, cell: workspaces, props: { favorites: { isFavorited: true } } },
27+
{ cell: <Button href='#' variant='link' isInline>{name}</Button> },
28+
branches,
29+
prs,
30+
workspaces,
31+
lastCommit
32+
]);
2233

23-
const columns = [ 'Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit' ];
34+
const columns: DataViewTh[] = [
35+
null,
36+
'Repositories',
37+
{ cell: <>Branches<ExclamationCircleIcon className='pf-v5-u-ml-sm' color='var(--pf-v5-global--danger-color--100)'/></> },
38+
'Pull requests',
39+
{ cell: 'Workspaces', props: { info: { tooltip: 'More information' } } },
40+
{ cell: 'Last commit', props: { sort: { sortBy: {}, columnIndex: 4 } } }
41+
];
2442

2543
const ouiaId = 'TableExample';
2644

0 commit comments

Comments
 (0)