material-react-table 0.3.3 → 0.4.1
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.
- package/dist/MaterialReactTable.d.ts +15 -7
- package/dist/body/MRT_TableBodyCell.d.ts +3 -0
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +4 -0
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +4 -0
- package/dist/head/MRT_TableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellActions.d.ts +5 -0
- package/dist/inputs/{MRT_EditCellTextfield.d.ts → MRT_EditCellTextField.d.ts} +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +604 -372
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +607 -375
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
- package/dist/menus/MRT_RowActionMenu.d.ts +1 -0
- package/dist/table/MRT_TableButtonCell.d.ts +3 -0
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +5 -0
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +5 -0
- package/dist/{useMaterialReactTable.d.ts → useMRT.d.ts} +8 -3
- package/dist/utils/localization.d.ts +8 -0
- package/package.json +21 -19
- package/src/@types/react-table-config.d.ts +37 -34
- package/src/MaterialReactTable.tsx +22 -6
- package/src/body/MRT_TableBody.tsx +2 -3
- package/src/body/MRT_TableBodyCell.tsx +8 -8
- package/src/body/MRT_TableBodyRow.tsx +13 -15
- package/src/body/MRT_TableDetailPanel.tsx +2 -2
- package/src/buttons/MRT_EditActionButtons.tsx +3 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +8 -16
- package/src/buttons/MRT_ExpandButton.tsx +8 -9
- package/src/buttons/MRT_FullScreenToggleButton.tsx +23 -0
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +34 -3
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -5
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +48 -26
- package/src/buttons/MRT_ToggleSearchButton.tsx +33 -0
- package/src/footer/MRT_TableFooter.tsx +2 -2
- package/src/footer/MRT_TableFooterCell.tsx +2 -2
- package/src/footer/MRT_TableFooterRow.tsx +9 -4
- package/src/head/MRT_TableHead.tsx +2 -2
- package/src/head/MRT_TableHeadCell.tsx +20 -16
- package/src/head/MRT_TableHeadCellActions.tsx +18 -0
- package/src/head/MRT_TableHeadRow.tsx +16 -11
- package/src/inputs/MRT_DensePaddingSwitch.tsx +5 -3
- package/src/inputs/{MRT_EditCellTextfield.tsx → MRT_EditCellTextField.tsx} +23 -16
- package/src/inputs/MRT_FilterTextField.tsx +43 -17
- package/src/inputs/MRT_SearchTextField.tsx +39 -34
- package/src/inputs/MRT_SelectAllCheckbox.tsx +9 -13
- package/src/inputs/MRT_SelectCheckbox.tsx +11 -14
- package/src/menus/MRT_ColumnActionMenu.tsx +66 -23
- package/src/menus/MRT_RowActionMenu.tsx +4 -8
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +24 -15
- package/src/table/MRT_Table.tsx +2 -2
- package/src/table/MRT_TableButtonCell.tsx +9 -0
- package/src/table/MRT_TableContainer.tsx +34 -8
- package/src/table/MRT_TableSpacerCell.tsx +2 -2
- package/src/toolbar/MRT_TablePagination.tsx +3 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +102 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +9 -5
- package/src/toolbar/{MRT_ToolbarButtons.tsx → MRT_ToolbarInternalButtons.tsx} +13 -4
- package/src/toolbar/MRT_ToolbarTop.tsx +14 -15
- package/src/{useMaterialReactTable.tsx → useMRT.tsx} +40 -23
- package/src/utils/localization.ts +22 -6
- package/dist/toolbar/MRT_ToolbarButtons.d.ts +0 -5
- package/dist/utils/useMRTCalcs.d.ts +0 -11
- package/src/utils/useMRTCalcs.tsx +0 -42
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
|
-
import { IconButton, InputAdornment, TextField } from '@mui/material';
|
|
2
|
+
import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
|
|
3
3
|
import CloseIcon from '@mui/icons-material/Close';
|
|
4
4
|
import FilterIcon from '@mui/icons-material/FilterList';
|
|
5
5
|
import { HeaderGroup, useAsyncDebounce } from 'react-table';
|
|
6
|
-
import {
|
|
6
|
+
import { useMRT } from '../useMRT';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
9
|
column: HeaderGroup;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const
|
|
13
|
-
const { localization } =
|
|
12
|
+
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
13
|
+
const { localization } = useMRT();
|
|
14
14
|
|
|
15
15
|
const [filterValue, setFilterValue] = useState('');
|
|
16
16
|
|
|
@@ -24,13 +24,23 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
if (column.Filter) {
|
|
27
|
-
return <>{column.Filter({ column })}</>;
|
|
27
|
+
return <>{column.Filter?.({ column })}</>;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
return (
|
|
31
31
|
<TextField
|
|
32
|
+
fullWidth
|
|
33
|
+
id={`filter-${column.id}-column`}
|
|
34
|
+
inputProps={{
|
|
35
|
+
style: {
|
|
36
|
+
textOverflow: 'ellipsis',
|
|
37
|
+
},
|
|
38
|
+
}}
|
|
32
39
|
margin="dense"
|
|
33
|
-
placeholder={localization?.filterTextFieldPlaceholder
|
|
40
|
+
placeholder={localization?.filterTextFieldPlaceholder?.replace(
|
|
41
|
+
'{column}',
|
|
42
|
+
String(column.Header),
|
|
43
|
+
)}
|
|
34
44
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
35
45
|
setFilterValue(e.target.value);
|
|
36
46
|
handleChange(e.target.value);
|
|
@@ -40,21 +50,37 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
|
|
|
40
50
|
variant="standard"
|
|
41
51
|
InputProps={{
|
|
42
52
|
startAdornment: (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
53
|
+
<Tooltip
|
|
54
|
+
arrow
|
|
55
|
+
title={
|
|
56
|
+
localization?.filterTextFieldPlaceholder?.replace(
|
|
57
|
+
'{column}',
|
|
58
|
+
String(column.Header),
|
|
59
|
+
) ?? ''
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
<InputAdornment position="start">
|
|
63
|
+
<FilterIcon />
|
|
64
|
+
</InputAdornment>
|
|
65
|
+
</Tooltip>
|
|
46
66
|
),
|
|
47
67
|
endAdornment: (
|
|
48
68
|
<InputAdornment position="end">
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
onClick={handleClear}
|
|
53
|
-
size="small"
|
|
54
|
-
title={localization?.filterTextFieldClearButtonTitle}
|
|
69
|
+
<Tooltip
|
|
70
|
+
arrow
|
|
71
|
+
title={localization?.filterTextFieldClearButtonTitle ?? ''}
|
|
55
72
|
>
|
|
56
|
-
<
|
|
57
|
-
|
|
73
|
+
<span>
|
|
74
|
+
<IconButton
|
|
75
|
+
aria-label={localization?.filterTextFieldClearButtonTitle}
|
|
76
|
+
disabled={filterValue?.length === 0}
|
|
77
|
+
onClick={handleClear}
|
|
78
|
+
size="small"
|
|
79
|
+
>
|
|
80
|
+
<CloseIcon fontSize="small" />
|
|
81
|
+
</IconButton>
|
|
82
|
+
</span>
|
|
83
|
+
</Tooltip>
|
|
58
84
|
</InputAdornment>
|
|
59
85
|
),
|
|
60
86
|
}}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Collapse,
|
|
3
4
|
IconButton,
|
|
4
5
|
InputAdornment,
|
|
5
6
|
styled,
|
|
@@ -7,7 +8,7 @@ import {
|
|
|
7
8
|
} from '@mui/material';
|
|
8
9
|
import SearchIcon from '@mui/icons-material/Search';
|
|
9
10
|
import CloseIcon from '@mui/icons-material/Close';
|
|
10
|
-
import {
|
|
11
|
+
import { useMRT } from '../useMRT';
|
|
11
12
|
import { useAsyncDebounce } from 'react-table';
|
|
12
13
|
|
|
13
14
|
const TextField = styled(MuiTextField)({
|
|
@@ -18,11 +19,12 @@ interface Props {}
|
|
|
18
19
|
|
|
19
20
|
export const MRT_SearchTextField: FC<Props> = () => {
|
|
20
21
|
const {
|
|
21
|
-
|
|
22
|
-
muiSearchTextFieldProps,
|
|
22
|
+
showSearch,
|
|
23
23
|
localization,
|
|
24
|
+
muiSearchTextFieldProps,
|
|
24
25
|
onGlobalFilterChange,
|
|
25
|
-
|
|
26
|
+
tableInstance,
|
|
27
|
+
} = useMRT();
|
|
26
28
|
|
|
27
29
|
const [searchValue, setSearchValue] = useState('');
|
|
28
30
|
|
|
@@ -40,35 +42,38 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
return (
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
45
|
+
<Collapse in={showSearch} orientation="horizontal">
|
|
46
|
+
<TextField
|
|
47
|
+
id="global-search-text-field"
|
|
48
|
+
placeholder={localization?.searchTextFieldPlaceholder}
|
|
49
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
50
|
+
setSearchValue(event.target.value);
|
|
51
|
+
handleChange(event);
|
|
52
|
+
}}
|
|
53
|
+
value={searchValue ?? ''}
|
|
54
|
+
variant="standard"
|
|
55
|
+
InputProps={{
|
|
56
|
+
startAdornment: (
|
|
57
|
+
<InputAdornment position="start">
|
|
58
|
+
<SearchIcon fontSize="small" />
|
|
59
|
+
</InputAdornment>
|
|
60
|
+
),
|
|
61
|
+
endAdornment: (
|
|
62
|
+
<InputAdornment position="end">
|
|
63
|
+
<IconButton
|
|
64
|
+
aria-label={localization?.searchTextFieldClearButtonTitle}
|
|
65
|
+
disabled={searchValue?.length === 0}
|
|
66
|
+
onClick={handleClear}
|
|
67
|
+
size="small"
|
|
68
|
+
title={localization?.searchTextFieldClearButtonTitle}
|
|
69
|
+
>
|
|
70
|
+
<CloseIcon fontSize="small" />
|
|
71
|
+
</IconButton>
|
|
72
|
+
</InputAdornment>
|
|
73
|
+
),
|
|
74
|
+
}}
|
|
75
|
+
{...muiSearchTextFieldProps}
|
|
76
|
+
/>
|
|
77
|
+
</Collapse>
|
|
73
78
|
);
|
|
74
79
|
};
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Checkbox
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const TableCell = styled(MuiTableCell, {
|
|
6
|
-
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
7
|
-
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
8
|
-
padding: densePadding ? '0' : '0.6rem',
|
|
9
|
-
transition: 'all 0.2s ease-in-out',
|
|
10
|
-
}));
|
|
2
|
+
import { Checkbox } from '@mui/material';
|
|
3
|
+
import { useMRT } from '../useMRT';
|
|
4
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
11
5
|
|
|
12
6
|
export const MRT_SelectAllCheckbox = () => {
|
|
13
7
|
const { tableInstance, disableSelectAll, densePadding, localization } =
|
|
14
|
-
|
|
8
|
+
useMRT();
|
|
15
9
|
|
|
16
10
|
return (
|
|
17
|
-
<
|
|
11
|
+
<MRT_TableButtonCell densePadding={densePadding} variant="head">
|
|
18
12
|
{!disableSelectAll ? (
|
|
19
13
|
<Checkbox
|
|
20
|
-
|
|
14
|
+
inputProps={{
|
|
15
|
+
'aria-label': localization?.selectAllCheckboxTitle ?? '',
|
|
16
|
+
}}
|
|
21
17
|
{...tableInstance.getToggleAllPageRowsSelectedProps()}
|
|
22
18
|
/>
|
|
23
19
|
) : null}
|
|
24
|
-
</
|
|
20
|
+
</MRT_TableButtonCell>
|
|
25
21
|
);
|
|
26
22
|
};
|
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
-
import { Checkbox
|
|
2
|
+
import { Checkbox } from '@mui/material';
|
|
3
3
|
import { Row } from 'react-table';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
const TableCell = styled(MuiTableCell, {
|
|
7
|
-
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
8
|
-
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
9
|
-
padding: densePadding ? '0' : '0.6rem',
|
|
10
|
-
transition: 'all 0.2s ease-in-out',
|
|
11
|
-
}));
|
|
4
|
+
import { useMRT } from '../useMRT';
|
|
5
|
+
import { MRT_TableButtonCell } from '../table/MRT_TableButtonCell';
|
|
12
6
|
|
|
13
7
|
interface Props {
|
|
14
8
|
row: Row;
|
|
15
9
|
}
|
|
16
10
|
|
|
17
11
|
export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
|
|
18
|
-
const { tableInstance, onRowSelectChange, densePadding } =
|
|
19
|
-
|
|
12
|
+
const { tableInstance, onRowSelectChange, densePadding, localization } =
|
|
13
|
+
useMRT();
|
|
20
14
|
|
|
21
15
|
const onSelectChange = (event: ChangeEvent) => {
|
|
22
16
|
row.getToggleRowSelectedProps()?.onChange?.(event);
|
|
@@ -24,11 +18,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row }) => {
|
|
|
24
18
|
};
|
|
25
19
|
|
|
26
20
|
return (
|
|
27
|
-
<
|
|
21
|
+
<MRT_TableButtonCell densePadding={densePadding}>
|
|
28
22
|
<Checkbox
|
|
29
|
-
{
|
|
23
|
+
inputProps={{
|
|
24
|
+
'aria-label': localization?.selectCheckboxTitle,
|
|
25
|
+
}}
|
|
30
26
|
onChange={onSelectChange}
|
|
27
|
+
{...row.getToggleRowSelectedProps()}
|
|
31
28
|
/>
|
|
32
|
-
</
|
|
29
|
+
</MRT_TableButtonCell>
|
|
33
30
|
);
|
|
34
31
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Divider, Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { useMRT } from '../useMRT';
|
|
4
|
+
import { HeaderGroup } from 'react-table';
|
|
5
5
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
6
6
|
import SortIcon from '@mui/icons-material/Sort';
|
|
7
7
|
import VisibilityOffIcon from '@mui/icons-material/VisibilityOff';
|
|
8
8
|
import DynamicFeedIcon from '@mui/icons-material/DynamicFeed';
|
|
9
|
+
import FilterIcon from '@mui/icons-material/FilterList';
|
|
9
10
|
|
|
10
11
|
const MenuItem = styled(MuiMenuItem)({
|
|
11
12
|
display: 'flex',
|
|
@@ -14,7 +15,7 @@ const MenuItem = styled(MuiMenuItem)({
|
|
|
14
15
|
|
|
15
16
|
interface Props {
|
|
16
17
|
anchorEl: HTMLElement | null;
|
|
17
|
-
column:
|
|
18
|
+
column: HeaderGroup;
|
|
18
19
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -25,10 +26,12 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
25
26
|
}) => {
|
|
26
27
|
const {
|
|
27
28
|
disableColumnHiding,
|
|
28
|
-
|
|
29
|
+
disableFilters,
|
|
29
30
|
disableSortBy,
|
|
31
|
+
enableColumnGrouping,
|
|
30
32
|
localization,
|
|
31
|
-
|
|
33
|
+
setShowFilters,
|
|
34
|
+
} = useMRT();
|
|
32
35
|
|
|
33
36
|
const handleClearSort = () => {
|
|
34
37
|
column.clearSortBy();
|
|
@@ -55,6 +58,22 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
55
58
|
setAnchorEl(null);
|
|
56
59
|
};
|
|
57
60
|
|
|
61
|
+
const handleFilterByColumn = () => {
|
|
62
|
+
setShowFilters(true);
|
|
63
|
+
setTimeout(
|
|
64
|
+
() =>
|
|
65
|
+
document
|
|
66
|
+
.getElementById(
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
column.muiTableHeadCellFilterTextFieldProps?.id ??
|
|
69
|
+
`filter-${column.id}-column`,
|
|
70
|
+
)
|
|
71
|
+
?.focus(),
|
|
72
|
+
200,
|
|
73
|
+
);
|
|
74
|
+
setAnchorEl(null);
|
|
75
|
+
};
|
|
76
|
+
|
|
58
77
|
return (
|
|
59
78
|
<Menu
|
|
60
79
|
anchorEl={anchorEl}
|
|
@@ -75,7 +94,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
75
94
|
disabled={column.isSorted && !column.isSortedDesc}
|
|
76
95
|
onClick={handleSortAsc}
|
|
77
96
|
>
|
|
78
|
-
<SortIcon />
|
|
97
|
+
<SortIcon />{' '}
|
|
98
|
+
{localization?.columnActionMenuItemSortAsc?.replace(
|
|
99
|
+
'{column}',
|
|
100
|
+
String(column.Header),
|
|
101
|
+
)}
|
|
79
102
|
</MenuItem>,
|
|
80
103
|
<MenuItem
|
|
81
104
|
key={3}
|
|
@@ -83,25 +106,45 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
83
106
|
onClick={handleSortDesc}
|
|
84
107
|
>
|
|
85
108
|
<SortIcon style={{ transform: 'rotate(180deg) scaleX(-1)' }} />{' '}
|
|
86
|
-
{localization?.columnActionMenuItemSortDesc
|
|
109
|
+
{localization?.columnActionMenuItemSortDesc?.replace(
|
|
110
|
+
'{column}',
|
|
111
|
+
String(column.Header),
|
|
112
|
+
)}
|
|
113
|
+
</MenuItem>,
|
|
114
|
+
]}
|
|
115
|
+
{!disableFilters &&
|
|
116
|
+
column.canFilter && [
|
|
117
|
+
<Divider key={0} />,
|
|
118
|
+
<MenuItem key={1} onClick={handleFilterByColumn}>
|
|
119
|
+
<FilterIcon />{' '}
|
|
120
|
+
{localization?.filterTextFieldPlaceholder?.replace(
|
|
121
|
+
'{column}',
|
|
122
|
+
String(column.Header),
|
|
123
|
+
)}
|
|
124
|
+
</MenuItem>,
|
|
125
|
+
]}
|
|
126
|
+
{enableColumnGrouping &&
|
|
127
|
+
column.canGroupBy && [
|
|
128
|
+
<Divider key={1} />,
|
|
129
|
+
<MenuItem key={2} onClick={handleGroupByColumn}>
|
|
130
|
+
<DynamicFeedIcon />{' '}
|
|
131
|
+
{localization?.[
|
|
132
|
+
column.isGrouped
|
|
133
|
+
? 'columnActionMenuItemUnGroupBy'
|
|
134
|
+
: 'columnActionMenuItemGroupBy'
|
|
135
|
+
]?.replace('{column}', String(column.Header))}
|
|
87
136
|
</MenuItem>,
|
|
88
|
-
<Divider key={4} />,
|
|
89
137
|
]}
|
|
90
|
-
{!disableColumnHiding &&
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
</MenuItem
|
|
99
|
-
|
|
100
|
-
{enableColumnGrouping && column.canGroupBy && (
|
|
101
|
-
<MenuItem disabled={!column.isGrouped} onClick={handleGroupByColumn}>
|
|
102
|
-
<DynamicFeedIcon /> {localization?.columnActionMenuItemUnGroupBy}
|
|
103
|
-
</MenuItem>
|
|
104
|
-
)}
|
|
138
|
+
{!disableColumnHiding && [
|
|
139
|
+
<Divider key={0} />,
|
|
140
|
+
<MenuItem key={1} onClick={handleHideColumn}>
|
|
141
|
+
<VisibilityOffIcon />{' '}
|
|
142
|
+
{localization?.columnActionMenuItemHideColumn?.replace(
|
|
143
|
+
'{column}',
|
|
144
|
+
String(column.Header),
|
|
145
|
+
)}
|
|
146
|
+
</MenuItem>,
|
|
147
|
+
]}
|
|
105
148
|
</Menu>
|
|
106
149
|
);
|
|
107
150
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Menu, MenuItem as MuiMenuItem, styled } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { useMRT } from '../useMRT';
|
|
4
4
|
import { Row } from 'react-table';
|
|
5
5
|
import EditIcon from '@mui/icons-material/Edit';
|
|
6
6
|
|
|
@@ -13,25 +13,21 @@ interface Props {
|
|
|
13
13
|
anchorEl: HTMLElement | null;
|
|
14
14
|
row: Row;
|
|
15
15
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
16
|
+
handleEdit: () => void;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export const MRT_RowActionMenu: FC<Props> = ({
|
|
19
20
|
anchorEl,
|
|
20
21
|
row,
|
|
22
|
+
handleEdit,
|
|
21
23
|
setAnchorEl,
|
|
22
24
|
}) => {
|
|
23
25
|
const {
|
|
24
26
|
enableRowEditing,
|
|
25
27
|
localization,
|
|
26
28
|
renderRowActionMenuItems,
|
|
27
|
-
setCurrentEditingRow,
|
|
28
29
|
tableInstance,
|
|
29
|
-
} =
|
|
30
|
-
|
|
31
|
-
const handleEdit = () => {
|
|
32
|
-
setCurrentEditingRow({ ...row });
|
|
33
|
-
setAnchorEl(null);
|
|
34
|
-
};
|
|
30
|
+
} = useMRT();
|
|
35
31
|
|
|
36
32
|
return (
|
|
37
33
|
<Menu
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import { FormControlLabel, MenuItem, Switch
|
|
3
|
-
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
2
|
+
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
4
3
|
import { ColumnInstance } from 'react-table';
|
|
5
4
|
|
|
6
5
|
interface Props {
|
|
@@ -8,23 +7,33 @@ interface Props {
|
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export const MRT_ShowHideColumnsMenu: FC<Props> = ({ column }) => {
|
|
11
|
-
const
|
|
10
|
+
const isParentHeader = (column?.columns?.length ?? 0) > 0;
|
|
12
11
|
|
|
13
|
-
const
|
|
12
|
+
const allChildColumnsVisible =
|
|
13
|
+
isParentHeader &&
|
|
14
|
+
!!column.columns?.every((childColumn) => childColumn.isVisible);
|
|
15
|
+
|
|
16
|
+
const switchChecked = column.isVisible ?? allChildColumnsVisible;
|
|
17
|
+
|
|
18
|
+
const handleToggleColumnHidden = (column: ColumnInstance) => {
|
|
19
|
+
if (isParentHeader) {
|
|
20
|
+
column?.columns?.forEach?.((childColumn) => {
|
|
21
|
+
childColumn.toggleHidden(switchChecked);
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
column.toggleHidden();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
14
27
|
|
|
15
28
|
return (
|
|
16
29
|
<>
|
|
17
|
-
<MenuItem style={{ paddingLeft: `${column.depth +
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/>
|
|
25
|
-
) : (
|
|
26
|
-
<Typography>{column.Header}</Typography>
|
|
27
|
-
)}
|
|
30
|
+
<MenuItem style={{ paddingLeft: `${(column.depth + 0.5) * 2}rem` }}>
|
|
31
|
+
<FormControlLabel
|
|
32
|
+
checked={switchChecked}
|
|
33
|
+
control={<Switch />}
|
|
34
|
+
label={column.Header as string}
|
|
35
|
+
onChange={() => handleToggleColumnHidden(column)}
|
|
36
|
+
/>
|
|
28
37
|
</MenuItem>
|
|
29
38
|
{column.columns?.map((c, i) => (
|
|
30
39
|
<MRT_ShowHideColumnsMenu key={`${i}-${c.id}`} column={c} />
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -3,13 +3,13 @@ import { Table } from '@mui/material';
|
|
|
3
3
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|
|
4
4
|
import { MRT_TableBody } from '../body/MRT_TableBody';
|
|
5
5
|
import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
|
6
|
-
import {
|
|
6
|
+
import { useMRT } from '../useMRT';
|
|
7
7
|
|
|
8
8
|
interface Props {}
|
|
9
9
|
|
|
10
10
|
export const MRT_Table: FC<Props> = () => {
|
|
11
11
|
const { tableInstance, muiTableProps, hideTableHead, hideTableFooter } =
|
|
12
|
-
|
|
12
|
+
useMRT();
|
|
13
13
|
|
|
14
14
|
const tableProps = {
|
|
15
15
|
...muiTableProps,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { styled, TableCell as MuiTableCell } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
export const MRT_TableButtonCell = styled(MuiTableCell, {
|
|
4
|
+
shouldForwardProp: (prop) => prop !== 'densePadding',
|
|
5
|
+
})<{ densePadding?: boolean }>(({ densePadding }) => ({
|
|
6
|
+
padding: densePadding ? '1px' : '0.6rem',
|
|
7
|
+
textAlign: 'center',
|
|
8
|
+
transition: 'all 0.2s ease-in-out',
|
|
9
|
+
}));
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
alpha,
|
|
4
3
|
CircularProgress,
|
|
5
4
|
LinearProgress,
|
|
6
5
|
Paper,
|
|
6
|
+
TableContainer as MuiTableContainer,
|
|
7
|
+
alpha,
|
|
7
8
|
styled,
|
|
8
|
-
TableContainer,
|
|
9
9
|
} from '@mui/material';
|
|
10
|
-
import {
|
|
10
|
+
import { useMRT } from '../useMRT';
|
|
11
11
|
import { MRT_Table } from './MRT_Table';
|
|
12
12
|
import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
|
|
13
13
|
import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
|
|
14
14
|
|
|
15
|
+
const TableContainer = styled(MuiTableContainer, {
|
|
16
|
+
shouldForwardProp: (prop) => prop !== 'fullScreen',
|
|
17
|
+
})<{ fullScreen?: boolean; component?: any }>(({ fullScreen }) => ({
|
|
18
|
+
bottom: fullScreen ? '0' : undefined,
|
|
19
|
+
height: fullScreen ? '100%' : undefined,
|
|
20
|
+
left: fullScreen ? '0' : undefined,
|
|
21
|
+
margin: fullScreen ? '0' : undefined,
|
|
22
|
+
position: fullScreen ? 'absolute' : undefined,
|
|
23
|
+
right: fullScreen ? '0' : undefined,
|
|
24
|
+
top: fullScreen ? '0' : undefined,
|
|
25
|
+
transition: 'all 0.2s ease-in-out',
|
|
26
|
+
width: fullScreen ? '100vw' : undefined,
|
|
27
|
+
zIndex: fullScreen ? 1200 : undefined,
|
|
28
|
+
}));
|
|
29
|
+
|
|
15
30
|
const CircularProgressWrapper = styled('div')(({ theme }) => ({
|
|
16
31
|
alignItems: 'center',
|
|
17
32
|
backgroundColor: alpha(theme.palette.background.paper, 0.5),
|
|
@@ -27,15 +42,26 @@ interface Props {}
|
|
|
27
42
|
|
|
28
43
|
export const MRT_TableContainer: FC<Props> = () => {
|
|
29
44
|
const {
|
|
30
|
-
|
|
31
|
-
hideToolbarTop,
|
|
45
|
+
fullScreen,
|
|
32
46
|
hideToolbarBottom,
|
|
33
|
-
|
|
47
|
+
hideToolbarTop,
|
|
34
48
|
isFetching,
|
|
35
|
-
|
|
49
|
+
isLoading,
|
|
50
|
+
muiTableContainerProps,
|
|
51
|
+
tableInstance,
|
|
52
|
+
} = useMRT();
|
|
53
|
+
|
|
54
|
+
const tableContainerProps =
|
|
55
|
+
muiTableContainerProps instanceof Function
|
|
56
|
+
? muiTableContainerProps(tableInstance)
|
|
57
|
+
: muiTableContainerProps;
|
|
36
58
|
|
|
37
59
|
return (
|
|
38
|
-
<TableContainer
|
|
60
|
+
<TableContainer
|
|
61
|
+
component={Paper}
|
|
62
|
+
fullScreen={fullScreen}
|
|
63
|
+
{...tableContainerProps}
|
|
64
|
+
>
|
|
39
65
|
{!hideToolbarTop && <MRT_ToolbarTop />}
|
|
40
66
|
{isFetching && <LinearProgress />}
|
|
41
67
|
{isLoading && (
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import React, { CSSProperties, FC } from 'react';
|
|
2
2
|
import { TableCell } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { useMRT } from '../useMRT';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
width?: CSSProperties['width'];
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export const MRT_TableSpacerCell: FC<Props> = ({ width }) => {
|
|
10
|
-
const { muiTableBodyCellProps } =
|
|
10
|
+
const { muiTableBodyCellProps } = useMRT();
|
|
11
11
|
|
|
12
12
|
const mTableBodyCellrops =
|
|
13
13
|
muiTableBodyCellProps instanceof Function
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC } from 'react';
|
|
2
2
|
import { TablePagination } from '@mui/material';
|
|
3
|
-
import {
|
|
3
|
+
import { useMRT } from '../useMRT';
|
|
4
4
|
|
|
5
5
|
interface Props {}
|
|
6
6
|
|
|
7
7
|
export const MRT_TablePagination: FC<Props> = () => {
|
|
8
|
-
const { tableInstance, muiTablePaginationProps } =
|
|
8
|
+
const { tableInstance, muiTablePaginationProps } = useMRT();
|
|
9
9
|
|
|
10
10
|
const tablePaginationProps =
|
|
11
11
|
muiTablePaginationProps instanceof Function
|
|
@@ -31,6 +31,7 @@ export const MRT_TablePagination: FC<Props> = () => {
|
|
|
31
31
|
showLastButton={
|
|
32
32
|
tableInstance.rows.length / tableInstance.state.pageSize > 2
|
|
33
33
|
}
|
|
34
|
+
style={{ padding: 0, position: 'relative', zIndex: 2 }}
|
|
34
35
|
{...tablePaginationProps}
|
|
35
36
|
/>
|
|
36
37
|
);
|