material-react-table 0.8.9 → 0.8.12
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 +29 -15
- package/dist/MaterialReactTable.d.ts +15 -12
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +185 -176
- 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 +186 -177
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
- package/package.json +14 -14
- package/src/MaterialReactTable.tsx +34 -30
- package/src/body/MRT_TableBodyCell.tsx +20 -18
- package/src/buttons/MRT_CopyButton.tsx +10 -3
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -3
- package/src/footer/MRT_TableFooterCell.tsx +11 -7
- package/src/footer/MRT_TableFooterRow.tsx +4 -4
- package/src/head/MRT_DraggableTableHeadCell.tsx +16 -9
- package/src/head/MRT_TableHeadCell.tsx +36 -37
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +3 -1
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +3 -2
- package/src/head/MRT_TableHeadCellSortLabel.tsx +4 -8
- package/src/inputs/MRT_EditCellTextField.tsx +15 -9
- package/src/inputs/MRT_FilterTextField.tsx +14 -9
- package/src/localization.ts +2 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +10 -8
- package/src/menus/MRT_FilterOptionMenu.tsx +11 -7
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -39
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +15 -6
- package/src/table/MRT_TableRoot.tsx +29 -28
|
@@ -41,25 +41,31 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
41
41
|
|
|
42
42
|
const { column } = header;
|
|
43
43
|
|
|
44
|
+
const { columnDef, columnDefType } = column;
|
|
45
|
+
|
|
44
46
|
const mTableHeadCellProps =
|
|
45
47
|
muiTableHeadCellProps instanceof Function
|
|
46
48
|
? muiTableHeadCellProps({ column, tableInstance })
|
|
47
49
|
: muiTableHeadCellProps;
|
|
48
50
|
|
|
49
51
|
const mcTableHeadCellProps =
|
|
50
|
-
|
|
51
|
-
?
|
|
52
|
-
:
|
|
52
|
+
columnDef.muiTableHeadCellProps instanceof Function
|
|
53
|
+
? columnDef.muiTableHeadCellProps({ column, tableInstance })
|
|
54
|
+
: columnDef.muiTableHeadCellProps;
|
|
53
55
|
|
|
54
56
|
const tableCellProps = {
|
|
55
57
|
...mTableHeadCellProps,
|
|
56
58
|
...mcTableHeadCellProps,
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
const headerElement = (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const headerElement = (
|
|
62
|
+
columnDef?.Header instanceof Function
|
|
63
|
+
? columnDef?.Header?.({
|
|
64
|
+
header,
|
|
65
|
+
tableInstance,
|
|
66
|
+
})
|
|
67
|
+
: columnDef?.Header ?? header.renderHeader()
|
|
68
|
+
) as ReactNode;
|
|
63
69
|
|
|
64
70
|
const getIsLastLeftPinnedColumn = () => {
|
|
65
71
|
return (
|
|
@@ -83,13 +89,13 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
83
89
|
|
|
84
90
|
return (
|
|
85
91
|
<TableCell
|
|
86
|
-
align={
|
|
92
|
+
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
87
93
|
colSpan={header.colSpan}
|
|
88
94
|
{...tableCellProps}
|
|
89
|
-
ref={
|
|
95
|
+
ref={columnDefType === 'data' ? dropRef : undefined}
|
|
90
96
|
sx={(theme: Theme) => ({
|
|
91
97
|
backgroundColor:
|
|
92
|
-
column.getIsPinned() &&
|
|
98
|
+
column.getIsPinned() && columnDefType !== 'group'
|
|
93
99
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
94
100
|
: 'inherit',
|
|
95
101
|
backgroundImage: 'inherit',
|
|
@@ -106,41 +112,36 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
106
112
|
: undefined,
|
|
107
113
|
overflow: 'visible',
|
|
108
114
|
p: isDensePadding
|
|
109
|
-
?
|
|
115
|
+
? columnDefType === 'display'
|
|
110
116
|
? '0 0.5rem'
|
|
111
117
|
: '0.5rem'
|
|
112
|
-
:
|
|
118
|
+
: columnDefType === 'display'
|
|
113
119
|
? '0.5rem 0.75rem'
|
|
114
120
|
: '1rem',
|
|
115
|
-
pb:
|
|
121
|
+
pb: columnDefType === 'display' ? 0 : undefined,
|
|
116
122
|
position:
|
|
117
|
-
column.getIsPinned() &&
|
|
123
|
+
column.getIsPinned() && columnDefType !== 'group'
|
|
118
124
|
? 'sticky'
|
|
119
125
|
: undefined,
|
|
120
|
-
pt:
|
|
121
|
-
column.columnDefType === 'display'
|
|
122
|
-
? 0
|
|
123
|
-
: isDensePadding
|
|
124
|
-
? '0.75rem'
|
|
125
|
-
: '1.25rem',
|
|
126
|
+
pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.5rem',
|
|
126
127
|
right:
|
|
127
128
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
128
129
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
129
130
|
verticalAlign: 'text-top',
|
|
130
131
|
zIndex: column.getIsResizing()
|
|
131
132
|
? 3
|
|
132
|
-
: column.getIsPinned() &&
|
|
133
|
+
: column.getIsPinned() && columnDefType !== 'group'
|
|
133
134
|
? 2
|
|
134
135
|
: 1,
|
|
135
136
|
...(tableCellProps?.sx as any),
|
|
136
137
|
})}
|
|
137
138
|
style={{
|
|
138
139
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
139
|
-
minWidth: `max(${column.getSize()}px, ${
|
|
140
|
+
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
|
140
141
|
width: header.getSize(),
|
|
141
142
|
}}
|
|
142
143
|
>
|
|
143
|
-
{header.isPlaceholder ? null :
|
|
144
|
+
{header.isPlaceholder ? null : columnDefType === 'display' ? (
|
|
144
145
|
headerElement
|
|
145
146
|
) : (
|
|
146
147
|
<Box
|
|
@@ -149,7 +150,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
149
150
|
alignItems: 'flex-start',
|
|
150
151
|
display: 'flex',
|
|
151
152
|
justifyContent:
|
|
152
|
-
|
|
153
|
+
columnDefType === 'group' ? 'center' : 'space-between',
|
|
153
154
|
opacity: isDragging ? 0.5 : 1,
|
|
154
155
|
width: '100%',
|
|
155
156
|
}}
|
|
@@ -159,25 +160,23 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
159
160
|
sx={{
|
|
160
161
|
alignItems: 'center',
|
|
161
162
|
cursor:
|
|
162
|
-
column.getCanSort() &&
|
|
163
|
+
column.getCanSort() && columnDefType !== 'group'
|
|
163
164
|
? 'pointer'
|
|
164
165
|
: undefined,
|
|
165
166
|
display: 'flex',
|
|
166
167
|
flexWrap: 'nowrap',
|
|
167
168
|
whiteSpace:
|
|
168
|
-
(
|
|
169
|
-
? 'nowrap'
|
|
170
|
-
: 'normal',
|
|
169
|
+
(columnDef.header?.length ?? 0) < 24 ? 'nowrap' : 'normal',
|
|
171
170
|
}}
|
|
172
171
|
>
|
|
173
172
|
{headerElement}
|
|
174
|
-
{
|
|
173
|
+
{columnDefType === 'data' && column.getCanSort() && (
|
|
175
174
|
<MRT_TableHeadCellSortLabel
|
|
176
175
|
header={header}
|
|
177
176
|
tableInstance={tableInstance}
|
|
178
177
|
/>
|
|
179
178
|
)}
|
|
180
|
-
{
|
|
179
|
+
{columnDefType === 'data' &&
|
|
181
180
|
enableColumnFilters &&
|
|
182
181
|
column.getCanFilter() && (
|
|
183
182
|
<MRT_TableHeadCellFilterLabel
|
|
@@ -187,19 +186,19 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
187
186
|
)}
|
|
188
187
|
</Box>
|
|
189
188
|
<Box sx={{ whiteSpace: 'nowrap' }}>
|
|
190
|
-
{
|
|
189
|
+
{columnDefType === 'data' &&
|
|
191
190
|
((enableColumnOrdering &&
|
|
192
|
-
|
|
193
|
-
(enableGrouping &&
|
|
191
|
+
columnDef.enableColumnOrdering !== false) ||
|
|
192
|
+
(enableGrouping && columnDef.enableGrouping !== false)) && (
|
|
194
193
|
<MRT_TableHeadCellGrabHandle
|
|
195
194
|
header={header}
|
|
196
195
|
ref={dragRef as Ref<HTMLButtonElement>}
|
|
197
196
|
tableInstance={tableInstance}
|
|
198
197
|
/>
|
|
199
198
|
)}
|
|
200
|
-
{(enableColumnActions ||
|
|
201
|
-
|
|
202
|
-
|
|
199
|
+
{(enableColumnActions || columnDef.enableColumnActions) &&
|
|
200
|
+
columnDef.enableColumnActions !== false &&
|
|
201
|
+
columnDefType !== 'group' && (
|
|
203
202
|
<MRT_ToggleColumnActionMenuButton
|
|
204
203
|
header={header}
|
|
205
204
|
tableInstance={tableInstance}
|
|
@@ -214,7 +213,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
214
213
|
)}
|
|
215
214
|
</Box>
|
|
216
215
|
)}
|
|
217
|
-
{
|
|
216
|
+
{columnDefType === 'data' && column.getCanFilter() && (
|
|
218
217
|
<MRT_TableHeadCellFilterContainer
|
|
219
218
|
header={header}
|
|
220
219
|
tableInstance={tableInstance}
|
|
@@ -24,11 +24,13 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({
|
|
|
24
24
|
|
|
25
25
|
const { column } = header;
|
|
26
26
|
|
|
27
|
+
const { columnDef } = column;
|
|
28
|
+
|
|
27
29
|
const filterFn = getState()?.currentFilterFns?.[header.id];
|
|
28
30
|
|
|
29
31
|
const filterTooltip = !!column.getFilterValue()
|
|
30
32
|
? localization.filteringByColumn
|
|
31
|
-
.replace('{column}', String(
|
|
33
|
+
.replace('{column}', String(columnDef.header))
|
|
32
34
|
.replace(
|
|
33
35
|
'{filterType}',
|
|
34
36
|
filterFn instanceof Function
|
|
@@ -17,6 +17,8 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
|
|
|
17
17
|
|
|
18
18
|
const { column } = header;
|
|
19
19
|
|
|
20
|
+
const { columnDefType } = column;
|
|
21
|
+
|
|
20
22
|
return (
|
|
21
23
|
<Divider
|
|
22
24
|
flexItem
|
|
@@ -26,8 +28,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
|
|
|
26
28
|
borderRadius: '2px',
|
|
27
29
|
borderRightWidth: '2px',
|
|
28
30
|
cursor: 'col-resize',
|
|
29
|
-
height:
|
|
30
|
-
showFilters && column.columnDefType === 'data' ? '4rem' : '2rem',
|
|
31
|
+
height: showFilters && columnDefType === 'data' ? '4rem' : '2rem',
|
|
31
32
|
opacity: 0.8,
|
|
32
33
|
position: 'absolute',
|
|
33
34
|
right: '1px',
|
|
@@ -17,16 +17,12 @@ export const MRT_TableHeadCellSortLabel: FC<Props> = ({
|
|
|
17
17
|
|
|
18
18
|
const { column } = header;
|
|
19
19
|
|
|
20
|
+
const { columnDef } = column;
|
|
21
|
+
|
|
20
22
|
const sortTooltip = !!column.getIsSorted()
|
|
21
23
|
? column.getIsSorted() === 'desc'
|
|
22
|
-
? localization.sortedByColumnDesc.replace(
|
|
23
|
-
|
|
24
|
-
column.columnDef.header,
|
|
25
|
-
)
|
|
26
|
-
: localization.sortedByColumnAsc.replace(
|
|
27
|
-
'{column}',
|
|
28
|
-
column.columnDef.header,
|
|
29
|
-
)
|
|
24
|
+
? localization.sortedByColumnDesc.replace('{column}', columnDef.header)
|
|
25
|
+
: localization.sortedByColumnAsc.replace('{column}', columnDef.header)
|
|
30
26
|
: localization.unsorted;
|
|
31
27
|
|
|
32
28
|
return (
|
|
@@ -31,19 +31,22 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
31
31
|
|
|
32
32
|
const { column, row } = cell;
|
|
33
33
|
|
|
34
|
+
const { columnDef } = column;
|
|
35
|
+
|
|
34
36
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
35
37
|
setValue(event.target.value);
|
|
36
|
-
|
|
38
|
+
columnDef.onCellEditChange?.({ event, cell, tableInstance });
|
|
37
39
|
onCellEditChange?.({ event, cell, tableInstance });
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
41
43
|
if (getState().currentEditingRow) {
|
|
42
|
-
row._valuesCache
|
|
44
|
+
if (!row._valuesCache) row._valuesCache = {};
|
|
45
|
+
(row._valuesCache as Record<string, any>)[column.id] = value;
|
|
43
46
|
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
44
47
|
}
|
|
45
48
|
setCurrentEditingCell(null);
|
|
46
|
-
|
|
49
|
+
columnDef.onCellEditBlur?.({ event, cell, tableInstance });
|
|
47
50
|
onCellEditBlur?.({ event, cell, tableInstance });
|
|
48
51
|
};
|
|
49
52
|
|
|
@@ -53,17 +56,20 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
53
56
|
: muiTableBodyCellEditTextFieldProps;
|
|
54
57
|
|
|
55
58
|
const mcTableBodyCellEditTextFieldProps =
|
|
56
|
-
|
|
57
|
-
?
|
|
58
|
-
|
|
59
|
+
columnDef.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
60
|
+
? columnDef.muiTableBodyCellEditTextFieldProps({
|
|
61
|
+
cell,
|
|
62
|
+
tableInstance,
|
|
63
|
+
})
|
|
64
|
+
: columnDef.muiTableBodyCellEditTextFieldProps;
|
|
59
65
|
|
|
60
66
|
const textFieldProps = {
|
|
61
67
|
...mTableBodyCellEditTextFieldProps,
|
|
62
68
|
...mcTableBodyCellEditTextFieldProps,
|
|
63
69
|
};
|
|
64
70
|
|
|
65
|
-
if (enableEditing &&
|
|
66
|
-
return <>{
|
|
71
|
+
if (enableEditing && columnDef.enableEditing !== false && columnDef.Edit) {
|
|
72
|
+
return <>{columnDef.Edit?.({ cell, tableInstance })}</>;
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
return (
|
|
@@ -73,7 +79,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
73
79
|
onBlur={handleBlur}
|
|
74
80
|
onChange={handleChange}
|
|
75
81
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
76
|
-
placeholder={
|
|
82
|
+
placeholder={columnDef.header}
|
|
77
83
|
value={value}
|
|
78
84
|
variant="standard"
|
|
79
85
|
{...textFieldProps}
|
|
@@ -43,6 +43,8 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
43
43
|
|
|
44
44
|
const { column } = header;
|
|
45
45
|
|
|
46
|
+
const { columnDef } = column;
|
|
47
|
+
|
|
46
48
|
const { currentFilterFns } = getState();
|
|
47
49
|
|
|
48
50
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
@@ -53,9 +55,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
53
55
|
: muiTableHeadCellFilterTextFieldProps;
|
|
54
56
|
|
|
55
57
|
const mcTableHeadCellFilterTextFieldProps =
|
|
56
|
-
|
|
57
|
-
?
|
|
58
|
-
|
|
58
|
+
columnDef.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
59
|
+
? columnDef.muiTableHeadCellFilterTextFieldProps({
|
|
60
|
+
column,
|
|
61
|
+
tableInstance,
|
|
62
|
+
})
|
|
63
|
+
: columnDef.muiTableHeadCellFilterTextFieldProps;
|
|
59
64
|
|
|
60
65
|
const textFieldProps = {
|
|
61
66
|
...mTableHeadCellFilterTextFieldProps,
|
|
@@ -109,15 +114,15 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
109
114
|
}));
|
|
110
115
|
};
|
|
111
116
|
|
|
112
|
-
if (
|
|
113
|
-
return <>{
|
|
117
|
+
if (columnDef.Filter) {
|
|
118
|
+
return <>{columnDef.Filter?.({ header, tableInstance })}</>;
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field${
|
|
117
122
|
inputIndex ?? ''
|
|
118
123
|
}`;
|
|
119
124
|
const filterFn = currentFilterFns?.[header.id];
|
|
120
|
-
const isSelectFilter = !!
|
|
125
|
+
const isSelectFilter = !!columnDef.filterSelectOptions;
|
|
121
126
|
const filterChipLabel =
|
|
122
127
|
!(filterFn instanceof Function) &&
|
|
123
128
|
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(
|
|
@@ -132,7 +137,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
132
137
|
inputIndex === undefined
|
|
133
138
|
? localization.filterByColumn?.replace(
|
|
134
139
|
'{column}',
|
|
135
|
-
String(
|
|
140
|
+
String(columnDef.header),
|
|
136
141
|
)
|
|
137
142
|
: inputIndex === 0
|
|
138
143
|
? localization.min
|
|
@@ -252,7 +257,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
252
257
|
sx={{
|
|
253
258
|
m: '-0.25rem',
|
|
254
259
|
p: 0,
|
|
255
|
-
minWidth: !filterChipLabel ? '
|
|
260
|
+
minWidth: !filterChipLabel ? '8rem' : 'auto',
|
|
256
261
|
width: 'calc(100% + 0.5rem)',
|
|
257
262
|
mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
|
|
258
263
|
'& .MuiSelect-icon': {
|
|
@@ -266,7 +271,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
266
271
|
{localization.clearFilter}
|
|
267
272
|
</MenuItem>
|
|
268
273
|
)}
|
|
269
|
-
{
|
|
274
|
+
{columnDef?.filterSelectOptions?.map((option) => {
|
|
270
275
|
let value;
|
|
271
276
|
let text;
|
|
272
277
|
if (typeof option === 'string') {
|
package/src/localization.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface MRT_Localization {
|
|
|
37
37
|
pinToLeft: string;
|
|
38
38
|
pinToRight: string;
|
|
39
39
|
resetColumnSize: string;
|
|
40
|
+
resetOrder: string;
|
|
40
41
|
rowActions: string;
|
|
41
42
|
rowNumber: string;
|
|
42
43
|
rowNumbers: string;
|
|
@@ -104,6 +105,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
104
105
|
pinToLeft: 'Pin to left',
|
|
105
106
|
pinToRight: 'Pin to right',
|
|
106
107
|
resetColumnSize: 'Reset column size',
|
|
108
|
+
resetOrder: 'Reset order',
|
|
107
109
|
rowActions: 'Row Actions',
|
|
108
110
|
rowNumber: '#',
|
|
109
111
|
rowNumbers: 'Row Numbers',
|
|
@@ -60,6 +60,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
60
60
|
|
|
61
61
|
const { column } = header;
|
|
62
62
|
|
|
63
|
+
const { columnDef } = column;
|
|
64
|
+
|
|
63
65
|
const { columnSizing, columnVisibility, isDensePadding } = getState();
|
|
64
66
|
|
|
65
67
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
@@ -178,7 +180,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
178
180
|
</ListItemIcon>
|
|
179
181
|
{localization.sortByColumnAsc?.replace(
|
|
180
182
|
'{column}',
|
|
181
|
-
String(
|
|
183
|
+
String(columnDef.header),
|
|
182
184
|
)}
|
|
183
185
|
</Box>
|
|
184
186
|
</MenuItem>,
|
|
@@ -195,7 +197,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
195
197
|
</ListItemIcon>
|
|
196
198
|
{localization.sortByColumnDesc?.replace(
|
|
197
199
|
'{column}',
|
|
198
|
-
String(
|
|
200
|
+
String(columnDef.header),
|
|
199
201
|
)}
|
|
200
202
|
</Box>
|
|
201
203
|
</MenuItem>,
|
|
@@ -227,10 +229,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
227
229
|
</ListItemIcon>
|
|
228
230
|
{localization.filterByColumn?.replace(
|
|
229
231
|
'{column}',
|
|
230
|
-
String(
|
|
232
|
+
String(columnDef.header),
|
|
231
233
|
)}
|
|
232
234
|
</Box>
|
|
233
|
-
{!
|
|
235
|
+
{!columnDef.filterSelectOptions && (
|
|
234
236
|
<IconButton
|
|
235
237
|
onClick={handleOpenFilterModeMenu}
|
|
236
238
|
onMouseEnter={handleOpenFilterModeMenu}
|
|
@@ -264,7 +266,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
264
266
|
</ListItemIcon>
|
|
265
267
|
{localization[
|
|
266
268
|
column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn'
|
|
267
|
-
]?.replace('{column}', String(
|
|
269
|
+
]?.replace('{column}', String(columnDef.header))}
|
|
268
270
|
</Box>
|
|
269
271
|
</MenuItem>,
|
|
270
272
|
]}
|
|
@@ -328,7 +330,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
328
330
|
]}
|
|
329
331
|
{enableHiding && [
|
|
330
332
|
<MenuItem
|
|
331
|
-
disabled={
|
|
333
|
+
disabled={columnDef.enableHiding === false}
|
|
332
334
|
key={0}
|
|
333
335
|
onClick={handleHideColumn}
|
|
334
336
|
sx={commonMenuItemStyles}
|
|
@@ -339,7 +341,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
339
341
|
</ListItemIcon>
|
|
340
342
|
{localization.hideColumn?.replace(
|
|
341
343
|
'{column}',
|
|
342
|
-
String(
|
|
344
|
+
String(columnDef.header),
|
|
343
345
|
)}
|
|
344
346
|
</Box>
|
|
345
347
|
</MenuItem>,
|
|
@@ -358,7 +360,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
358
360
|
</ListItemIcon>
|
|
359
361
|
{localization.showAllColumns?.replace(
|
|
360
362
|
'{column}',
|
|
361
|
-
String(
|
|
363
|
+
String(columnDef.header),
|
|
362
364
|
)}
|
|
363
365
|
</Box>
|
|
364
366
|
<IconButton
|
|
@@ -47,6 +47,10 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
47
47
|
const { isDensePadding, currentFilterFns, currentGlobalFilterFn } =
|
|
48
48
|
getState();
|
|
49
49
|
|
|
50
|
+
const { column } = header ?? {};
|
|
51
|
+
|
|
52
|
+
const { columnDef } = column ?? {};
|
|
53
|
+
|
|
50
54
|
const filterOptions: {
|
|
51
55
|
option: MRT_FILTER_OPTION;
|
|
52
56
|
label: string;
|
|
@@ -122,9 +126,9 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
122
126
|
fn: notEmpty,
|
|
123
127
|
},
|
|
124
128
|
].filter((filterType) =>
|
|
125
|
-
|
|
126
|
-
? !
|
|
127
|
-
|
|
129
|
+
columnDef
|
|
130
|
+
? !columnDef.enabledColumnFilterOptions ||
|
|
131
|
+
columnDef.enabledColumnFilterOptions.includes(filterType.option)
|
|
128
132
|
: (!enabledGlobalFilterOptions ||
|
|
129
133
|
enabledGlobalFilterOptions.includes(filterType.option)) &&
|
|
130
134
|
[MRT_FILTER_OPTION.FUZZY, MRT_FILTER_OPTION.CONTAINS].includes(
|
|
@@ -135,7 +139,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
135
139
|
);
|
|
136
140
|
|
|
137
141
|
const handleSelectFilterType = (value: MRT_FILTER_OPTION) => {
|
|
138
|
-
if (header) {
|
|
142
|
+
if (header && column) {
|
|
139
143
|
setCurrentFilterFns((prev: { [key: string]: MRT_FilterFn }) => ({
|
|
140
144
|
...prev,
|
|
141
145
|
[header.id]: value,
|
|
@@ -143,11 +147,11 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
143
147
|
if (
|
|
144
148
|
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(value)
|
|
145
149
|
) {
|
|
146
|
-
|
|
150
|
+
column.setFilterValue(' ');
|
|
147
151
|
} else if (value === MRT_FILTER_OPTION.BETWEEN) {
|
|
148
|
-
|
|
152
|
+
column.setFilterValue(['', '']);
|
|
149
153
|
} else {
|
|
150
|
-
|
|
154
|
+
column.setFilterValue('');
|
|
151
155
|
}
|
|
152
156
|
} else {
|
|
153
157
|
setCurrentGlobalFilterFn(value);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Button, Menu, Divider, Box } from '@mui/material';
|
|
3
3
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
4
|
-
import { MRT_Column, MRT_TableInstance } from '..';
|
|
4
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
anchorEl: HTMLElement | null;
|
|
@@ -18,42 +18,36 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
18
18
|
}) => {
|
|
19
19
|
const {
|
|
20
20
|
getAllColumns,
|
|
21
|
+
getAllLeafColumns,
|
|
21
22
|
getIsAllColumnsVisible,
|
|
22
|
-
getIsSomeColumnsVisible,
|
|
23
23
|
getIsSomeColumnsPinned,
|
|
24
|
+
getIsSomeColumnsVisible,
|
|
24
25
|
getState,
|
|
25
26
|
toggleAllColumnsVisible,
|
|
26
|
-
|
|
27
|
-
options: { localization, enablePinning },
|
|
27
|
+
options: { localization, enablePinning, enableColumnOrdering },
|
|
28
28
|
} = tableInstance;
|
|
29
29
|
|
|
30
|
-
const { isDensePadding } = getState();
|
|
30
|
+
const { isDensePadding, columnOrder, columnPinning } = getState();
|
|
31
31
|
|
|
32
32
|
const hideAllColumns = () => {
|
|
33
33
|
getAllLeafColumns()
|
|
34
|
-
.filter((col) => col.enableHiding !== false)
|
|
34
|
+
.filter((col) => col.columnDef.enableHiding !== false)
|
|
35
35
|
.forEach((col) => col.toggleVisibility(false));
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
...dataColumns.filter((c) => c.getIsPinned() === false),
|
|
52
|
-
null,
|
|
53
|
-
...dataColumns.filter((c) => c.getIsPinned() === 'right'),
|
|
54
|
-
]
|
|
55
|
-
: dataColumns;
|
|
56
|
-
}, [getAllColumns(), getState().columnPinning, getIsSomeColumnsPinned()]);
|
|
38
|
+
const allColumns = useMemo(() => {
|
|
39
|
+
const columns = getAllColumns();
|
|
40
|
+
if (
|
|
41
|
+
columnOrder.length > 0 &&
|
|
42
|
+
!columns.some((col) => col.columnDefType === 'group')
|
|
43
|
+
) {
|
|
44
|
+
return (
|
|
45
|
+
columnOrder.map((colId) => columns.find((col) => col.id === colId)) ??
|
|
46
|
+
columns
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return columns;
|
|
50
|
+
}, [getAllColumns(), columnOrder, columnPinning]) as MRT_Column[];
|
|
57
51
|
|
|
58
52
|
return (
|
|
59
53
|
<Menu
|
|
@@ -80,6 +74,11 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
80
74
|
{localization.hideAll}
|
|
81
75
|
</Button>
|
|
82
76
|
)}
|
|
77
|
+
{!isSubMenu && enableColumnOrdering && (
|
|
78
|
+
<Button onClick={() => tableInstance.resetColumnOrder()}>
|
|
79
|
+
{localization.resetOrder}
|
|
80
|
+
</Button>
|
|
81
|
+
)}
|
|
83
82
|
{!isSubMenu && enablePinning && (
|
|
84
83
|
<Button
|
|
85
84
|
disabled={!getIsSomeColumnsPinned()}
|
|
@@ -96,7 +95,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
96
95
|
</Button>
|
|
97
96
|
</Box>
|
|
98
97
|
<Divider />
|
|
99
|
-
{
|
|
98
|
+
{allColumns.map((column, index) => (
|
|
100
99
|
<MRT_ShowHideColumnsMenuItems
|
|
101
100
|
column={column}
|
|
102
101
|
isSubMenu={isSubMenu}
|
|
@@ -104,19 +103,6 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
104
103
|
tableInstance={tableInstance}
|
|
105
104
|
/>
|
|
106
105
|
))}
|
|
107
|
-
<Divider />
|
|
108
|
-
{allDataColumns.map((column, index) =>
|
|
109
|
-
column ? (
|
|
110
|
-
<MRT_ShowHideColumnsMenuItems
|
|
111
|
-
column={column}
|
|
112
|
-
isSubMenu={isSubMenu}
|
|
113
|
-
key={`${index}-${column.id}`}
|
|
114
|
-
tableInstance={tableInstance}
|
|
115
|
-
/>
|
|
116
|
-
) : (
|
|
117
|
-
<Divider key={`${index}-divider`} />
|
|
118
|
-
),
|
|
119
|
-
)}
|
|
120
106
|
</Menu>
|
|
121
107
|
);
|
|
122
108
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
|
-
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
4
3
|
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
|
4
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
column: MRT_Column;
|
|
@@ -21,13 +21,15 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
21
21
|
|
|
22
22
|
const { columnVisibility } = getState();
|
|
23
23
|
|
|
24
|
+
const { columnDef, columnDefType } = column;
|
|
25
|
+
|
|
24
26
|
const switchChecked =
|
|
25
|
-
(
|
|
26
|
-
(
|
|
27
|
+
(columnDefType !== 'group' && column.getIsVisible()) ||
|
|
28
|
+
(columnDefType === 'group' &&
|
|
27
29
|
column.getLeafColumns().some((col) => col.getIsVisible()));
|
|
28
30
|
|
|
29
31
|
const handleToggleColumnHidden = (column: MRT_Column) => {
|
|
30
|
-
if (
|
|
32
|
+
if (columnDefType === 'group') {
|
|
31
33
|
column?.columns?.forEach?.((childColumn: MRT_Column) => {
|
|
32
34
|
childColumn.toggleVisibility(!switchChecked);
|
|
33
35
|
});
|
|
@@ -59,11 +61,18 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
59
61
|
/>
|
|
60
62
|
)}
|
|
61
63
|
<FormControlLabel
|
|
62
|
-
componentsProps={{
|
|
64
|
+
componentsProps={{
|
|
65
|
+
typography: {
|
|
66
|
+
sx: {
|
|
67
|
+
marginBottom: 0,
|
|
68
|
+
opacity: columnDefType !== 'display' ? 1 : 0.5,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}}
|
|
63
72
|
checked={switchChecked}
|
|
64
73
|
control={<Switch />}
|
|
65
74
|
disabled={(isSubMenu && switchChecked) || !column.getCanHide()}
|
|
66
|
-
label={
|
|
75
|
+
label={columnDef.header}
|
|
67
76
|
onChange={() => handleToggleColumnHidden(column)}
|
|
68
77
|
/>
|
|
69
78
|
</MenuItem>
|