material-react-table 0.7.0-alpha.9 → 0.7.2
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/README.md +3 -5
- package/dist/MaterialReactTable.d.ts +65 -46
- package/dist/buttons/{MRT_ToggleSearchButton.d.ts → MRT_ToggleGlobalFilterButton.d.ts} +1 -1
- package/dist/icons.d.ts +1 -0
- package/dist/localization.d.ts +4 -0
- package/dist/material-react-table.cjs.development.js +279 -187
- 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 +282 -190
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -2
- package/dist/utils.d.ts +5 -5
- package/package.json +5 -5
- package/src/MaterialReactTable.tsx +107 -57
- package/src/body/MRT_TableBodyCell.tsx +5 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -1
- package/src/buttons/MRT_FullScreenToggleButton.tsx +13 -4
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +0 -1
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +13 -4
- package/src/buttons/MRT_ToggleFiltersButton.tsx +13 -4
- package/src/buttons/{MRT_ToggleSearchButton.tsx → MRT_ToggleGlobalFilterButton.tsx} +14 -8
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +1 -1
- package/src/footer/MRT_TableFooterCell.tsx +3 -0
- package/src/head/MRT_TableHeadCell.tsx +60 -62
- package/src/head/MRT_TableHeadRow.tsx +12 -3
- package/src/icons.ts +3 -0
- package/src/inputs/MRT_EditCellTextField.tsx +2 -5
- package/src/inputs/MRT_FilterTextField.tsx +2 -2
- package/src/inputs/MRT_SearchTextField.tsx +6 -6
- package/src/localization.ts +8 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +29 -7
- package/src/menus/MRT_FilterTypeMenu.tsx +5 -8
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +7 -7
- package/src/table/MRT_Table.tsx +5 -5
- package/src/table/MRT_TableContainer.tsx +6 -7
- package/src/table/MRT_TablePaper.tsx +9 -13
- package/src/table/MRT_TableRoot.tsx +97 -83
- package/src/toolbar/MRT_ToolbarBottom.tsx +2 -2
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -9
- package/src/toolbar/MRT_ToolbarTop.tsx +2 -2
- package/src/utils.ts +15 -11
|
@@ -46,8 +46,11 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
46
46
|
0.05,
|
|
47
47
|
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
48
48
|
fontWeight: 'bold',
|
|
49
|
+
maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
|
|
50
|
+
minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
|
|
49
51
|
p: isDensePadding ? '0.5rem' : '1rem',
|
|
50
52
|
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
53
|
+
width: column.getWidth(),
|
|
51
54
|
verticalAlign: 'text-top',
|
|
52
55
|
//@ts-ignore
|
|
53
56
|
...tableCellProps?.sx,
|
|
@@ -30,8 +30,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
30
30
|
icons: { FilterAltIcon, FilterAltOff },
|
|
31
31
|
localization,
|
|
32
32
|
muiTableHeadCellProps,
|
|
33
|
-
setShowFilters,
|
|
34
33
|
},
|
|
34
|
+
setShowFilters,
|
|
35
35
|
} = tableInstance;
|
|
36
36
|
|
|
37
37
|
const { isDensePadding, showFilters } = getState();
|
|
@@ -56,9 +56,9 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
56
56
|
|
|
57
57
|
const sortTooltip = !!column.getIsSorted()
|
|
58
58
|
? column.getIsSorted() === 'desc'
|
|
59
|
-
? localization.
|
|
60
|
-
: localization.
|
|
61
|
-
: localization.
|
|
59
|
+
? localization.sortedByColumnDesc.replace('{column}', column.header)
|
|
60
|
+
: localization.sortedByColumnAsc.replace('{column}', column.header)
|
|
61
|
+
: localization.unsorted;
|
|
62
62
|
|
|
63
63
|
const filterType = getState()?.currentFilterTypes?.[header.id];
|
|
64
64
|
|
|
@@ -97,10 +97,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
97
97
|
theme.palette.common.white,
|
|
98
98
|
0.05,
|
|
99
99
|
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
100
|
-
boxShadow: `3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
101
100
|
fontWeight: 'bold',
|
|
102
101
|
height: '100%',
|
|
103
|
-
|
|
102
|
+
maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
|
|
103
|
+
minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
|
|
104
104
|
p: isDensePadding
|
|
105
105
|
? column.columnDefType === 'display'
|
|
106
106
|
? '0 0.5rem'
|
|
@@ -115,9 +115,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
115
115
|
? '0.75rem'
|
|
116
116
|
: '1.25rem',
|
|
117
117
|
pb: column.columnDefType === 'display' ? 0 : undefined,
|
|
118
|
+
overflow: 'visible',
|
|
118
119
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
119
120
|
verticalAlign: 'text-top',
|
|
120
121
|
width: header.getWidth(),
|
|
122
|
+
zIndex: column.getIsResizing() ? 2 : 1,
|
|
121
123
|
//@ts-ignore
|
|
122
124
|
...tableCellProps?.sx,
|
|
123
125
|
})}
|
|
@@ -135,7 +137,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
135
137
|
}}
|
|
136
138
|
>
|
|
137
139
|
<Box
|
|
138
|
-
{
|
|
140
|
+
onClick={() => column.toggleSorting()}
|
|
139
141
|
sx={{
|
|
140
142
|
alignItems: 'center',
|
|
141
143
|
cursor:
|
|
@@ -144,12 +146,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
144
146
|
: undefined,
|
|
145
147
|
display: 'flex',
|
|
146
148
|
flexWrap: 'nowrap',
|
|
147
|
-
whiteSpace: column.header.length <
|
|
149
|
+
whiteSpace: column.header.length < 24 ? 'nowrap' : 'normal',
|
|
148
150
|
}}
|
|
149
|
-
title={undefined}
|
|
150
151
|
>
|
|
151
152
|
{headerElement}
|
|
152
|
-
{column.columnDefType
|
|
153
|
+
{column.columnDefType === 'data' && column.getCanSort() && (
|
|
153
154
|
<Tooltip arrow placement="top" title={sortTooltip}>
|
|
154
155
|
<TableSortLabel
|
|
155
156
|
aria-label={sortTooltip}
|
|
@@ -162,7 +163,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
162
163
|
/>
|
|
163
164
|
</Tooltip>
|
|
164
165
|
)}
|
|
165
|
-
{column.columnDefType
|
|
166
|
+
{column.columnDefType === 'data' &&
|
|
166
167
|
enableColumnFilters &&
|
|
167
168
|
!!column.getCanColumnFilter() && (
|
|
168
169
|
<Tooltip arrow placement="top" title={filterTooltip}>
|
|
@@ -185,67 +186,64 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
185
186
|
}}
|
|
186
187
|
>
|
|
187
188
|
{showFilters && !column.getColumnFilterValue() ? (
|
|
188
|
-
<FilterAltOff
|
|
189
|
+
<FilterAltOff />
|
|
189
190
|
) : (
|
|
190
|
-
<FilterAltIcon
|
|
191
|
+
<FilterAltIcon />
|
|
191
192
|
)}
|
|
192
193
|
</IconButton>
|
|
193
194
|
</Tooltip>
|
|
194
195
|
)}
|
|
195
196
|
</Box>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
<MRT_ToggleColumnActionMenuButton
|
|
203
|
-
header={header}
|
|
204
|
-
tableInstance={tableInstance}
|
|
205
|
-
/>
|
|
206
|
-
)}
|
|
207
|
-
{enableColumnResizing && column.columnDefType !== 'group' && (
|
|
208
|
-
<Divider
|
|
209
|
-
flexItem
|
|
210
|
-
orientation="vertical"
|
|
211
|
-
onDoubleClick={() => header.resetSize()}
|
|
212
|
-
sx={(theme: Theme) => ({
|
|
213
|
-
borderRightWidth: '2px',
|
|
214
|
-
borderRadius: '2px',
|
|
215
|
-
maxHeight: '2rem',
|
|
216
|
-
cursor: 'col-resize',
|
|
217
|
-
userSelect: 'none',
|
|
218
|
-
touchAction: 'none',
|
|
219
|
-
'&:active': {
|
|
220
|
-
backgroundColor: theme.palette.secondary.dark,
|
|
221
|
-
opacity: 1,
|
|
222
|
-
},
|
|
223
|
-
})}
|
|
224
|
-
{...(header.getResizerProps((props: ColumnResizerProps) => ({
|
|
225
|
-
...props,
|
|
226
|
-
style: {
|
|
227
|
-
transform: column.getIsResizing()
|
|
228
|
-
? `translateX(${
|
|
229
|
-
getState().columnSizingInfo.deltaOffset
|
|
230
|
-
}px)`
|
|
231
|
-
: '',
|
|
232
|
-
},
|
|
233
|
-
})) as any)}
|
|
197
|
+
{(enableColumnActions || column.enableColumnActions) &&
|
|
198
|
+
column.enableColumnActions !== false &&
|
|
199
|
+
column.columnDefType !== 'group' && (
|
|
200
|
+
<MRT_ToggleColumnActionMenuButton
|
|
201
|
+
header={header}
|
|
202
|
+
tableInstance={tableInstance}
|
|
234
203
|
/>
|
|
235
204
|
)}
|
|
236
|
-
|
|
205
|
+
{column.getCanResize() && (
|
|
206
|
+
<Divider
|
|
207
|
+
flexItem
|
|
208
|
+
orientation="vertical"
|
|
209
|
+
onDoubleClick={() => header.resetSize()}
|
|
210
|
+
sx={(theme: Theme) => ({
|
|
211
|
+
borderRadius: '2px',
|
|
212
|
+
borderRightWidth: '2px',
|
|
213
|
+
cursor: 'col-resize',
|
|
214
|
+
height:
|
|
215
|
+
showFilters && column.columnDefType === 'data'
|
|
216
|
+
? '4rem'
|
|
217
|
+
: '2rem',
|
|
218
|
+
opacity: 0.8,
|
|
219
|
+
position: 'absolute',
|
|
220
|
+
right: '1px',
|
|
221
|
+
touchAction: 'none',
|
|
222
|
+
transition: 'all 0.2s ease-in-out',
|
|
223
|
+
userSelect: 'none',
|
|
224
|
+
zIndex: 2000,
|
|
225
|
+
'&:active': {
|
|
226
|
+
backgroundColor: theme.palette.info.main,
|
|
227
|
+
opacity: 1,
|
|
228
|
+
},
|
|
229
|
+
})}
|
|
230
|
+
{...(header.getResizerProps((props: ColumnResizerProps) => ({
|
|
231
|
+
...props,
|
|
232
|
+
style: {
|
|
233
|
+
transform: column.getIsResizing()
|
|
234
|
+
? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
|
|
235
|
+
: '',
|
|
236
|
+
},
|
|
237
|
+
})) as any)}
|
|
238
|
+
/>
|
|
239
|
+
)}
|
|
237
240
|
</Box>
|
|
238
241
|
)}
|
|
239
|
-
{column.columnDefType === 'data' &&
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
header={header}
|
|
245
|
-
tableInstance={tableInstance}
|
|
246
|
-
/>
|
|
247
|
-
</Collapse>
|
|
248
|
-
)}
|
|
242
|
+
{column.columnDefType === 'data' && column.getCanColumnFilter() && (
|
|
243
|
+
<Collapse in={showFilters}>
|
|
244
|
+
<MRT_FilterTextField header={header} tableInstance={tableInstance} />
|
|
245
|
+
</Collapse>
|
|
246
|
+
)}
|
|
249
247
|
</TableCell>
|
|
250
248
|
);
|
|
251
249
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import { TableRow } from '@mui/material';
|
|
1
|
+
import React, { CSSProperties, FC } from 'react';
|
|
2
|
+
import { alpha, TableRow } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
4
|
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
@@ -24,7 +24,16 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
return (
|
|
27
|
-
<TableRow
|
|
27
|
+
<TableRow
|
|
28
|
+
{...tableRowProps}
|
|
29
|
+
sx={(theme) =>
|
|
30
|
+
({
|
|
31
|
+
boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
32
|
+
//@ts-ignore
|
|
33
|
+
...tableRowProps?.sx,
|
|
34
|
+
} as CSSProperties)
|
|
35
|
+
}
|
|
36
|
+
>
|
|
28
37
|
{headerGroup.headers.map((header: MRT_Header, index) => (
|
|
29
38
|
<MRT_TableHeadCell
|
|
30
39
|
header={header}
|
package/src/icons.ts
CHANGED
|
@@ -19,6 +19,7 @@ import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
|
|
19
19
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
20
20
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
21
21
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
|
22
|
+
import RestartAltIcon from '@mui/icons-material/RestartAlt';
|
|
22
23
|
import SaveIcon from '@mui/icons-material/Save';
|
|
23
24
|
import SearchIcon from '@mui/icons-material/Search';
|
|
24
25
|
import SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
@@ -48,6 +49,7 @@ export interface MRT_Icons {
|
|
|
48
49
|
MoreHorizIcon: any;
|
|
49
50
|
MoreVertIcon: any;
|
|
50
51
|
PushPinIcon: any;
|
|
52
|
+
RestartAltIcon: any;
|
|
51
53
|
SaveIcon: any;
|
|
52
54
|
SearchIcon: any;
|
|
53
55
|
SearchOffIcon: any;
|
|
@@ -78,6 +80,7 @@ export const MRT_Default_Icons: MRT_Icons = {
|
|
|
78
80
|
MoreHorizIcon,
|
|
79
81
|
MoreVertIcon,
|
|
80
82
|
PushPinIcon,
|
|
83
|
+
RestartAltIcon,
|
|
81
84
|
SaveIcon,
|
|
82
85
|
SearchIcon,
|
|
83
86
|
SearchOffIcon,
|
|
@@ -16,11 +16,8 @@ interface Props {
|
|
|
16
16
|
export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: {
|
|
20
|
-
|
|
21
|
-
muiTableBodyCellEditTextFieldProps,
|
|
22
|
-
setCurrentEditingRow,
|
|
23
|
-
},
|
|
19
|
+
options: { enableEditing, muiTableBodyCellEditTextFieldProps },
|
|
20
|
+
setCurrentEditingRow,
|
|
24
21
|
} = tableInstance;
|
|
25
22
|
|
|
26
23
|
const [value, setValue] = useState(cell.value);
|
|
@@ -32,8 +32,8 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
32
32
|
idPrefix,
|
|
33
33
|
localization,
|
|
34
34
|
muiTableHeadCellFilterTextFieldProps,
|
|
35
|
-
setCurrentFilterTypes,
|
|
36
35
|
},
|
|
36
|
+
setCurrentFilterTypes,
|
|
37
37
|
} = tableInstance;
|
|
38
38
|
|
|
39
39
|
const { column } = header;
|
|
@@ -206,7 +206,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
206
206
|
width: '1.75rem',
|
|
207
207
|
}}
|
|
208
208
|
>
|
|
209
|
-
<CloseIcon
|
|
209
|
+
<CloseIcon />
|
|
210
210
|
</IconButton>
|
|
211
211
|
</span>
|
|
212
212
|
</Tooltip>
|
|
@@ -29,11 +29,11 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
29
29
|
idPrefix,
|
|
30
30
|
localization,
|
|
31
31
|
muiSearchTextFieldProps,
|
|
32
|
-
|
|
32
|
+
onGlobalSearchFilterChange,
|
|
33
33
|
},
|
|
34
34
|
} = tableInstance;
|
|
35
35
|
|
|
36
|
-
const { globalFilter,
|
|
36
|
+
const { globalFilter, showGlobalFilter } = getState();
|
|
37
37
|
|
|
38
38
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
39
39
|
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
|
@@ -41,7 +41,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
41
41
|
const handleChange = useCallback(
|
|
42
42
|
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
43
43
|
setGlobalFilter(event.target.value ?? undefined);
|
|
44
|
-
|
|
44
|
+
onGlobalSearchFilterChange?.({ event, tableInstance });
|
|
45
45
|
}, 200),
|
|
46
46
|
[],
|
|
47
47
|
);
|
|
@@ -61,7 +61,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
61
61
|
: muiSearchTextFieldProps;
|
|
62
62
|
|
|
63
63
|
return (
|
|
64
|
-
<Collapse in={
|
|
64
|
+
<Collapse in={showGlobalFilter} orientation="horizontal">
|
|
65
65
|
<TextField
|
|
66
66
|
id={`mrt-${idPrefix}-search-text-field`}
|
|
67
67
|
placeholder={localization.search}
|
|
@@ -82,7 +82,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
82
82
|
size="small"
|
|
83
83
|
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
84
84
|
>
|
|
85
|
-
<SearchIcon
|
|
85
|
+
<SearchIcon />
|
|
86
86
|
</IconButton>
|
|
87
87
|
</span>
|
|
88
88
|
</Tooltip>
|
|
@@ -97,7 +97,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
97
97
|
size="small"
|
|
98
98
|
title={localization.clearSearch}
|
|
99
99
|
>
|
|
100
|
-
<CloseIcon
|
|
100
|
+
<CloseIcon />
|
|
101
101
|
</IconButton>
|
|
102
102
|
</InputAdornment>
|
|
103
103
|
),
|
package/src/localization.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface MRT_Localization {
|
|
|
32
32
|
hideColumn: string;
|
|
33
33
|
pinToLeft: string;
|
|
34
34
|
pinToRight: string;
|
|
35
|
+
resetColumnSize: string;
|
|
35
36
|
rowActions: string;
|
|
36
37
|
rowNumber: string;
|
|
37
38
|
rowNumbers: string;
|
|
@@ -46,6 +47,8 @@ export interface MRT_Localization {
|
|
|
46
47
|
showHideSearch: string;
|
|
47
48
|
sortByColumnAsc: string;
|
|
48
49
|
sortByColumnDesc: string;
|
|
50
|
+
sortedByColumnAsc: string;
|
|
51
|
+
sortedByColumnDesc: string;
|
|
49
52
|
thenBy: string;
|
|
50
53
|
toggleDensePadding: string;
|
|
51
54
|
toggleFullScreen: string;
|
|
@@ -53,6 +56,7 @@ export interface MRT_Localization {
|
|
|
53
56
|
toggleSelectRow: string;
|
|
54
57
|
ungroupByColumn: string;
|
|
55
58
|
unpin: string;
|
|
59
|
+
unsorted: string;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
@@ -89,6 +93,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
89
93
|
hideColumn: 'Hide {column} column',
|
|
90
94
|
pinToLeft: 'Pin to left',
|
|
91
95
|
pinToRight: 'Pin to right',
|
|
96
|
+
resetColumnSize: 'Reset column size',
|
|
92
97
|
rowActions: 'Row Actions',
|
|
93
98
|
rowNumber: '#',
|
|
94
99
|
rowNumbers: 'Row Numbers',
|
|
@@ -104,6 +109,8 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
104
109
|
showHideSearch: 'Show/Hide search',
|
|
105
110
|
sortByColumnAsc: 'Sort by {column} ascending',
|
|
106
111
|
sortByColumnDesc: 'Sort by {column} descending',
|
|
112
|
+
sortedByColumnAsc: 'Sorted by {column} ascending',
|
|
113
|
+
sortedByColumnDesc: 'Sorted by {column} descending',
|
|
107
114
|
thenBy: ', then by ',
|
|
108
115
|
toggleDensePadding: 'Toggle dense padding',
|
|
109
116
|
toggleFullScreen: 'Toggle full screen',
|
|
@@ -111,4 +118,5 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
111
118
|
toggleSelectRow: 'Toggle select row',
|
|
112
119
|
ungroupByColumn: 'Ungroup by {column}',
|
|
113
120
|
unpin: 'Unpin',
|
|
121
|
+
unsorted: 'Unsorted',
|
|
114
122
|
};
|
|
@@ -35,9 +35,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
35
35
|
setColumnOrder,
|
|
36
36
|
options: {
|
|
37
37
|
enableColumnFilters,
|
|
38
|
-
|
|
38
|
+
enableColumnResizing,
|
|
39
39
|
enableGrouping,
|
|
40
40
|
enableHiding,
|
|
41
|
+
enablePinning,
|
|
41
42
|
enableSorting,
|
|
42
43
|
icons: {
|
|
43
44
|
ArrowRightIcon,
|
|
@@ -48,17 +49,18 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
48
49
|
FilterListOffIcon,
|
|
49
50
|
PushPinIcon,
|
|
50
51
|
SortIcon,
|
|
52
|
+
RestartAltIcon,
|
|
51
53
|
VisibilityOffIcon,
|
|
52
54
|
},
|
|
53
55
|
idPrefix,
|
|
54
56
|
localization,
|
|
55
|
-
setShowFilters,
|
|
56
57
|
},
|
|
58
|
+
setShowFilters,
|
|
57
59
|
} = tableInstance;
|
|
58
60
|
|
|
59
61
|
const { column } = header;
|
|
60
62
|
|
|
61
|
-
const {
|
|
63
|
+
const { columnSizing, columnVisibility, isDensePadding } = getState();
|
|
62
64
|
|
|
63
65
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
64
66
|
useState<null | HTMLElement>(null);
|
|
@@ -81,6 +83,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
81
83
|
setAnchorEl(null);
|
|
82
84
|
};
|
|
83
85
|
|
|
86
|
+
const handleResetColumnSize = () => {
|
|
87
|
+
column.resetSize();
|
|
88
|
+
setAnchorEl(null);
|
|
89
|
+
};
|
|
90
|
+
|
|
84
91
|
const handleHideColumn = () => {
|
|
85
92
|
column.toggleVisibility(false);
|
|
86
93
|
setAnchorEl(null);
|
|
@@ -245,7 +252,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
245
252
|
{enableGrouping &&
|
|
246
253
|
column.getCanGroup() && [
|
|
247
254
|
<MenuItem
|
|
248
|
-
divider={
|
|
255
|
+
divider={enablePinning}
|
|
249
256
|
key={0}
|
|
250
257
|
onClick={handleGroupByColumn}
|
|
251
258
|
sx={commonMenuItemStyles}
|
|
@@ -260,10 +267,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
260
267
|
</Box>
|
|
261
268
|
</MenuItem>,
|
|
262
269
|
]}
|
|
263
|
-
{
|
|
270
|
+
{enablePinning &&
|
|
264
271
|
column.getCanPin() && [
|
|
265
272
|
<MenuItem
|
|
266
|
-
disabled={column.getIsPinned() === 'left'}
|
|
273
|
+
disabled={column.getIsPinned() === 'left' || !column.getCanPin()}
|
|
267
274
|
key={0}
|
|
268
275
|
onClick={() => handlePinColumn('left')}
|
|
269
276
|
sx={commonMenuItemStyles}
|
|
@@ -276,7 +283,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
276
283
|
</Box>
|
|
277
284
|
</MenuItem>,
|
|
278
285
|
<MenuItem
|
|
279
|
-
disabled={column.getIsPinned() === 'right'}
|
|
286
|
+
disabled={column.getIsPinned() === 'right' || !column.getCanPin()}
|
|
280
287
|
key={0}
|
|
281
288
|
onClick={() => handlePinColumn('right')}
|
|
282
289
|
sx={commonMenuItemStyles}
|
|
@@ -303,6 +310,21 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
303
310
|
</Box>
|
|
304
311
|
</MenuItem>,
|
|
305
312
|
]}
|
|
313
|
+
{enableColumnResizing && [
|
|
314
|
+
<MenuItem
|
|
315
|
+
disabled={!column.getCanResize() || !columnSizing[column.id]}
|
|
316
|
+
key={0}
|
|
317
|
+
onClick={handleResetColumnSize}
|
|
318
|
+
sx={commonMenuItemStyles}
|
|
319
|
+
>
|
|
320
|
+
<Box sx={commonListItemStyles}>
|
|
321
|
+
<ListItemIcon>
|
|
322
|
+
<RestartAltIcon />
|
|
323
|
+
</ListItemIcon>
|
|
324
|
+
{localization.resetColumnSize}
|
|
325
|
+
</Box>
|
|
326
|
+
</MenuItem>,
|
|
327
|
+
]}
|
|
306
328
|
{enableHiding && [
|
|
307
329
|
<MenuItem
|
|
308
330
|
disabled={column.enableHiding === false}
|
|
@@ -39,12 +39,9 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
39
39
|
}) => {
|
|
40
40
|
const {
|
|
41
41
|
getState,
|
|
42
|
-
options: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setCurrentFilterTypes,
|
|
46
|
-
setCurrentGlobalFilterType,
|
|
47
|
-
},
|
|
42
|
+
options: { enabledGlobalFilterTypes, localization },
|
|
43
|
+
setCurrentFilterTypes,
|
|
44
|
+
setCurrentGlobalFilterType,
|
|
48
45
|
} = tableInstance;
|
|
49
46
|
|
|
50
47
|
const { isDensePadding, currentFilterTypes, currentGlobalFilterType } =
|
|
@@ -126,8 +123,8 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
126
123
|
},
|
|
127
124
|
].filter((filterType) =>
|
|
128
125
|
header
|
|
129
|
-
? !header.column.
|
|
130
|
-
header.column.
|
|
126
|
+
? !header.column.enabledColumnFilterTypes ||
|
|
127
|
+
header.column.enabledColumnFilterTypes.includes(filterType.type)
|
|
131
128
|
: (!enabledGlobalFilterTypes ||
|
|
132
129
|
enabledGlobalFilterTypes.includes(filterType.type)) &&
|
|
133
130
|
[
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
|
-
import type {
|
|
3
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
4
4
|
import { commonMenuItemStyles } from './MRT_ColumnActionMenu';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
|
-
column:
|
|
7
|
+
column: MRT_Column;
|
|
8
8
|
isSubMenu?: boolean;
|
|
9
9
|
tableInstance: MRT_TableInstance;
|
|
10
10
|
}
|
|
@@ -16,7 +16,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: {
|
|
19
|
+
options: { onToggleColumnVisibility },
|
|
20
20
|
} = tableInstance;
|
|
21
21
|
|
|
22
22
|
const { columnVisibility } = getState();
|
|
@@ -26,15 +26,15 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
26
26
|
(column.columnDefType === 'group' &&
|
|
27
27
|
column.getLeafColumns().some((col) => col.getIsVisible()));
|
|
28
28
|
|
|
29
|
-
const handleToggleColumnHidden = (column:
|
|
29
|
+
const handleToggleColumnHidden = (column: MRT_Column) => {
|
|
30
30
|
if (column.columnDefType === 'group') {
|
|
31
|
-
column?.columns?.forEach?.((childColumn:
|
|
31
|
+
column?.columns?.forEach?.((childColumn: MRT_Column) => {
|
|
32
32
|
childColumn.toggleVisibility(!switchChecked);
|
|
33
33
|
});
|
|
34
34
|
} else {
|
|
35
35
|
column.toggleVisibility();
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
onToggleColumnVisibility?.({
|
|
38
38
|
column,
|
|
39
39
|
columnVisibility,
|
|
40
40
|
tableInstance,
|
|
@@ -57,7 +57,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
57
57
|
onChange={() => handleToggleColumnHidden(column)}
|
|
58
58
|
/>
|
|
59
59
|
</MenuItem>
|
|
60
|
-
{column.columns?.map((c:
|
|
60
|
+
{column.columns?.map((c: MRT_Column, i) => (
|
|
61
61
|
<MRT_ShowHideColumnsMenuItems
|
|
62
62
|
key={`${i}-${c.id}`}
|
|
63
63
|
column={c}
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -14,10 +14,10 @@ export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
14
14
|
const {
|
|
15
15
|
getTableProps,
|
|
16
16
|
options: {
|
|
17
|
-
enableStickyHeader,
|
|
18
|
-
hideTableFooter,
|
|
19
|
-
hideTableHead,
|
|
20
17
|
muiTableProps,
|
|
18
|
+
enableTableHead,
|
|
19
|
+
enableTableFooter,
|
|
20
|
+
enableStickyHeader,
|
|
21
21
|
},
|
|
22
22
|
} = tableInstance;
|
|
23
23
|
|
|
@@ -33,11 +33,11 @@ export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<Table stickyHeader={enableStickyHeader} {...tableProps}>
|
|
36
|
-
{
|
|
36
|
+
{enableTableHead && (
|
|
37
37
|
<MRT_TableHead pinned={pinned} tableInstance={tableInstance} />
|
|
38
38
|
)}
|
|
39
39
|
<MRT_TableBody pinned={pinned} tableInstance={tableInstance} />
|
|
40
|
-
{
|
|
40
|
+
{enableTableFooter && (
|
|
41
41
|
<MRT_TableFooter pinned={pinned} tableInstance={tableInstance} />
|
|
42
42
|
)}
|
|
43
43
|
</Table>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { FC,
|
|
1
|
+
import React, { CSSProperties, FC, useEffect, useState } from 'react';
|
|
2
2
|
import { alpha, Box, TableContainer, Theme } from '@mui/material';
|
|
3
|
-
import { SystemStyleObject } from '@mui/material/node_modules/@mui/system';
|
|
4
3
|
import { MRT_TableInstance } from '..';
|
|
5
4
|
import { MRT_Table } from './MRT_Table';
|
|
6
5
|
|
|
@@ -12,10 +11,10 @@ const commonBoxStyles = ({
|
|
|
12
11
|
pinned?: 'left' | 'right';
|
|
13
12
|
theme: Theme;
|
|
14
13
|
visible?: boolean;
|
|
15
|
-
}):
|
|
14
|
+
}): CSSProperties => ({
|
|
16
15
|
display: 'grid',
|
|
17
16
|
minWidth: visible ? '200px' : 0,
|
|
18
|
-
overflowX: 'auto',
|
|
17
|
+
overflowX: pinned ? 'scroll' : 'auto',
|
|
19
18
|
boxShadow:
|
|
20
19
|
pinned === 'left'
|
|
21
20
|
? `0 1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
@@ -36,7 +35,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
36
35
|
getRightTableWidth,
|
|
37
36
|
getState,
|
|
38
37
|
options: {
|
|
39
|
-
|
|
38
|
+
enablePinning,
|
|
40
39
|
enableStickyHeader,
|
|
41
40
|
idPrefix,
|
|
42
41
|
muiTableContainerProps,
|
|
@@ -52,7 +51,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
52
51
|
? muiTableContainerProps({ tableInstance })
|
|
53
52
|
: muiTableContainerProps;
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
useEffect(() => {
|
|
56
55
|
const topToolbarHeight =
|
|
57
56
|
typeof document !== 'undefined'
|
|
58
57
|
? document?.getElementById(`mrt-${idPrefix}-toolbar-top`)
|
|
@@ -85,7 +84,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
85
84
|
: undefined,
|
|
86
85
|
}}
|
|
87
86
|
>
|
|
88
|
-
{
|
|
87
|
+
{enablePinning && getIsSomeColumnsPinned() ? (
|
|
89
88
|
<Box
|
|
90
89
|
sx={{
|
|
91
90
|
display: 'grid',
|