material-react-table 0.9.7 → 0.12.0
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 +176 -158
- package/dist/body/MRT_TableBody.d.ts +1 -1
- package/dist/body/MRT_TableBodyCell.d.ts +1 -1
- package/dist/body/MRT_TableBodyRow.d.ts +1 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
- package/dist/buttons/MRT_ColumnPinningButtons.d.ts +1 -1
- package/dist/buttons/MRT_CopyButton.d.ts +1 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
- package/dist/buttons/MRT_ExpandAllButton.d.ts +1 -1
- package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +1 -1
- package/dist/buttons/MRT_GrabHandleButton.d.ts +1 -1
- package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
- package/dist/filtersFNs.d.ts +2 -2
- package/dist/footer/MRT_TableFooter.d.ts +1 -1
- package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
- package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/head/MRT_DraggableTableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHead.d.ts +1 -1
- package/dist/head/MRT_TableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellFilterContainer.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellResizeHandle.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/head/MRT_TableHeadRow.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
- package/dist/inputs/MRT_FilterRangeFields.d.ts +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/inputs/MRT_SearchTextField.d.ts +1 -1
- package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +607 -577
- 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 -577
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +1 -1
- package/dist/menus/MRT_FilterOptionMenu.d.ts +1 -1
- package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/table/MRT_Table.d.ts +1 -1
- package/dist/table/MRT_TableContainer.d.ts +1 -1
- package/dist/table/MRT_TablePaper.d.ts +1 -1
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +1 -1
- package/dist/toolbar/MRT_TablePagination.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -1
- package/dist/utils.d.ts +2 -2
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +227 -211
- package/src/body/MRT_TableBody.tsx +5 -8
- package/src/body/MRT_TableBodyCell.tsx +15 -19
- package/src/body/MRT_TableBodyRow.tsx +8 -12
- package/src/body/MRT_TableDetailPanel.tsx +13 -11
- package/src/buttons/MRT_ColumnPinningButtons.tsx +3 -6
- package/src/buttons/MRT_CopyButton.tsx +5 -9
- package/src/buttons/MRT_EditActionButtons.tsx +5 -5
- package/src/buttons/MRT_ExpandAllButton.tsx +3 -3
- package/src/buttons/MRT_ExpandButton.tsx +5 -5
- package/src/buttons/MRT_FullScreenToggleButton.tsx +6 -6
- package/src/buttons/MRT_GrabHandleButton.tsx +3 -3
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -7
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +6 -6
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +6 -6
- package/src/buttons/MRT_ToggleFiltersButton.tsx +6 -9
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +7 -7
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +6 -9
- package/src/filtersFNs.ts +2 -2
- package/src/footer/MRT_TableFooter.tsx +5 -5
- package/src/footer/MRT_TableFooterCell.tsx +6 -6
- package/src/footer/MRT_TableFooterRow.tsx +5 -8
- package/src/head/MRT_DraggableTableHeadCell.tsx +4 -7
- package/src/head/MRT_TableHead.tsx +5 -5
- package/src/head/MRT_TableHeadCell.tsx +14 -22
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +6 -7
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +3 -3
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +3 -3
- package/src/head/MRT_TableHeadCellSortLabel.tsx +3 -6
- package/src/head/MRT_TableHeadRow.tsx +6 -6
- package/src/inputs/MRT_EditCellTextField.tsx +12 -12
- package/src/inputs/MRT_FilterRangeFields.tsx +5 -13
- package/src/inputs/MRT_FilterTextField.tsx +82 -53
- package/src/inputs/MRT_SearchTextField.tsx +17 -13
- package/src/inputs/MRT_SelectCheckbox.tsx +14 -20
- package/src/menus/MRT_ColumnActionMenu.tsx +5 -5
- package/src/menus/MRT_FilterOptionMenu.tsx +43 -36
- package/src/menus/MRT_RowActionMenu.tsx +4 -4
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -6
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +9 -12
- package/src/table/MRT_Table.tsx +7 -7
- package/src/table/MRT_TableContainer.tsx +5 -8
- package/src/table/MRT_TablePaper.tsx +7 -9
- package/src/table/MRT_TableRoot.tsx +13 -21
- package/src/toolbar/MRT_LinearProgressBar.tsx +4 -7
- package/src/toolbar/MRT_TablePagination.tsx +4 -4
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +6 -8
- package/src/toolbar/MRT_ToolbarBottom.tsx +8 -8
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +10 -12
- package/src/toolbar/MRT_ToolbarTop.tsx +10 -10
- package/src/utils.ts +2 -2
- package/dist/enums.d.ts +0 -13
- package/src/enums.ts +0 -13
|
@@ -15,31 +15,33 @@ import {
|
|
|
15
15
|
TextFieldProps,
|
|
16
16
|
Tooltip,
|
|
17
17
|
} from '@mui/material';
|
|
18
|
-
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
19
18
|
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
20
|
-
import {
|
|
19
|
+
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
21
20
|
|
|
22
21
|
interface Props {
|
|
23
22
|
header: MRT_Header;
|
|
24
23
|
inputIndex?: number;
|
|
25
|
-
|
|
24
|
+
instance: MRT_TableInstance;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
export const MRT_FilterTextField: FC<Props> = ({
|
|
29
28
|
header,
|
|
30
29
|
inputIndex,
|
|
31
|
-
|
|
30
|
+
instance,
|
|
32
31
|
}) => {
|
|
33
32
|
const {
|
|
34
33
|
getState,
|
|
35
34
|
options: {
|
|
35
|
+
enabledColumnFilterOptions,
|
|
36
36
|
icons: { FilterListIcon, CloseIcon },
|
|
37
|
-
tableId,
|
|
38
37
|
localization,
|
|
39
38
|
muiTableHeadCellFilterTextFieldProps,
|
|
39
|
+
onColumnFilterValueChanged,
|
|
40
|
+
onColumnFilterValueChangedDebounced,
|
|
41
|
+
tableId,
|
|
40
42
|
},
|
|
41
43
|
setCurrentFilterFns,
|
|
42
|
-
} =
|
|
44
|
+
} = instance;
|
|
43
45
|
|
|
44
46
|
const { column } = header;
|
|
45
47
|
|
|
@@ -51,14 +53,14 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
51
53
|
|
|
52
54
|
const mTableHeadCellFilterTextFieldProps =
|
|
53
55
|
muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
54
|
-
? muiTableHeadCellFilterTextFieldProps({ column,
|
|
56
|
+
? muiTableHeadCellFilterTextFieldProps({ column, instance })
|
|
55
57
|
: muiTableHeadCellFilterTextFieldProps;
|
|
56
58
|
|
|
57
59
|
const mcTableHeadCellFilterTextFieldProps =
|
|
58
60
|
columnDef.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
59
61
|
? columnDef.muiTableHeadCellFilterTextFieldProps({
|
|
60
62
|
column,
|
|
61
|
-
|
|
63
|
+
instance,
|
|
62
64
|
})
|
|
63
65
|
: columnDef.muiTableHeadCellFilterTextFieldProps;
|
|
64
66
|
|
|
@@ -74,20 +76,45 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
74
76
|
);
|
|
75
77
|
|
|
76
78
|
const handleChangeDebounced = useCallback(
|
|
77
|
-
debounce(
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
79
|
+
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
80
|
+
if (inputIndex !== undefined) {
|
|
81
|
+
column.setFilterValue((old: [string, string]) => {
|
|
82
|
+
const newFilterValues = old ?? ['', ''];
|
|
83
|
+
newFilterValues[inputIndex] = event.target.value;
|
|
84
|
+
return newFilterValues;
|
|
85
|
+
});
|
|
86
|
+
} else {
|
|
87
|
+
column.setFilterValue(event.target.value ?? undefined);
|
|
88
|
+
}
|
|
89
|
+
onColumnFilterValueChangedDebounced?.({
|
|
90
|
+
column,
|
|
91
|
+
event,
|
|
92
|
+
filterValue: event.target.value,
|
|
93
|
+
});
|
|
94
|
+
columnDef.onColumnFilterValueChangedDebounced?.({
|
|
95
|
+
column,
|
|
96
|
+
event,
|
|
97
|
+
filterValue: event.target.value,
|
|
98
|
+
});
|
|
99
|
+
}, 200),
|
|
88
100
|
[],
|
|
89
101
|
);
|
|
90
102
|
|
|
103
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
104
|
+
setFilterValue(event.target.value);
|
|
105
|
+
handleChangeDebounced(event);
|
|
106
|
+
onColumnFilterValueChanged?.({
|
|
107
|
+
column,
|
|
108
|
+
event,
|
|
109
|
+
filterValue: event.target.value,
|
|
110
|
+
});
|
|
111
|
+
columnDef.onColumnFilterValueChanged?.({
|
|
112
|
+
column,
|
|
113
|
+
event,
|
|
114
|
+
filterValue: event.target.value,
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
91
118
|
const handleFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
92
119
|
setAnchorEl(event.currentTarget);
|
|
93
120
|
};
|
|
@@ -110,12 +137,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
110
137
|
column.setFilterValue(undefined);
|
|
111
138
|
setCurrentFilterFns((prev) => ({
|
|
112
139
|
...prev,
|
|
113
|
-
[header.id]:
|
|
140
|
+
[header.id]: 'fuzzy',
|
|
114
141
|
}));
|
|
115
142
|
};
|
|
116
143
|
|
|
117
144
|
if (columnDef.Filter) {
|
|
118
|
-
return <>{columnDef.Filter?.({ header,
|
|
145
|
+
return <>{columnDef.Filter?.({ header, instance })}</>;
|
|
119
146
|
}
|
|
120
147
|
|
|
121
148
|
const filterId = `mrt-${tableId}-${header.id}-filter-text-field${
|
|
@@ -124,10 +151,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
124
151
|
const filterFn = currentFilterFns?.[header.id];
|
|
125
152
|
const isSelectFilter = !!columnDef.filterSelectOptions;
|
|
126
153
|
const filterChipLabel =
|
|
127
|
-
!(filterFn instanceof Function) &&
|
|
128
|
-
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(
|
|
129
|
-
filterFn as MRT_FILTER_OPTION,
|
|
130
|
-
)
|
|
154
|
+
!(filterFn instanceof Function) && ['empty', 'notEmpty'].includes(filterFn)
|
|
131
155
|
? //@ts-ignore
|
|
132
156
|
localization[
|
|
133
157
|
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
@@ -145,6 +169,9 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
145
169
|
? localization.max
|
|
146
170
|
: '';
|
|
147
171
|
|
|
172
|
+
const allowedColumnFilterOptions =
|
|
173
|
+
columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
|
|
174
|
+
|
|
148
175
|
return (
|
|
149
176
|
<>
|
|
150
177
|
<TextField
|
|
@@ -159,7 +186,9 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
159
186
|
title: filterPlaceholder,
|
|
160
187
|
}}
|
|
161
188
|
helperText={
|
|
162
|
-
!inputIndex
|
|
189
|
+
!inputIndex &&
|
|
190
|
+
(allowedColumnFilterOptions === undefined ||
|
|
191
|
+
(allowedColumnFilterOptions?.length ?? 0) > 0) ? (
|
|
163
192
|
<label htmlFor={filterId}>
|
|
164
193
|
{filterFn instanceof Function
|
|
165
194
|
? localization.filterMode.replace(
|
|
@@ -196,37 +225,37 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
196
225
|
placeholder={
|
|
197
226
|
filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
|
|
198
227
|
}
|
|
199
|
-
onChange={
|
|
200
|
-
setFilterValue(event.target.value);
|
|
201
|
-
handleChangeDebounced(event);
|
|
202
|
-
}}
|
|
228
|
+
onChange={handleChange}
|
|
203
229
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
204
230
|
select={isSelectFilter}
|
|
205
231
|
value={filterValue ?? ''}
|
|
206
232
|
variant="standard"
|
|
207
233
|
InputProps={{
|
|
208
|
-
startAdornment: !isSelectFilter &&
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
startAdornment: !isSelectFilter &&
|
|
235
|
+
!inputIndex &&
|
|
236
|
+
(allowedColumnFilterOptions === undefined ||
|
|
237
|
+
(allowedColumnFilterOptions?.length ?? 0) > 0) && (
|
|
238
|
+
<InputAdornment position="start">
|
|
239
|
+
<Tooltip arrow title={localization.changeFilterMode}>
|
|
240
|
+
<span>
|
|
241
|
+
<IconButton
|
|
242
|
+
aria-label={localization.changeFilterMode}
|
|
243
|
+
onClick={handleFilterMenuOpen}
|
|
244
|
+
size="small"
|
|
245
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
246
|
+
>
|
|
247
|
+
<FilterListIcon />
|
|
248
|
+
</IconButton>
|
|
249
|
+
</span>
|
|
250
|
+
</Tooltip>
|
|
251
|
+
{filterChipLabel && (
|
|
252
|
+
<Chip
|
|
253
|
+
onDelete={handleClearFilterChip}
|
|
254
|
+
label={filterChipLabel}
|
|
255
|
+
/>
|
|
256
|
+
)}
|
|
257
|
+
</InputAdornment>
|
|
258
|
+
),
|
|
230
259
|
endAdornment: !filterChipLabel && (
|
|
231
260
|
<InputAdornment position="end">
|
|
232
261
|
<Tooltip
|
|
@@ -292,7 +321,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
292
321
|
anchorEl={anchorEl}
|
|
293
322
|
header={header}
|
|
294
323
|
setAnchorEl={setAnchorEl}
|
|
295
|
-
|
|
324
|
+
instance={instance}
|
|
296
325
|
/>
|
|
297
326
|
</>
|
|
298
327
|
);
|
|
@@ -17,10 +17,10 @@ import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
|
17
17
|
import { MRT_TableInstance } from '..';
|
|
18
18
|
|
|
19
19
|
interface Props {
|
|
20
|
-
|
|
20
|
+
instance: MRT_TableInstance;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export const MRT_SearchTextField: FC<Props> = ({
|
|
23
|
+
export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
24
24
|
const {
|
|
25
25
|
getState,
|
|
26
26
|
setGlobalFilter,
|
|
@@ -29,23 +29,30 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
29
29
|
tableId,
|
|
30
30
|
localization,
|
|
31
31
|
muiSearchTextFieldProps,
|
|
32
|
-
|
|
32
|
+
onGlobalFilterValueChanged,
|
|
33
|
+
onGlobalFilterValueChangedDebounced,
|
|
33
34
|
},
|
|
34
|
-
} =
|
|
35
|
+
} = instance;
|
|
35
36
|
|
|
36
37
|
const { globalFilter, showGlobalFilter } = getState();
|
|
37
38
|
|
|
38
39
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
39
40
|
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
+
const handleChangeDebounced = useCallback(
|
|
42
43
|
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
43
44
|
setGlobalFilter(event.target.value ?? undefined);
|
|
44
|
-
|
|
45
|
-
},
|
|
45
|
+
onGlobalFilterValueChangedDebounced?.({ event, instance });
|
|
46
|
+
}, 250),
|
|
46
47
|
[],
|
|
47
48
|
);
|
|
48
49
|
|
|
50
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
51
|
+
setSearchValue(event.target.value);
|
|
52
|
+
handleChangeDebounced(event);
|
|
53
|
+
onGlobalFilterValueChanged?.({ event, instance });
|
|
54
|
+
};
|
|
55
|
+
|
|
49
56
|
const handleGlobalFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
50
57
|
setAnchorEl(event.currentTarget);
|
|
51
58
|
};
|
|
@@ -57,7 +64,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
57
64
|
|
|
58
65
|
const textFieldProps =
|
|
59
66
|
muiSearchTextFieldProps instanceof Function
|
|
60
|
-
? muiSearchTextFieldProps({
|
|
67
|
+
? muiSearchTextFieldProps({ instance })
|
|
61
68
|
: muiSearchTextFieldProps;
|
|
62
69
|
|
|
63
70
|
return (
|
|
@@ -65,10 +72,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
65
72
|
<TextField
|
|
66
73
|
id={`mrt-${tableId}-search-text-field`}
|
|
67
74
|
placeholder={localization.search}
|
|
68
|
-
onChange={
|
|
69
|
-
setSearchValue(event.target.value);
|
|
70
|
-
handleChange(event);
|
|
71
|
-
}}
|
|
75
|
+
onChange={handleChange}
|
|
72
76
|
value={searchValue ?? ''}
|
|
73
77
|
variant="standard"
|
|
74
78
|
InputProps={{
|
|
@@ -108,7 +112,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
108
112
|
<MRT_FilterOptionMenu
|
|
109
113
|
anchorEl={anchorEl}
|
|
110
114
|
setAnchorEl={setAnchorEl}
|
|
111
|
-
|
|
115
|
+
instance={instance}
|
|
112
116
|
/>
|
|
113
117
|
</Collapse>
|
|
114
118
|
);
|
|
@@ -5,14 +5,10 @@ import type { MRT_Row, MRT_TableInstance } from '..';
|
|
|
5
5
|
interface Props {
|
|
6
6
|
row?: MRT_Row;
|
|
7
7
|
selectAll?: boolean;
|
|
8
|
-
|
|
8
|
+
instance: MRT_TableInstance;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export const MRT_SelectCheckbox: FC<Props> = ({
|
|
12
|
-
row,
|
|
13
|
-
selectAll,
|
|
14
|
-
tableInstance,
|
|
15
|
-
}) => {
|
|
11
|
+
export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
|
|
16
12
|
const {
|
|
17
13
|
getRowModel,
|
|
18
14
|
getSelectedRowModel,
|
|
@@ -20,29 +16,29 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
20
16
|
options: {
|
|
21
17
|
localization,
|
|
22
18
|
muiSelectCheckboxProps,
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
onRowSelectionChanged,
|
|
20
|
+
onRowSelectAllChanged,
|
|
25
21
|
selectAllMode,
|
|
26
22
|
},
|
|
27
|
-
} =
|
|
23
|
+
} = instance;
|
|
28
24
|
|
|
29
25
|
const { isDensePadding } = getState();
|
|
30
26
|
|
|
31
27
|
const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
32
28
|
if (selectAll) {
|
|
33
29
|
if (selectAllMode === 'all') {
|
|
34
|
-
|
|
30
|
+
instance.getToggleAllRowsSelectedHandler()(event as any);
|
|
35
31
|
} else if (selectAllMode === 'page') {
|
|
36
|
-
|
|
32
|
+
instance.getToggleAllPageRowsSelectedHandler()(event as any);
|
|
37
33
|
}
|
|
38
|
-
|
|
34
|
+
onRowSelectAllChanged?.({
|
|
39
35
|
event,
|
|
40
36
|
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
41
|
-
|
|
37
|
+
instance,
|
|
42
38
|
});
|
|
43
39
|
} else if (row) {
|
|
44
40
|
row?.getToggleSelectedHandler()(event as any);
|
|
45
|
-
|
|
41
|
+
onRowSelectionChanged?.({
|
|
46
42
|
event,
|
|
47
43
|
row,
|
|
48
44
|
selectedRows: event.target.checked
|
|
@@ -50,14 +46,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
50
46
|
: getSelectedRowModel().flatRows.filter(
|
|
51
47
|
(selectedRow) => selectedRow.id !== row.id,
|
|
52
48
|
),
|
|
53
|
-
|
|
49
|
+
instance,
|
|
54
50
|
});
|
|
55
51
|
}
|
|
56
52
|
};
|
|
57
53
|
|
|
58
54
|
const checkboxProps =
|
|
59
55
|
muiSelectCheckboxProps instanceof Function
|
|
60
|
-
? muiSelectCheckboxProps({ isSelectAll: !!selectAll, row,
|
|
56
|
+
? muiSelectCheckboxProps({ isSelectAll: !!selectAll, row, instance })
|
|
61
57
|
: muiSelectCheckboxProps;
|
|
62
58
|
|
|
63
59
|
return (
|
|
@@ -71,13 +67,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
71
67
|
>
|
|
72
68
|
<Checkbox
|
|
73
69
|
checked={
|
|
74
|
-
selectAll
|
|
75
|
-
? tableInstance.getIsAllRowsSelected()
|
|
76
|
-
: row?.getIsSelected()
|
|
70
|
+
selectAll ? instance.getIsAllRowsSelected() : row?.getIsSelected()
|
|
77
71
|
}
|
|
78
72
|
indeterminate={
|
|
79
73
|
selectAll
|
|
80
|
-
?
|
|
74
|
+
? instance.getIsSomeRowsSelected()
|
|
81
75
|
: row?.getIsSomeSelected()
|
|
82
76
|
}
|
|
83
77
|
inputProps={{
|
|
@@ -20,14 +20,14 @@ interface Props {
|
|
|
20
20
|
anchorEl: HTMLElement | null;
|
|
21
21
|
header: MRT_Header;
|
|
22
22
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
23
|
-
|
|
23
|
+
instance: MRT_TableInstance;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
27
27
|
anchorEl,
|
|
28
28
|
header,
|
|
29
29
|
setAnchorEl,
|
|
30
|
-
|
|
30
|
+
instance,
|
|
31
31
|
}) => {
|
|
32
32
|
const {
|
|
33
33
|
getState,
|
|
@@ -56,7 +56,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
56
56
|
localization,
|
|
57
57
|
},
|
|
58
58
|
setShowFilters,
|
|
59
|
-
} =
|
|
59
|
+
} = instance;
|
|
60
60
|
|
|
61
61
|
const { column } = header;
|
|
62
62
|
|
|
@@ -249,7 +249,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
249
249
|
key={2}
|
|
250
250
|
onSelect={handleFilterByColumn}
|
|
251
251
|
setAnchorEl={setFilterMenuAnchorEl}
|
|
252
|
-
|
|
252
|
+
instance={instance}
|
|
253
253
|
/>,
|
|
254
254
|
]}
|
|
255
255
|
{enableGrouping &&
|
|
@@ -377,7 +377,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
377
377
|
isSubMenu
|
|
378
378
|
key={2}
|
|
379
379
|
setAnchorEl={setShowHideColumnsMenuAnchorEl}
|
|
380
|
-
|
|
380
|
+
instance={instance}
|
|
381
381
|
/>,
|
|
382
382
|
]}
|
|
383
383
|
</Menu>
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Menu, MenuItem } from '@mui/material';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
3
|
+
import type {
|
|
4
|
+
MRT_FilterFn,
|
|
5
|
+
MRT_FILTER_OPTION,
|
|
6
|
+
MRT_Header,
|
|
7
|
+
MRT_TableInstance,
|
|
8
|
+
} from '..';
|
|
5
9
|
import {
|
|
6
10
|
between,
|
|
7
11
|
contains,
|
|
@@ -27,7 +31,7 @@ interface Props {
|
|
|
27
31
|
header?: MRT_Header;
|
|
28
32
|
onSelect?: () => void;
|
|
29
33
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
30
|
-
|
|
34
|
+
instance: MRT_TableInstance;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
@@ -35,14 +39,18 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
35
39
|
header,
|
|
36
40
|
onSelect,
|
|
37
41
|
setAnchorEl,
|
|
38
|
-
|
|
42
|
+
instance,
|
|
39
43
|
}) => {
|
|
40
44
|
const {
|
|
41
45
|
getState,
|
|
42
|
-
options: {
|
|
46
|
+
options: {
|
|
47
|
+
enabledGlobalFilterOptions,
|
|
48
|
+
enabledColumnFilterOptions,
|
|
49
|
+
localization,
|
|
50
|
+
},
|
|
43
51
|
setCurrentFilterFns,
|
|
44
52
|
setCurrentGlobalFilterFn,
|
|
45
|
-
} =
|
|
53
|
+
} = instance;
|
|
46
54
|
|
|
47
55
|
const { isDensePadding, currentFilterFns, currentGlobalFilterFn } =
|
|
48
56
|
getState();
|
|
@@ -51,104 +59,103 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
51
59
|
|
|
52
60
|
const { columnDef } = column ?? {};
|
|
53
61
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
fn: Function;
|
|
59
|
-
}[] = useMemo(
|
|
62
|
+
const allowedColumnFilterOptions =
|
|
63
|
+
columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
|
|
64
|
+
|
|
65
|
+
const filterOptions = useMemo(
|
|
60
66
|
() =>
|
|
61
67
|
[
|
|
62
68
|
{
|
|
63
|
-
option:
|
|
69
|
+
option: 'fuzzy',
|
|
64
70
|
label: localization.filterFuzzy,
|
|
65
71
|
divider: false,
|
|
66
72
|
fn: fuzzy,
|
|
67
73
|
},
|
|
68
74
|
{
|
|
69
|
-
option:
|
|
75
|
+
option: 'contains',
|
|
70
76
|
label: localization.filterContains,
|
|
71
77
|
divider: false,
|
|
72
78
|
fn: contains,
|
|
73
79
|
},
|
|
74
80
|
{
|
|
75
|
-
option:
|
|
81
|
+
option: 'startsWith',
|
|
76
82
|
label: localization.filterStartsWith,
|
|
77
83
|
divider: false,
|
|
78
84
|
fn: startsWith,
|
|
79
85
|
},
|
|
80
86
|
{
|
|
81
|
-
option:
|
|
87
|
+
option: 'endsWith',
|
|
82
88
|
label: localization.filterEndsWith,
|
|
83
89
|
divider: true,
|
|
84
90
|
fn: endsWith,
|
|
85
91
|
},
|
|
86
92
|
{
|
|
87
|
-
option:
|
|
93
|
+
option: 'equals',
|
|
88
94
|
label: localization.filterEquals,
|
|
89
95
|
divider: false,
|
|
90
96
|
fn: equals,
|
|
91
97
|
},
|
|
92
98
|
{
|
|
93
|
-
option:
|
|
99
|
+
option: 'notEquals',
|
|
94
100
|
label: localization.filterNotEquals,
|
|
95
101
|
divider: true,
|
|
96
102
|
fn: notEquals,
|
|
97
103
|
},
|
|
98
104
|
{
|
|
99
|
-
option:
|
|
105
|
+
option: 'between',
|
|
100
106
|
label: localization.filterBetween,
|
|
101
107
|
divider: false,
|
|
102
108
|
fn: between,
|
|
103
109
|
},
|
|
104
110
|
{
|
|
105
|
-
option:
|
|
111
|
+
option: 'greaterThan',
|
|
106
112
|
label: localization.filterGreaterThan,
|
|
107
113
|
divider: false,
|
|
108
114
|
fn: greaterThan,
|
|
109
115
|
},
|
|
110
116
|
{
|
|
111
|
-
option:
|
|
117
|
+
option: 'lessThan',
|
|
112
118
|
label: localization.filterLessThan,
|
|
113
119
|
divider: true,
|
|
114
120
|
fn: lessThan,
|
|
115
121
|
},
|
|
116
122
|
{
|
|
117
|
-
option:
|
|
123
|
+
option: 'empty',
|
|
118
124
|
label: localization.filterEmpty,
|
|
119
125
|
divider: false,
|
|
120
126
|
fn: empty,
|
|
121
127
|
},
|
|
122
128
|
{
|
|
123
|
-
option:
|
|
129
|
+
option: 'notEmpty',
|
|
124
130
|
label: localization.filterNotEmpty,
|
|
125
131
|
divider: false,
|
|
126
132
|
fn: notEmpty,
|
|
127
133
|
},
|
|
128
134
|
].filter((filterType) =>
|
|
129
135
|
columnDef
|
|
130
|
-
?
|
|
131
|
-
|
|
136
|
+
? allowedColumnFilterOptions === undefined ||
|
|
137
|
+
allowedColumnFilterOptions?.includes(filterType.option)
|
|
132
138
|
: (!enabledGlobalFilterOptions ||
|
|
133
139
|
enabledGlobalFilterOptions.includes(filterType.option)) &&
|
|
134
|
-
[
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
['fuzzy', 'contains'].includes(filterType.option),
|
|
141
|
+
) as Array<{
|
|
142
|
+
option: MRT_FILTER_OPTION;
|
|
143
|
+
label: string;
|
|
144
|
+
divider: boolean;
|
|
145
|
+
fn: Function;
|
|
146
|
+
}>,
|
|
138
147
|
[],
|
|
139
148
|
);
|
|
140
149
|
|
|
141
|
-
const handleSelectFilterType = (value:
|
|
150
|
+
const handleSelectFilterType = (value: string) => {
|
|
142
151
|
if (header && column) {
|
|
143
152
|
setCurrentFilterFns((prev: { [key: string]: MRT_FilterFn }) => ({
|
|
144
153
|
...prev,
|
|
145
154
|
[header.id]: value,
|
|
146
155
|
}));
|
|
147
|
-
if (
|
|
148
|
-
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(value)
|
|
149
|
-
) {
|
|
156
|
+
if (['empty', 'notEmpty'].includes(value)) {
|
|
150
157
|
column.setFilterValue(' ');
|
|
151
|
-
} else if (value ===
|
|
158
|
+
} else if (value === 'between') {
|
|
152
159
|
column.setFilterValue(['', '']);
|
|
153
160
|
} else {
|
|
154
161
|
column.setFilterValue('');
|
|
@@ -178,10 +185,10 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
178
185
|
<MenuItem
|
|
179
186
|
divider={divider}
|
|
180
187
|
key={index}
|
|
181
|
-
onClick={() => handleSelectFilterType(option)}
|
|
188
|
+
onClick={() => handleSelectFilterType(option as string)}
|
|
182
189
|
selected={option === filterOption || fn === filterOption}
|
|
183
190
|
sx={commonMenuItemStyles}
|
|
184
|
-
value={option}
|
|
191
|
+
value={option as string}
|
|
185
192
|
>
|
|
186
193
|
{label}
|
|
187
194
|
</MenuItem>
|
|
@@ -11,7 +11,7 @@ interface Props {
|
|
|
11
11
|
handleEdit: () => void;
|
|
12
12
|
row: MRT_Row;
|
|
13
13
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
14
|
-
|
|
14
|
+
instance: MRT_TableInstance;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const MRT_RowActionMenu: FC<Props> = ({
|
|
@@ -19,7 +19,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
19
19
|
handleEdit,
|
|
20
20
|
row,
|
|
21
21
|
setAnchorEl,
|
|
22
|
-
|
|
22
|
+
instance,
|
|
23
23
|
}) => {
|
|
24
24
|
const {
|
|
25
25
|
getState,
|
|
@@ -29,7 +29,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
29
29
|
localization,
|
|
30
30
|
renderRowActionMenuItems,
|
|
31
31
|
},
|
|
32
|
-
} =
|
|
32
|
+
} = instance;
|
|
33
33
|
|
|
34
34
|
const { isDensePadding } = getState();
|
|
35
35
|
|
|
@@ -54,7 +54,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
|
|
|
54
54
|
)}
|
|
55
55
|
{renderRowActionMenuItems?.({
|
|
56
56
|
row,
|
|
57
|
-
|
|
57
|
+
instance,
|
|
58
58
|
closeMenu: () => setAnchorEl(null),
|
|
59
59
|
})}
|
|
60
60
|
</Menu>
|