Skip to content

Commit 9d29b3b

Browse files
authored
docs(AnalyticalTable): add feature examples subfolder (#8499)
1 parent d71742c commit 9d29b3b

6 files changed

Lines changed: 2368 additions & 425 deletions

File tree

.storybook/components/VersionSwitch.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ addons.register(ADDON_ID, () => {
6363
onClick={() => {
6464
setOpen(true);
6565
}}
66+
ariaLabel={false}
6667
>
6768
Version: {activeVersion}
6869
</IconButton>

packages/main/src/components/AnalyticalTable/docs/AnalyticalTable.mdx

Lines changed: 38 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ const TableComp = () => {
9999

100100
## Tree Table
101101

102+
Set `isTreeTable` to `true` and provide nested data via the `subRows` key (configurable with `subRowsKey`). Each row with `subRows` becomes expandable.
103+
102104
<Canvas of={ComponentStories.TreeTable} sourceState={'none'} />
103105

104106
The `data` structure of the tree table is as follows:
@@ -136,7 +138,7 @@ In this example the default key for sub row detection is used (`subRows`), you c
136138

137139
The table initially contains 50 rows, when the last 10 rows are reached the table will load more data.
138140

139-
**Note:** To prevent the table state from resetting when the data is updated, please see [this recipe](?path=/docs/data-display-analyticaltable-recipes--docs#how-to-stop-the-table-state-from-automatically-resetting-when-the-data-changes).
141+
**Note:** To prevent the table state from resetting when the data is updated, please see [this faq entry](?path=/docs/data-display-analyticaltable-faq--docs#how-to-stop-the-table-state-from-automatically-resetting-when-the-data-changes).
140142

141143
<Canvas sourceState="none" of={ComponentStories.InfiniteScrolling} />
142144

@@ -172,109 +174,31 @@ const InfiniteScrollTable = (props) => {
172174
header="Scroll to load more data"
173175
onLoadMore={onLoadMore}
174176
loading={loading}
175-
reactTableOptions: {{ autoResetSelectedRows: false }}
177+
reactTableOptions={{ autoResetSelectedRows: false }}
176178
/>
177179
);
178180
};
179181
```
180182

181183
</details>
182184

183-
## AnalyticalTable with subcomponents
184-
185-
Adding custom subcomponents below table rows can be achieved by setting the `renderRowSubComponent` prop.
186-
The prop expects a function with an optional parameter containing the `row` instance, there you can control which row should display subcomponents. If you want to display the subcomponent at the bottom of the row without an expandable container, you can set `subComponentsBehavior` prop to `"Visible"` or to `"IncludeHeight"`. "Visible" simply adds the subcomponent to the row without including its height in the initial calculation of the table body, whereas "IncludeHeight" does.
187-
188-
### Notes
189-
190-
- When `renderRowSubComponent` is set, `grouping` is disabled.
191-
- When rendering active elements inside the subcomponent, make sure to add the `data-subcomponent-active-element' attribute, otherwise focus behavior won't be consistent.
192-
- When `AnalyticalTableSubComponentsBehavior.IncludeHeight` or `AnalyticalTableSubComponentsBehavior.IncludeHeightExpandable` is used, `AnalyticalTableVisibleRowCountMode.Interactive` is not supported.
193-
194-
<ControlsWithNote of={ComponentStories.Subcomponents} include={['renderRowSubComponent', 'subComponentsBehavior']} />
195-
196-
<Canvas sourceState="none" of={ComponentStories.Subcomponents} />
197-
198-
### Code
199-
200-
<details>
201-
202-
<summary>Show Code</summary>
203-
204-
```jsx
205-
const TableWithSubcomponents = (props) => {
206-
const renderRowSubComponent = (row) => {
207-
if (row.id === '0') {
208-
return (
209-
<FlexBox
210-
style={{ backgroundColor: 'lightblue', height: '300px' }}
211-
justifyContent={FlexBoxJustifyContent.Center}
212-
alignItems={FlexBoxAlignItems.Center}
213-
direction={FlexBoxDirection.Column}
214-
>
215-
<Tag>height: 300px</Tag>
216-
<Text>This subcomponent will only be displayed below the first row.</Text>
217-
<hr />
218-
<Text>
219-
The button below is rendered with `data-subcomponent-active-element` attribute to ensure consistent focus
220-
behavior
221-
</Text>
222-
<Button data-subcomponent-active-element>Click</Button>
223-
</FlexBox>
224-
);
225-
}
226-
if (row.id === '1') {
227-
return (
228-
<FlexBox
229-
style={{ backgroundColor: 'lightyellow', height: '100px' }}
230-
justifyContent={FlexBoxJustifyContent.Center}
231-
alignItems={FlexBoxAlignItems.Center}
232-
direction={FlexBoxDirection.Column}
233-
>
234-
<Tag>height: 100px</Tag>
235-
<Text>This subcomponent will only be displayed below the second row.</Text>
236-
</FlexBox>
237-
);
238-
}
239-
if (row.id === '2') {
240-
return null;
241-
}
242-
return (
243-
<FlexBox
244-
style={{ backgroundColor: 'lightgrey', height: '50px' }}
245-
justifyContent={FlexBoxJustifyContent.Center}
246-
alignItems={FlexBoxAlignItems.Center}
247-
direction={FlexBoxDirection.Column}
248-
>
249-
<Tag>height: 50px</Tag>
250-
<Text>This subcomponent will be displayed below all rows except the first, second and third.</Text>
251-
</FlexBox>
252-
);
253-
};
254-
return (
255-
<AnalyticalTable
256-
data={props.data}
257-
columns={props.columns}
258-
renderRowSubComponent={renderRowSubComponent}
259-
subComponentsBehavior={AnalyticalTableSubComponentsBehavior.Expandable} //default value
260-
/>
261-
);
262-
};
263-
```
185+
## Auto Row Count
264186

265-
</details>
187+
Set `visibleRowCountMode` to `AnalyticalTableVisibleRowCountMode.Auto` or `AutoWithEmptyRows` to let the table automatically fill its container with rows.
266188

267-
## Adjust the number of rows to the container height
189+
**Prerequisites:**
268190

269-
By adding the `visibleRowCountMode` prop and setting it to `AnalyticalTableVisibleRowCountMode.Auto` the table automatically fills the surrounding container with rows and when setting it to `AnalyticalTableVisibleRowCountMode.AutoWithEmptyRows`, empty rows fill the container as well, if not enough visible rows are available.
191+
- The table **must** be placed inside a container with a **defined height** (e.g. `height: 500px`, `flex: 1`, or a CSS Grid row). Without a constrained parent, the table cannot determine how many rows to render.
192+
- `AutoWithEmptyRows` fills remaining space with empty rows when there aren't enough data rows to fill the container.
193+
- `Auto` may lead to inconsistent table heights depending on the container — prefer `AutoWithEmptyRows` for a stable layout.
270194

271195
<ControlsWithNote
272-
of={ComponentStories.DynamicRowCount}
196+
of={ComponentStories.AutoRowCount}
273197
include={['containerHeight', 'visibleRowCountMode']}
274198
hideHTMLPropsNote
275199
/>
276200

277-
<Canvas sourceState="none" of={ComponentStories.DynamicRowCount} />
201+
<Canvas sourceState="none" of={ComponentStories.AutoRowCount} />
278202

279203
### Code
280204

@@ -294,10 +218,10 @@ const TableComponent = (props) => {
294218
};
295219
```
296220

297-
## Responsively display columns on small devices (Pop-In)
221+
## Responsive Columns (Pop-In)
298222

299223
<ControlsWithNote
300-
of={ComponentStories.ResponsiveColumns}
224+
of={ComponentStories.ResponsiveColumnsPopIn}
301225
hideHTMLPropsNote
302226
include={['adjustTableHeightOnPopIn', 'containerWidth']}
303227
/>
@@ -315,7 +239,7 @@ In the example below you can have a look at this behavior:
315239
- `600`: The content of the "Age" column is moved to the first column (`responsiveMinWidth: 601`) and receives a custom header.
316240
- `400`: The content of the "Friend Name" column is moved to the first column and the "Friend Age" column is hidden (`responsiveMinWidth: 401`). The "Friend Name" column also receives a custom header.
317241

318-
<Canvas sourceState="none" of={ComponentStories.ResponsiveColumns} />
242+
<Canvas sourceState="none" of={ComponentStories.ResponsiveColumnsPopIn} />
319243

320244
### Columns Config
321245

@@ -366,9 +290,9 @@ const COLUMNS = [
366290
Header: 'PopinDisplay Modes',
367291
responsivePopIn: true,
368292
responsiveMinWidth: 801,
369-
popinDisplay: popinDisplay, // possible values: "Block", "Inline", "WithoutHeader"
293+
popinDisplay: AnalyticalTablePopinDisplay.Block, // possible values: "Block", "Inline", "WithoutHeader"
370294
Cell: () => {
371-
return <Text maxLines={1}>Using popinDisplay: {popinDisplay}</Text>;
295+
return <Text maxLines={1}>Using popinDisplay: Block</Text>;
372296
}
373297
}
374298
];
@@ -410,118 +334,11 @@ const COLUMNS = [
410334
];
411335
```
412336

413-
## Display indicator for navigated rows
414-
415-
To display show the navigation column you need to set `withNavigationHighlight` to `true` and to mark a row as "navigated" the `markNavigatedRow` prop is required.
416-
With the `markNavigatedRow` callback it is possible to define when and how many navigation indicators should be shown.
417-
418-
Click on any of the rows in the example below to display the "navigated" indicator in the navigation-column.
419-
420-
<Canvas sourceState="none" of={ComponentStories.NavigationIndicator} />
421-
422-
### Code
423-
424-
```jsx
425-
export const TableWithNavigationIndicators = () => {
426-
const [selectedRow, setSelectedRow] = useState();
427-
const onRowSelect = (e) => {
428-
setSelectedRow(e.detail.row);
429-
};
430-
const markNavigatedRow = useCallback(
431-
(row) => {
432-
return selectedRow?.id === row.id;
433-
},
434-
[selectedRow]
435-
);
436-
return (
437-
<AnalyticalTable
438-
data={data}
439-
columns={columns}
440-
withNavigationHighlight
441-
selectionMode={selectionMode}
442-
markNavigatedRow={markNavigatedRow}
443-
onRowSelect={onRowSelect}
444-
/>
445-
);
446-
};
447-
```
448-
449-
## Custom column filtering
450-
451-
It is possible to define your own filter function and filter component on each column. For this you need to customize the column option `filter` or add a custom filter type to the `reactTableOptions.filterTypes` object (for a custom filter function) and the column option `Filter` (for a custom filter component).
452-
453-
Here you can find an example using a `MultiComboBox` with multiple values as filter.
454-
455-
<Canvas sourceState="none" of={ComponentStories.CustomFilter} />
456-
457-
### Code
458-
459-
<details>
460-
461-
<summary>Show static code</summary>
462-
463-
```jsx
464-
const filterFn = (rows, accessor, filterValue) => {
465-
if (filterValue.length > 0) {
466-
return rows.filter((row) => {
467-
const rowVal = row.values[accessor];
468-
if (filterValue.some((item) => rowVal.includes(item))) {
469-
return true;
470-
}
471-
return false;
472-
});
473-
}
474-
return rows;
475-
};
476-
const COLUMNS = [
477-
{
478-
Header: 'Name',
479-
accessor: 'name',
480-
// either define your filter function here or set is as `reactTableOption` and pass the key as string here (see below)
481-
filter: filterFn,
482-
Filter: ({ column }) => {
483-
const firstNames = ['Carl', 'Dan', 'Rose', 'Susanne'];
484-
return (
485-
<MultiComboBox
486-
onSelectionChange={(e) => {
487-
column.setFilter(e.detail.items.map((item) => item.getAttribute('text')));
488-
}}
489-
>
490-
{firstNames.map((item) => {
491-
const isSelected = column?.filterValue?.some((filterVal) => filterVal.includes(item));
492-
return <MultiComboBoxItem text={item} key={item} selected={isSelected} />;
493-
})}
494-
</MultiComboBox>
495-
);
496-
}
497-
},
498-
{
499-
Header: 'Age',
500-
accessor: 'age'
501-
}
502-
];
503-
const TableComponent = () => {
504-
return (
505-
<ThemeProvider>
506-
<AnalyticalTable
507-
columns={COLUMNS}
508-
data={DATA}
509-
filterable
510-
// you can also define your function here, then you can just pass the key as string to the `filter` column option
511-
// reactTableOptions={{
512-
// filterTypes: {
513-
// multiValueFilter: filterFn
514-
// }
515-
// }}
516-
/>
517-
</ThemeProvider>
518-
);
519-
};
520-
```
337+
## Table Without Data
521338

522-
</details>
339+
Use the `NoDataComponent` prop to customize the empty state. By default, a simple text message is shown. You can pass a custom component (e.g. an `IllustratedMessage`) to display a richer empty state for different scenarios like "no data" vs. "no filter results". The component receives an `accessibleRole` prop that should be forwarded for accessibility.
523340

524-
## Table Without Data
341+
**Note:** When using an `IllustratedMessage` as `NoDataComponent`, the table must have sufficient height for the illustration to render properly. With `visibleRowCountMode` set to `Auto` or `AutoWithEmptyRows`, the table container needs a minimum height of approximately `300px`. With the default `Fixed` mode, ensure `visibleRows` provides enough vertical space (typically 5+ rows).
525342

526343
<Canvas of={ComponentStories.NoData} />
527344

@@ -588,6 +405,8 @@ function NoDataTable(props) {
588405

589406
## Kitchen Sink
590407

408+
A comprehensive example combining many AnalyticalTable features: sorting, filtering, grouping, custom cells, row and navigation highlighting, infinite scrolling, column reordering, vertical alignment, `scaleWidthModeOptions` for custom renderers, `retainColumnWidth`, `sortDescFirst`, and more.
409+
591410
<Canvas of={ComponentStories.KitchenSink} />
592411

593412
### Code
@@ -634,12 +453,14 @@ const columns = [
634453
disableFilters: false,
635454
disableGroupBy: true,
636455
disableSortBy: false,
637-
hAlign: 'End'
456+
hAlign: 'End',
457+
sortDescFirst: true
638458
},
639459
{
640460
Header: 'Friend Name',
641461
accessor: 'friend.name',
642-
autoResizable: true
462+
autoResizable: true,
463+
vAlign: VerticalAlign.Middle
643464
},
644465
{
645466
Filter: () => {},
@@ -648,17 +469,26 @@ const columns = [
648469
autoResizable: true,
649470
filter: () => {},
650471
hAlign: 'End',
651-
headerLabel: 'Friend Age'
472+
headerLabel: 'Friend Age',
473+
scaleWidthModeOptions: { headerString: 'Friend Age' }
474+
},
475+
{
476+
Header: 'Status',
477+
id: 'os',
478+
Cell: () => {},
479+
scaleWidthModeOptions: { cellString: 'Negative' }
652480
},
653481
{
654482
Cell: () => {},
655483
Header: 'Actions',
656484
accessor: '.',
657485
cellLabel: () => {},
658486
disableFilters: true,
487+
disableGlobalFilter: true,
659488
disableGroupBy: true,
660489
disableResizing: true,
661490
disableSortBy: true,
491+
disableDragAndDrop: true,
662492
id: 'actions',
663493
minWidth: 100,
664494
width: 100
@@ -688,6 +518,7 @@ const TestComp2 = () => {
688518
minRows={5}
689519
noDataText="Custom 'noDataText' message"
690520
overscanCountHorizontal={5}
521+
retainColumnWidth
691522
scaleWidthMode="Smart"
692523
selectedRowIds={{
693524
3: true
@@ -698,6 +529,7 @@ const TestComp2 = () => {
698529
subRowsKey="subRows"
699530
visibleRowCountMode="Interactive"
700531
visibleRows={5}
532+
withNavigationHighlight
701533
withRowHighlight
702534
onAutoResize={() => {}}
703535
onColumnsReorder={() => {}}

0 commit comments

Comments
 (0)