Debian Codegraph @

node/@patternfly/react-table/src/deprecated/components/Table/examples/Table.md

raw
1 ---
2 id: Table
3 cssPrefix: pf-c-table
4 section: components
5 propComponents: ['Table', 'TableHeader', 'TableBody', 'ISortBy']
6 ouia: true
7 deprecated: true
8 ---
9
10 Note: Table lives in its own package at [@patternfly/react-table](https://www.npmjs.com/package/@patternfly/react-table)!
11
12 **This implementation of `Table` has been deprecated. It is no longer supported or maintained.**
13
14 This deprecated `Table` component is configuration-based and takes a less declarative and more implicit approach to laying out the table structure, such as the rows and cells within it.
15
16 import { Fragment, isValidElement, useCallback, useEffect, useRef, useState } from 'react';
17 import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon';
18 import RhUiCodeIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-code-icon';
19 import RhUiBranchFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-branch-fill-icon';
20 import CodeIcon from '@patternfly/react-icons/dist/esm/icons/code-icon';
21 import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon';
22 import LeafIcon from '@patternfly/react-icons/dist/esm/icons/leaf-icon';
23 import FolderIcon from '@patternfly/react-icons/dist/esm/icons/folder-icon';
24 import FolderOpenIcon from '@patternfly/react-icons/dist/esm/icons/folder-open-icon';
25 import RhMicronsSortDownLargeToSmallIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-sort-down-large-to-small-icon';
26 import {
27 Select as NewSelect,
28 SelectGroup as NewSelectGroup,
29 SelectList as NewSelectList,
30 SelectOption as NewSelectOption,
31 } from '@patternfly/react-core/dist/esm/components/Select';
32
33 import { css } from '@patternfly/react-styles';
34 import styles from '@patternfly/react-styles/css/components/Table/table';
35 import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing';
36 import t_global_color_brand_default from '@patternfly/react-tokens/dist/esm/t_global_color_brand_default';
37
38 ## Table Columns
39
40 Array items for columns provided to the `Table`'s `cells` prop, can be simple strings or objects.
41
42 ```
43 cells: (ICell | string)[];
44 ```
45
46 `ICell` (excerpt):
47
48 ```
49 interface ICell {
50 /* cell contents */
51 title?: React.ReactNode;
52 /** transformations applied to the header cell */
53 transforms?: ITransform[];
54 /** transformations applied to the cells within the column's body */
55 cellTransforms?: ITransform[];
56 /** transformations applied to the entire column */
57 columnTransforms?: ITransform[];
58 /** Additional header props, it contains the info prop as well which can be used to add tooltip/popover */
59 header?: HeaderType;
60 /** Additional props passed into the rendered column header element */
61 props?: any;
62 /** Text to display when data from this column is rendered in mobile view */
63 dataLabel?: string;
64 }
65 ```
66
67 If you wish to enable other built in features, use `transforms` to apply them to
68 column headers or `cellTransforms` to apply them to every cell in that column.
69
70 ```
71 // simple
72 columns: ['Repositories', 'Branches', 'Pull requests', 'Workspaces', 'Last commit']
73 // with tooltip
74 columns: [
75 {
76 title: 'Repositories',
77 transforms: [
78 info({
79 tooltip: 'More information about repositories'
80 })
81 ]
82 }
83 ]
84 // center header and body cells within the column
85 columns: [
86 {
87 title: 'Last commit',
88 transforms: [textCenter],
89 cellTransforms: [textCenter]
90 }
91 ]
92 ```
93
94 Many of the subsequent examples demonstrate how to apply different transformations to enable `Table` features.
95
96 ## Table Rows
97
98 Array items for rows provided to the `Table`'s `rows` prop, can be simple strings or objects.
99
100 ```
101 rows: (IRow | string[])[]
102 ```
103
104 `IRow` (excerpt):
105
106 ```
107 interface IRow extends RowType {
108 cells?: (React.ReactNode | IRowCell)[];
109 props?: any;
110 fullWidth?: boolean;
111 noPadding?: boolean;
112 }
113 interface IRowCell {
114 title?: React.ReactNode | RowCellContent;
115 props?: any;
116 formatters?: IFormatter[];
117 }
118 ```
119
120 ## Table examples
121
122 ### Basic
123
124 ```ts file="LegacyTableBasic.tsx"
125
126 ```
127
128 ### Custom row wrapper
129
130 Custom row wrappers are passed to the `Table` component via the `rowWrapper` prop.
131 Each `rowWrapper` should return a tr element.
132
133 ```
134 rowWrapper?: (props: RowWrapperProps) => JSX.Element;
135 ```
136
137 RowWrapperProps:
138
139 ```
140 interface RowWrapperProps {
141 trRef?: React.Ref<any> | Function;
142 className?: string;
143 onScroll?: React.UIEventHandler;
144 onResize?: React.UIEventHandler;
145 row?: IRow;
146 rowProps?: {
147 rowIndex: number;
148 rowKey: string;
149 };
150 children?: React.ReactNode;
151 ouiaId?: number | string;
152 }
153 ```
154
155 ```ts file="LegacyTableMisc.tsx"
156
157 ```
158
159 ### Sortable & wrapping column headers
160
161 To implement sortable columns:
162
163 1. Import and apply the `sortable` transform to the desired column.
164 2. Pass a managed `sortBy` prop to the `Table` component.
165 `` `sortBy` - Specifies the initial sorting pattern for the table - asc/desc and the index of the column to sort by ``
166 3. Pass an `onSort` callback to the `Table` component
167 `` `onSort` - (event: React.MouseEvent, columnIndex: number, sortByDirection: SortByDirection, extraData: IExtraColumnData) => void; ``
168
169 Note: If you want to add a tooltip/popover to a sortable header, in the `transforms` array the `info` transform has to precede the `sortable` transform.
170
171 The built in display for sorting is not fully responsive, as the column headers will be displayed per row when the screen size is small. The example below showcases how sorting may have a custom control display that can be used for small screen sizes.
172
173 ```ts file="LegacyTableSortable.tsx"
174
175 ```
176
177 ### Sortable - custom control
178
179 Sorting a table may also be controlled with a toolbar. This toolbar item may also be hidden at large screen sizes and only displayed when the screen size is small to support responsive tables.
180
181 ```ts file="LegacyTableSortableCustom.tsx"
182
183 ```
184
185 ### Selectable with checkbox
186
187 To enable row selection, set the `onSelect` callback prop on the Table.
188
189 To control whether a row is selected or not, the Table looks for `selected: true | falsy` on the row definition.
190
191 To disable selection for a row, set `disableSelection: true` on the row definition.
192
193 To include a 'select all' checkbox in the header row, pass `true` to the`canSelectAll` prop on the Table.
194
195 Note: this example also demonstrates the use of the `headerCol` transformation being applied to the first
196 column via the `cellTransforms` in the column definition. `headerCol` transforms the column so that instead
197 of using `td` elements, the cells in that column use `th` elements.
198
199 **Note:** This example has a `shift + select` feature where holding shift while
200 checking checkboxes will check intermediate rows' checkboxes.
201
202 ```ts file="LegacyTableSelectable.tsx"
203
204 ```
205
206 ### Selectable radio input
207
208 To enable row radio selection, set the `onSelect` callback prop on the Table, and set
209 `RowSelectVariant.radio` or `"radio"` as the `selectVariant` prop on the Table.
210
211 To disable selection for a row, set `disableSelection: true` on the row definition.
212
213 ```ts file="LegacyTableSelectableRadio.tsx"
214
215 ```
216
217 ### Clickable rows, selectable rows, and header cell tooltips/popovers
218
219 This selectable rows feature is intended for use when a table is used to present a list of objects in a Primary-detail view.
220
221 ```ts file="LegacyTableClickable.tsx"
222
223 ```
224
225 ### Actions and first cell in body rows as th
226
227 To use actions you can either specify an array of actions and pass that into the `Table`'s `actions` prop, or for more control you can use the `actionResolver` callback prop to add actions conditionally.
228
229 If actions menus are getting clipped by other items on the page, such as sticky columns or rows, the `Table` can be passed a `actionsMenuAppendTo` prop to adjust where the actions menu is appended.
230
231 ```ts file="LegacyTableActions.tsx"
232
233 ```
234
235 ### Expandable
236
237 To make an exapandable row, define a child row with the `parent` field set to its parent's row index.
238 The parent row can have an `isOpen` field for managing the expanded state of the parent row.
239
240 Also, pass an `onCollapse` event handler via the prop on the Table
241
242 ```ts file="LegacyTableExpandable.tsx"
243
244 ```
245
246 ### Compound expandable
247
248 To build a compound expandable table:
249
250 1. Pass the `compoundExpand` transformation via the `cellTransforms` field in the column definition for each column that will have an expanded section.
251 2. For each expandable parent row, the cells in the expandable columns should:
252 1. have a managed `isOpen` prop passed to the cell definition
253 2. have an `ariaControls` value which matches the `id` of it’s child row
254 3. For each expandable child row, the row definition needs:
255 1. A `parent` field set to its parent’s row index
256 2. A `compoundParent` field set to the cell index which will control the expanding/collapsing of this row
257 4. An `onExpand` event handler prop should be passed to the Table.
258
259 ```ts file="LegacyTableCompoundExpandable.tsx"
260
261 ```
262
263 ### With width and breakpoint visibility modifiers
264
265 ```ts file="LegacyTableCellWidth.tsx"
266
267 ```
268
269 ### Controlling text
270
271 ```ts file="LegacyTableControllingText.tsx"
272
273 ```
274
275 ### Modifiers with table text
276
277 ```ts file="LegacyTableTextModifiers.tsx"
278
279 ```
280
281 ### Empty state
282
283 ```ts file="LegacyTableEmptyState.tsx"
284
285 ```
286
287 ### Editable rows
288
289 To make a table row editable:
290
291 1. Pass a callback to Table via the `onRowEdit` prop.
292 2. Define the title for the editable cells using the RowCellContent type function.
293 3. Have the function return an `EditableTextCell`.
294 4. Pass the `value` and `name` of the cell's input to the `EditableTextCell` via the cell's `props` field, which is
295 defined as being of type `EditableTextCellProps`.
296
297 Example:
298
299 ```
300 {
301 title: (value, rowIndex, cellIndex, props) => (
302 <EditableTextCell
303 value={value}
304 rowIndex={rowIndex}
305 cellIndex={cellIndex}
306 props={props}
307 handleTextInputChange={this.handleTextInputChange}
308 inputAriaLabel="Row 1 cell 1 content"
309 />
310 ),
311 props: {
312 value: 'Row 1 cell 1 content',
313 name: 'uniqueIdRow1Cell1'
314 }
315 },
316 ```
317
318 ```js
319 import {
320 Table,
321 TableHeader,
322 TableBody,
323 TableVariant,
324 cancelCellEdits,
325 validateCellEdits,
326 applyCellEdits,
327 EditableTextCell,
328 EditableSelectInputCell,
329 } from '@patternfly/react-table';
330
331 import { SelectOption as NewSelectOption} from '@patternfly/react-core/dist/esm/components/Select';
332
333 class EditableRowsTable extends React.Component {
334 constructor(props) {
335 super(props);
336
337 this.state = {
338 columns: ['Text input col 1', 'Disabled text input col 2', 'Text input col 3', 'Text input col 4'],
339 actions: [
340 {
341 title: 'Some action',
342 onClick: (event, rowId, rowData, extra) => console.log('clicked on Some action, on row: ', rowId)
343 }
344 ],
345 rows: [
346 {
347 rowEditBtnAriaLabel: (idx) => `Edit row ${idx}`,
348 rowSaveBtnAriaLabel: (idx) => `Save edits for row ${idx}`,
349 rowCancelBtnAriaLabel: (idx) => `Cancel edits for row ${idx}`,
350 rowEditValidationRules: [
351 {
352 name: 'required',
353 validator: (value) => value.trim() !== '',
354 errorText: 'This field is required'
355 }
356 ],
357 cells: [
358 {
359 title: (value, rowIndex, cellIndex, props) => (
360 <EditableTextCell
361 value={value}
362 rowIndex={rowIndex}
363 cellIndex={cellIndex}
364 props={props}
365 handleTextInputChange={this.handleTextInputChange}
366 inputAriaLabel="Row 1 cell 1 content"
367 />
368 ),
369 props: {
370 value: 'Row 1 cell 1 content',
371 name: 'uniqueIdRow1Cell1'
372 }
373 },
374 {
375 title: (value, rowIndex, cellIndex, props) => (
376 <EditableTextCell
377 value={value}
378 rowIndex={rowIndex}
379 cellIndex={cellIndex}
380 props={props}
381 handleTextInputChange={this.handleTextInputChange}
382 isDisabled
383 inputAriaLabel="Row 1 cell 2 content"
384 />
385 ),
386 props: {
387 value: 'Row 1 cell 2, disabled content',
388 name: 'uniqueIdRow1Cell2'
389 }
390 },
391 {
392 title: (value, rowIndex, cellIndex, props) => (
393 <EditableTextCell
394 value={value}
395 rowIndex={rowIndex}
396 cellIndex={cellIndex}
397 props={props}
398 handleTextInputChange={this.handleTextInputChange}
399 inputAriaLabel="Row 1 cell 3 content"
400 />
401 ),
402 props: {
403 value: 'Row 1 cell 3 content',
404 name: 'uniqueIdRow1Cell3'
405 }
406 },
407 {
408 title: (value, rowIndex, cellIndex, props) => (
409 <EditableSelectInputCell
410 value={value}
411 rowIndex={rowIndex}
412 cellIndex={cellIndex}
413 props={props}
414 onSelect={this.onSelect}
415 isOpen={props.isSelectOpen}
416 options={props.options.map((option, index) => (
417 <NewSelectOption key={index} value={option.value} id={'uniqueIdRow1Cell4Option' + index}>
418 {option.value}
419 </NewSelectOption>
420 ))}
421 onToggle={(event) => {
422 this.onToggle(props.isSelectOpen, rowIndex, cellIndex);
423 }}
424 selections={props.selected}
425 />
426 ),
427 props: {
428 value: ['Option 1'],
429 name: 'uniqueIdRow1Cell4',
430 isSelectOpen: props.isSelectOpen || false,
431 selected: props.selected || ['Option 1'],
432 options: [
433 { value: 'Option 1' },
434 { value: 'Option 2' },
435 { value: 'Option 3' },
436 { value: 'Option 4' },
437 { value: 'Option 5' }
438 ],
439 editableSelectProps: {
440 'aria-label': 'Row 1 cell 4 content',
441 onOpenChange: (isOpen: boolean) => this.onOpenChange(isOpen, 0, 3)
442 }
443 }
444 }
445 ]
446 },
447 {
448 cells: [
449 {
450 title: (value, rowIndex, cellIndex, props) => (
451 <EditableTextCell
452 value={value}
453 rowIndex={rowIndex}
454 cellIndex={cellIndex}
455 props={props}
456 handleTextInputChange={this.handleTextInputChange}
457 inputAriaLabel="Row 2 cell 1 content"
458 />
459 ),
460 props: {
461 value: 'Row 2 cell 1 content',
462 name: 'uniqueIdRow2Cell1'
463 }
464 },
465 {
466 title: (value, rowIndex, cellIndex, props) => (
467 <EditableTextCell
468 value={value}
469 rowIndex={rowIndex}
470 cellIndex={cellIndex}
471 props={props}
472 handleTextInputChange={this.handleTextInputChange}
473 isDisabled
474 inputAriaLabel="Row 2 cell 2 content"
475 />
476 ),
477 props: {
478 value: 'Row 2 cell 2, disabled content',
479 name: 'uniqueIdRow2Cell2'
480 }
481 },
482 {
483 title: (value, rowIndex, cellIndex, props) => (
484 <EditableTextCell
485 value={value}
486 rowIndex={rowIndex}
487 cellIndex={cellIndex}
488 props={props}
489 handleTextInputChange={this.handleTextInputChange}
490 inputAriaLabel="Row 2 cell 3 content"
491 />
492 ),
493 props: {
494 value: 'Row 2 cell 3 content',
495 name: 'uniqueIdRow2Cell3'
496 }
497 },
498 {
499 title: (value, rowIndex, cellIndex, props) => (
500 <EditableSelectInputCell
501 value={value}
502 rowIndex={rowIndex}
503 cellIndex={cellIndex}
504 props={props}
505 onSelect={this.onSelect}
506 clearSelection={this.clearSelection}
507 isOpen={props.isSelectOpen}
508 options={props.options.map((option, index) => {
509 return (
510 <NewSelectOption key={index} value={option.value} id={'uniqueIdRow2Cell4Option' + index}>
511 {option.value}
512 </NewSelectOption>
513 );
514 })}
515 onToggle={(event) => {
516 this.onToggle(props.isSelectOpen, rowIndex, cellIndex);
517 }}
518 selections={props.selected}
519 />
520 ),
521 props: {
522 value: ['Placeholder...'],
523 name: 'uniqueIdRow2Cell4',
524 isSelectOpen: props.isSelectOpen || false,
525 selected: props.selected || [],
526 isPlaceholder: true,
527 options: [
528 { value: 'Placeholder...', isPlaceholder: true},
529 { value: 'Option 1' },
530 { value: 'Option 2' },
531 { value: 'Option 3' },
532 { value: 'Option 4' },
533 { value: 'Option 5' }
534 ],
535 editableSelectProps: {
536 'aria-label': 'Row 2 cell 4 content',
537 toggleId: 'editable-toggle',
538 onOpenChange: (isOpen: boolean) => this.onOpenChange(isOpen, 1, 3)
539
540 }
541 }
542 }
543 ]
544 },
545 {
546 rowEditValidationRules: [
547 {
548 name: 'required',
549 validator: (value) => value.trim() !== '',
550 errorText: 'This field is required'
551 },
552 {
553 name: 'notFoo',
554 validator: (value) => value.trim().toLowerCase() !== 'foo',
555 errorText: 'Value cannot be "foo"'
556 },
557 {
558 name: 'minLength',
559 validator: (value) => value.trim().length >= 7,
560 errorText: 'Value must be at least 7 characters'
561 },
562 {
563 name: 'notXyz',
564 validator: (value) => value.trim().toLowerCase() !== 'xyz',
565 errorText: 'Value cannot be xyz'
566 }
567 ],
568 cells: [
569 {
570 title: (value, rowIndex, cellIndex, props) => (
571 <EditableTextCell
572 value={value}
573 rowIndex={rowIndex}
574 cellIndex={cellIndex}
575 props={props}
576 handleTextInputChange={this.handleTextInputChange}
577 inputAriaLabel="Row 3 cell 1 content"
578 />
579 ),
580 props: {
581 value: 'Row 3 cell 1 content',
582 name: 'uniqueIdRow3Cell1'
583 }
584 },
585 {
586 title: (value, rowIndex, cellIndex, props) => (
587 <EditableTextCell
588 value={value}
589 rowIndex={rowIndex}
590 cellIndex={cellIndex}
591 props={props}
592 handleTextInputChange={this.handleTextInputChange}
593 isDisabled
594 inputAriaLabel="Row 3 cell 2 content"
595 />
596 ),
597 props: {
598 value: 'Row 3 cell 2, disabled content',
599 name: 'uniqueIdRow3Cell2'
600 }
601 },
602 {
603 title: (value, rowIndex, cellIndex, props) => (
604 <EditableTextCell
605 value={value}
606 rowIndex={rowIndex}
607 cellIndex={cellIndex}
608 props={props}
609 handleTextInputChange={this.handleTextInputChange}
610 inputAriaLabel="Row 3 cell 3 content"
611 />
612 ),
613 props: {
614 value: 'Row 3 cell 3 content',
615 name: 'uniqueIdRow3Cell3'
616 }
617 },
618 {
619 title: (value, rowIndex, cellIndex, props) => (
620 <EditableSelectInputCell
621 value={value}
622 rowIndex={rowIndex}
623 cellIndex={cellIndex}
624 props={props}
625 onSelect={this.onSelect}
626 clearSelection={this.clearSelection}
627 isOpen={props.isSelectOpen}
628 options={props.options.map((option, index) => (
629 <NewSelectOption key={index} value={option.value} id={'uniqueIdRow3Cell4Option' + index}>
630 {option.value}
631 </NewSelectOption>
632 ))}
633 onToggle={(event) => {
634 this.onToggle(props.isSelectOpen, rowIndex, cellIndex);
635 }}
636 selections={props.selected}
637 />
638 ),
639 props: {
640 value: ['Option 3'],
641 name: 'uniqueIdRow3Cell4',
642 isSelectOpen: props.isSelectOpen || false,
643 selected: props.selected || ['Option 3'],
644 isPlaceholder: false,
645 options: [
646 { value: 'Placeholder...', isPlaceholder: true},
647 { value: 'Option 1' },
648 { value: 'Option 2' },
649 { value: 'Option 3' },
650 { value: 'Option 4' },
651 { value: 'Option 5' }
652 ],
653 editableSelectProps: {
654 'aria-label': 'Row 3 cell 4 content',
655 onOpenChange: (isOpen: boolean) => this.onOpenChange(isOpen, 2, 3)
656
657 }
658 }
659 }
660 ]
661 }
662 ]
663 };
664
665 this.updateEditableRows = (evt, type, isEditable, rowIndex, validationErrors) => {
666 let newRows = Array.from(this.state.rows);
667
668 if (validationErrors && Object.keys(validationErrors).length) {
669 newRows[rowIndex] = validateCellEdits(newRows[rowIndex], type, validationErrors);
670 this.setState({ rows: newRows });
671 return;
672 }
673
674 if (type === 'cancel') {
675 newRows[rowIndex] = cancelCellEdits(newRows[rowIndex]);
676 this.setState({ rows: newRows });
677 return;
678 }
679
680 newRows[rowIndex] = applyCellEdits(newRows[rowIndex], type);
681
682 this.setState({ rows: newRows });
683 };
684
685 this.handleTextInputChange = (newValue, evt, rowIndex, cellIndex) => {
686 let newRows = Array.from(this.state.rows);
687 newRows[rowIndex].cells[cellIndex].props.editableValue = newValue;
688 this.setState({
689 rows: newRows
690 });
691 };
692
693 this.onSelect = (_event, newValue, rowIndex, cellIndex, isPlaceholder) => {
694 const newRows = Array.from(this.state.rows);
695 const newCellProps = newRows[rowIndex].cells[cellIndex].props;
696
697 if (isPlaceholder) {
698 newCellProps.editableValue = [];
699 newCellProps.selected = [];
700 } else {
701 if (newCellProps.editableValue === undefined) {
702 newCellProps.editableValue = [];
703 }
704
705 let newSelected = Array.from(newCellProps.selected);
706 let newSelectOpen = false;
707
708 switch (newCellProps.editableSelectProps.variant) {
709 case 'typeaheadmulti':
710 case 'checkbox': {
711 if (!newSelected.includes(newValue)) {
712 newSelected.push(newValue);
713 } else {
714 newSelected = newSelected.filter((el) => el !== newValue);
715 }
716 newSelectOpen = true;
717 break;
718 }
719 default: {
720 newSelected = newValue;
721 }
722 }
723
724 newCellProps.editableValue = newSelected;
725 newCellProps.selected = newSelected;
726 newCellProps.isSelectOpen = newSelectOpen;
727 }
728
729 this.setState({
730 rows: newRows
731 });
732 };
733
734 this.clearSelection = (_event, rowIndex, cellIndex) => {
735 const newRows = Array.from(this.state.rows);
736 const newCellProps = newRows[rowIndex].cells[cellIndex].props;
737 newCellProps.editableValue = [];
738 newCellProps.selected = [];
739 this.setState({
740 rows: newRows
741 });
742 };
743
744 // set open state if component closes menu on click (e.g. when you click outside of the menu)
745 this.onOpenChange = (isOpen: boolean, rowIndex: string | number | undefined, cellIndex: string | number | undefined) => {
746 const newRows = Array.from(this.state.rows);
747 newRows[rowIndex].cells[cellIndex].props.isSelectOpen = isOpen;
748 this.setState({
749 rows: newRows
750 });
751 }
752
753 this.onToggle = (isOpen, rowIndex, cellIndex) => {
754 console.log('isOpen', isOpen);
755 let newRows = Array.from(this.state.rows);
756 newRows[rowIndex].cells[cellIndex].props.isSelectOpen = !newRows[rowIndex].cells[cellIndex].props.isSelectOpen;
757 this.setState({
758 rows: newRows
759 });
760 };
761 }
762
763 render() {
764 const { columns, rows, actions } = this.state;
765
766 return (
767 <Table
768 actions={actions}
769 onRowEdit={this.updateEditableRows}
770 aria-label="Editable Rows Table"
771 variant={TableVariant.compact}
772 cells={columns}
773 rows={rows}
774 >
775 <TableHeader />
776 <TableBody />
777 </Table>
778 );
779 }
780 }
781 ```
782
783 ### Favoritable (implemented with sortable and selectable)
784
785 To enable favoriting of a row, set the `onFavorite` callback prop on the Table.
786
787 To control whether a row is favorited or not, the Table looks for `favorited: true | falsy` on the row definition.
788
789 When you also pass a sort callback through the `onSort` prop, favorites sorting is also enabled.
790
791 If you want to exclude favorites from sorting, set `canSortFavorites={false}` on the Table.
792
793 ```ts file="LegacyTableFavoritable.tsx"
794
795 ```
796
797 ### Tree table
798
799 To enable a tree table:
800
801 1. Pass the `isTreeTable` prop to the `Table` component
802 2. Pass the following props to each row:
803 - `isExpanded` - Flag indicating the node is expanded and its children are visible
804 - `isDetailsExpanded` - (optional) Flag indicating the row's details are visible in responsive view
805 - `isHidden` - Flag indicating the node's parent is expanded and this node is visible
806 - `aria-level` - number representing how many levels deep this node is nested
807 - `aria-posinset` - number representing where in the order this node sits amongst its siblings
808 - `aria-setsize` - number representing the number of children this node has
809 - `isChecked` - (optional) boolean used if this row uses checkboxes, flag indicating the checkbox checked
810 - `icon` - (optional) ReactNode icon to display before the row title
811 - `toggleAriaLabel` - (optional) accessible label for the expand/collapse children rows toggle arrow
812 - `checkAriaLabel` - (optional) accessible label for the checkbox
813 - `showDetailsAriaLabel` - (optional) accessible label for the show row details button in the responsive view
814 3. Use the `treeRow` cellTransform in the first column of the table. `treeRow` expects one or two callbacks as params.
815 - `onCollapse` - Callback when user expands/collapses a row to reveal/hide the row's children.
816 - `onCheckChange` - (optional) Callback when user changes the checkbox on a row.
817 - `onToggleRowDetails` - (optional) Callback when user shows/hides the row details in responsive view.
818
819 Note: If this table is going to be tested using axe-core, the tests will flag the use of aria-level,
820 aria-posinset, and aria-setsize as violations. This is an intentional choice at this time so that
821 the voice over technologies will recognize the flat table structure as a tree.
822
823 ```ts file="LegacyTableTree.tsx"
824
825 ```
826
827 ### Striped
828
829 To apply striping to a basic table, add the `isStriped` property to `Table`.
830
831 ```ts file="LegacyTableStriped.tsx"
832
833 ```
834
835 ### Striped expandable
836
837 To apply striping to an expandable table, add the `isStriped` and `isExpandable` properties to `Table`.
838
839 ```ts file="LegacyTableStripedExpandable.tsx"
840
841 ```
842
843 ### Striped custom tr
844
845 To manually control striping, use a custom row wrapper that applies the `pf-m-striped` css class for each desired row.
846
847 ```ts file="LegacyTableStripedCustomTr.tsx"
848
849 ```