| 1 |
--- |
| 2 |
id: Table |
| 3 |
section: components |
| 4 |
--- |
| 5 |
|
| 6 |
import { Fragment, ReactNode, useEffect, useState } from 'react'; |
| 7 |
|
| 8 |
import { |
| 9 |
Checkbox, |
| 10 |
Content, |
| 11 |
Label, |
| 12 |
PageSection, |
| 13 |
ToolbarExpandIconWrapper, |
| 14 |
ToolbarContent, |
| 15 |
Toolbar, |
| 16 |
ToolbarItem, |
| 17 |
SearchInput, |
| 18 |
Masthead, |
| 19 |
MastheadToggle, |
| 20 |
MastheadBrand, |
| 21 |
MastheadContent, |
| 22 |
SkipToContent, |
| 23 |
Breadcrumb, |
| 24 |
BreadcrumbItem, |
| 25 |
Page, |
| 26 |
PageSectionVariants, |
| 27 |
Divider, |
| 28 |
Avatar, |
| 29 |
Brand, |
| 30 |
Button, |
| 31 |
ButtonVariant, |
| 32 |
Dropdown, |
| 33 |
DropdownGroup, |
| 34 |
DropdownItem, |
| 35 |
DropdownList, |
| 36 |
MastheadLogo, |
| 37 |
MenuToggle, |
| 38 |
ToolbarGroup, |
| 39 |
PageToggleButton, |
| 40 |
Nav, |
| 41 |
NavItem, |
| 42 |
NavList, |
| 43 |
PageSidebar, |
| 44 |
PageSidebarBody, |
| 45 |
Modal, |
| 46 |
ModalHeader, |
| 47 |
ModalBody, |
| 48 |
ModalFooter, |
| 49 |
} from '@patternfly/react-core'; |
| 50 |
import { DragDropSort } from '@patternfly/react-drag-drop'; |
| 51 |
import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon'; |
| 52 |
import CloneIcon from '@patternfly/react-icons/dist/esm/icons/clone-icon'; |
| 53 |
import RhUiCodeIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-code-icon'; |
| 54 |
import RhUiBranchFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-branch-fill-icon'; |
| 55 |
import CubeIcon from '@patternfly/react-icons/dist/esm/icons/cube-icon'; |
| 56 |
import EditIcon from '@patternfly/react-icons/dist/esm/icons/edit-icon'; |
| 57 |
import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon'; |
| 58 |
import RhMicronsSortDownLargeToSmallIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-sort-down-large-to-small-icon'; |
| 59 |
import SearchIcon from '@patternfly/react-icons/dist/esm/icons/search-icon'; |
| 60 |
import SyncIcon from '@patternfly/react-icons/dist/esm/icons/sync-icon'; |
| 61 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 62 |
import RhUiSettingsFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-settings-fill-icon'; |
| 63 |
import HelpIcon from '@patternfly/react-icons/dist/esm/icons/help-icon'; |
| 64 |
import RhUiQuestionMarkCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-question-mark-circle-fill-icon'; |
| 65 |
import RhMicronsCaretDownIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-down-icon'; |
| 66 |
import RhMicronsCaretRightIcon from '@patternfly/react-icons/dist/esm/icons/rh-microns-caret-right-icon'; |
| 67 |
import RhUiBlueprintIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-blueprint-icon'; |
| 68 |
import RhUiMenuBarsIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-menu-bars-icon'; |
| 69 |
import RhUiEllipsisVerticalFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-ellipsis-vertical-fill-icon'; |
| 70 |
import { DashboardWrapper } from '@patternfly/react-table/dist/esm/demos/DashboardWrapper'; |
| 71 |
import { rows, columns } from '@patternfly/react-table/dist/esm/demos/sampleData'; |
| 72 |
import spacing from '@patternfly/react-styles/css/utilities/Spacing/spacing'; |
| 73 |
import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon'; |
| 74 |
|
| 75 |
## Demos |
| 76 |
|
| 77 |
### Bulk select |
| 78 |
|
| 79 |
```ts isFullscreen file="examples/TableBulkSelect.tsx" |
| 80 |
|
| 81 |
``` |
| 82 |
|
| 83 |
### Expand/collapse all |
| 84 |
|
| 85 |
```ts isFullscreen file="examples/TableExpandCollapseAll.tsx" |
| 86 |
|
| 87 |
``` |
| 88 |
|
| 89 |
### Compact |
| 90 |
|
| 91 |
```ts isFullscreen file="examples/TableCompact.tsx" |
| 92 |
|
| 93 |
``` |
| 94 |
|
| 95 |
### Compound expansion |
| 96 |
|
| 97 |
```ts isFullscreen file="examples/TableCompoundExpansion.tsx" |
| 98 |
|
| 99 |
``` |
| 100 |
|
| 101 |
### Column management |
| 102 |
|
| 103 |
```ts isFullscreen file="examples/TableColumnManagement.tsx" |
| 104 |
|
| 105 |
``` |
| 106 |
|
| 107 |
### Column management with draggable |
| 108 |
|
| 109 |
```ts isFullscreen file="examples/TableColumnManagementWithDraggable.tsx" |
| 110 |
|
| 111 |
``` |
| 112 |
|
| 113 |
### Filterable |
| 114 |
|
| 115 |
```ts isFullscreen file="examples/TableFilterable.tsx" |
| 116 |
|
| 117 |
``` |
| 118 |
|
| 119 |
### Sortable - responsive |
| 120 |
|
| 121 |
```ts isFullscreen file="examples/TableSortableResponsive.tsx" |
| 122 |
|
| 123 |
``` |
| 124 |
|
| 125 |
### Automatic pagination |
| 126 |
|
| 127 |
The below example illustrates the `isLastFullPageShown` prop, which makes the following changes when the user sets the number of items to display per page to an amount that exceeds the remaining amount of data: |
| 128 |
|
| 129 |
- The component automatically changes the page back to the last full page of results, rather than defaulting to the final page of results. |
| 130 |
|
| 131 |
To demonstrate this, navigate to the last page of data below using the `>>` navigation arrows, then use the dropdown selector to change the view to 5 per page. |
| 132 |
|
| 133 |
- The default behavior would show the last page of results, which would only contain the last two rows (rows 11 - 12). |
| 134 |
- The `isLastFullPageShown` prop navigates you back to the previous page which does contain a full page of 5 rows (rows 6 - 10). |
| 135 |
|
| 136 |
```js isFullscreen file="./examples/TableAutomaticPagination.tsx" |
| 137 |
|
| 138 |
``` |
| 139 |
|
| 140 |
### Static bottom pagination on mobile |
| 141 |
|
| 142 |
```ts isFullscreen file="./examples/TableStaticBottomPagination.tsx" |
| 143 |
|
| 144 |
``` |
| 145 |
|
| 146 |
### Sticky header |
| 147 |
|
| 148 |
```js isFullscreen file="./examples/TableStickyHeader.tsx" |
| 149 |
|
| 150 |
``` |
| 151 |
|
| 152 |
### Sticky first column |
| 153 |
|
| 154 |
```js isFullscreen file="./examples/TableStickyFirstColumn.tsx" |
| 155 |
|
| 156 |
``` |
| 157 |
|
| 158 |
### Sticky columns and header with toolbar |
| 159 |
|
| 160 |
A toolbar may be added above a sticky table either inside or outside the `OuterScrollContainer`. |
| 161 |
|
| 162 |
```js isFullscreen file="../components/Table/examples/TableStickyColumnsAndHeader.tsx" |
| 163 |
|
| 164 |
``` |
| 165 |
|
| 166 |
## Empty states |
| 167 |
|
| 168 |
These examples demonstrate the use of an [Empty State component](/components/empty-state) inside of a [Table](/components/table). Empty states are useful in a table when a filter returns no results, while data is loading, or when any type of error or exception condition occurs. |
| 169 |
|
| 170 |
### Empty |
| 171 |
|
| 172 |
```js isFullscreen file="./examples/TableEmptyStateDefault.tsx" |
| 173 |
|
| 174 |
``` |
| 175 |
|
| 176 |
### Loading |
| 177 |
|
| 178 |
```js isFullscreen file="./examples/TableEmptyStateLoading.tsx" |
| 179 |
|
| 180 |
``` |
| 181 |
|
| 182 |
### Error |
| 183 |
|
| 184 |
```js isFullscreen file="./examples/TableEmptyStateError.tsx" |
| 185 |
|
| 186 |
``` |