material-react-table 0.11.0 → 0.12.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/dist/MaterialReactTable.d.ts +65 -51
- package/dist/filtersFNs.d.ts +2 -2
- package/dist/material-react-table.cjs.development.js +116 -61
- 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 +116 -61
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_TableRoot.d.ts +0 -1
- package/package.json +17 -17
- package/src/MaterialReactTable.tsx +91 -66
- package/src/body/MRT_TableBodyCell.tsx +2 -2
- package/src/body/MRT_TableBodyRow.tsx +2 -2
- package/src/body/MRT_TableDetailPanel.tsx +2 -2
- package/src/buttons/MRT_EditActionButtons.tsx +2 -2
- package/src/buttons/MRT_ExpandButton.tsx +2 -2
- package/src/buttons/MRT_FullScreenToggleButton.tsx +2 -2
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +2 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +2 -2
- package/src/filtersFNs.ts +2 -2
- package/src/inputs/MRT_EditCellTextField.tsx +6 -6
- package/src/inputs/MRT_FilterTextField.tsx +72 -39
- package/src/inputs/MRT_SearchTextField.tsx +12 -8
- package/src/inputs/MRT_SelectCheckbox.tsx +4 -4
- package/src/menus/MRT_FilterOptionMenu.tsx +10 -3
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +2 -2
- package/src/table/MRT_TableRoot.tsx +90 -73
|
@@ -32,10 +32,13 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
32
32
|
const {
|
|
33
33
|
getState,
|
|
34
34
|
options: {
|
|
35
|
+
enabledColumnFilterOptions,
|
|
35
36
|
icons: { FilterListIcon, CloseIcon },
|
|
36
|
-
tableId,
|
|
37
37
|
localization,
|
|
38
38
|
muiTableHeadCellFilterTextFieldProps,
|
|
39
|
+
onColumnFilterValueChanged,
|
|
40
|
+
onColumnFilterValueChangedDebounced,
|
|
41
|
+
tableId,
|
|
39
42
|
},
|
|
40
43
|
setCurrentFilterFns,
|
|
41
44
|
} = instance;
|
|
@@ -73,20 +76,45 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
73
76
|
);
|
|
74
77
|
|
|
75
78
|
const handleChangeDebounced = useCallback(
|
|
76
|
-
debounce(
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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),
|
|
87
100
|
[],
|
|
88
101
|
);
|
|
89
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
|
+
|
|
90
118
|
const handleFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
91
119
|
setAnchorEl(event.currentTarget);
|
|
92
120
|
};
|
|
@@ -141,6 +169,9 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
141
169
|
? localization.max
|
|
142
170
|
: '';
|
|
143
171
|
|
|
172
|
+
const allowedColumnFilterOptions =
|
|
173
|
+
columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
|
|
174
|
+
|
|
144
175
|
return (
|
|
145
176
|
<>
|
|
146
177
|
<TextField
|
|
@@ -155,7 +186,9 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
155
186
|
title: filterPlaceholder,
|
|
156
187
|
}}
|
|
157
188
|
helperText={
|
|
158
|
-
!inputIndex
|
|
189
|
+
!inputIndex &&
|
|
190
|
+
(allowedColumnFilterOptions === undefined ||
|
|
191
|
+
(allowedColumnFilterOptions?.length ?? 0) > 0) ? (
|
|
159
192
|
<label htmlFor={filterId}>
|
|
160
193
|
{filterFn instanceof Function
|
|
161
194
|
? localization.filterMode.replace(
|
|
@@ -192,37 +225,37 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
192
225
|
placeholder={
|
|
193
226
|
filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
|
|
194
227
|
}
|
|
195
|
-
onChange={
|
|
196
|
-
setFilterValue(event.target.value);
|
|
197
|
-
handleChangeDebounced(event);
|
|
198
|
-
}}
|
|
228
|
+
onChange={handleChange}
|
|
199
229
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
200
230
|
select={isSelectFilter}
|
|
201
231
|
value={filterValue ?? ''}
|
|
202
232
|
variant="standard"
|
|
203
233
|
InputProps={{
|
|
204
|
-
startAdornment: !isSelectFilter &&
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
+
),
|
|
226
259
|
endAdornment: !filterChipLabel && (
|
|
227
260
|
<InputAdornment position="end">
|
|
228
261
|
<Tooltip
|
|
@@ -29,7 +29,8 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
29
29
|
tableId,
|
|
30
30
|
localization,
|
|
31
31
|
muiSearchTextFieldProps,
|
|
32
|
-
|
|
32
|
+
onGlobalFilterValueChanged,
|
|
33
|
+
onGlobalFilterValueChangedDebounced,
|
|
33
34
|
},
|
|
34
35
|
} = instance;
|
|
35
36
|
|
|
@@ -38,14 +39,20 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
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
|
};
|
|
@@ -65,10 +72,7 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
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={{
|
|
@@ -16,8 +16,8 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
|
|
|
16
16
|
options: {
|
|
17
17
|
localization,
|
|
18
18
|
muiSelectCheckboxProps,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
onRowSelectionChanged,
|
|
20
|
+
onRowSelectAllChanged,
|
|
21
21
|
selectAllMode,
|
|
22
22
|
},
|
|
23
23
|
} = instance;
|
|
@@ -31,14 +31,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, instance }) => {
|
|
|
31
31
|
} else if (selectAllMode === 'page') {
|
|
32
32
|
instance.getToggleAllPageRowsSelectedHandler()(event as any);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
onRowSelectAllChanged?.({
|
|
35
35
|
event,
|
|
36
36
|
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
37
37
|
instance,
|
|
38
38
|
});
|
|
39
39
|
} else if (row) {
|
|
40
40
|
row?.getToggleSelectedHandler()(event as any);
|
|
41
|
-
|
|
41
|
+
onRowSelectionChanged?.({
|
|
42
42
|
event,
|
|
43
43
|
row,
|
|
44
44
|
selectedRows: event.target.checked
|
|
@@ -43,7 +43,11 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
43
43
|
}) => {
|
|
44
44
|
const {
|
|
45
45
|
getState,
|
|
46
|
-
options: {
|
|
46
|
+
options: {
|
|
47
|
+
enabledGlobalFilterOptions,
|
|
48
|
+
enabledColumnFilterOptions,
|
|
49
|
+
localization,
|
|
50
|
+
},
|
|
47
51
|
setCurrentFilterFns,
|
|
48
52
|
setCurrentGlobalFilterFn,
|
|
49
53
|
} = instance;
|
|
@@ -55,6 +59,9 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
55
59
|
|
|
56
60
|
const { columnDef } = column ?? {};
|
|
57
61
|
|
|
62
|
+
const allowedColumnFilterOptions =
|
|
63
|
+
columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
|
|
64
|
+
|
|
58
65
|
const filterOptions = useMemo(
|
|
59
66
|
() =>
|
|
60
67
|
[
|
|
@@ -126,8 +133,8 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
126
133
|
},
|
|
127
134
|
].filter((filterType) =>
|
|
128
135
|
columnDef
|
|
129
|
-
?
|
|
130
|
-
|
|
136
|
+
? allowedColumnFilterOptions === undefined ||
|
|
137
|
+
allowedColumnFilterOptions?.includes(filterType.option)
|
|
131
138
|
: (!enabledGlobalFilterOptions ||
|
|
132
139
|
enabledGlobalFilterOptions.includes(filterType.option)) &&
|
|
133
140
|
['fuzzy', 'contains'].includes(filterType.option),
|
|
@@ -21,7 +21,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
21
21
|
}) => {
|
|
22
22
|
const {
|
|
23
23
|
getState,
|
|
24
|
-
options: { enableColumnOrdering,
|
|
24
|
+
options: { enableColumnOrdering, onColumnVisibilityChanged },
|
|
25
25
|
setColumnOrder,
|
|
26
26
|
} = instance;
|
|
27
27
|
|
|
@@ -56,7 +56,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
56
56
|
} else {
|
|
57
57
|
column.toggleVisibility();
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
onColumnVisibilityChanged?.({
|
|
60
60
|
column,
|
|
61
61
|
columnVisibility,
|
|
62
62
|
instance,
|
|
@@ -153,87 +153,104 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
153
153
|
[],
|
|
154
154
|
);
|
|
155
155
|
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
[
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
156
|
+
const [leadingDisplayColumns, trailingDisplayColumns] = useMemo(() => {
|
|
157
|
+
const leadingDisplayColumns = [
|
|
158
|
+
showActionColumn &&
|
|
159
|
+
createDisplayColumn(table, {
|
|
160
|
+
Cell: ({ cell }) => (
|
|
161
|
+
<MRT_ToggleRowActionMenuButton
|
|
162
|
+
row={cell.row as any}
|
|
163
|
+
instance={instance}
|
|
164
|
+
/>
|
|
165
|
+
),
|
|
166
|
+
header: props.localization?.actions,
|
|
167
|
+
id: 'mrt-row-actions',
|
|
168
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
169
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
170
|
+
size: 70,
|
|
171
|
+
}),
|
|
172
|
+
showExpandColumn &&
|
|
173
|
+
createDisplayColumn(table, {
|
|
174
|
+
Cell: ({ cell }) => (
|
|
175
|
+
<MRT_ExpandButton row={cell.row as any} instance={instance} />
|
|
176
|
+
),
|
|
177
|
+
Header: () =>
|
|
178
|
+
props.enableExpandAll ? (
|
|
179
|
+
<MRT_ExpandAllButton instance={instance} />
|
|
180
|
+
) : null,
|
|
181
|
+
header: props.localization?.expand,
|
|
182
|
+
id: 'mrt-expand',
|
|
183
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
184
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
185
|
+
size: 50,
|
|
186
|
+
}),
|
|
187
|
+
props.enableRowSelection &&
|
|
188
|
+
createDisplayColumn(table, {
|
|
189
|
+
Cell: ({ cell }) => (
|
|
190
|
+
<MRT_SelectCheckbox row={cell.row as any} instance={instance} />
|
|
191
|
+
),
|
|
192
|
+
Header: () =>
|
|
193
|
+
props.enableSelectAll ? (
|
|
194
|
+
<MRT_SelectCheckbox selectAll instance={instance} />
|
|
195
|
+
) : null,
|
|
196
|
+
header: props.localization?.select,
|
|
197
|
+
id: 'mrt-select',
|
|
198
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
199
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
200
|
+
size: 50,
|
|
201
|
+
}),
|
|
202
|
+
props.enableRowNumbers &&
|
|
203
|
+
createDisplayColumn(table, {
|
|
204
|
+
Cell: ({ cell }) => cell.row.index + 1,
|
|
205
|
+
Header: () => props.localization?.rowNumber,
|
|
206
|
+
header: props.localization?.rowNumbers,
|
|
207
|
+
id: 'mrt-row-numbers',
|
|
208
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
209
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
210
|
+
size: 50,
|
|
211
|
+
}),
|
|
212
|
+
].filter(Boolean) as MRT_ColumnDef<D>[];
|
|
213
|
+
|
|
214
|
+
const trailingDisplayColumns = [] as MRT_ColumnDef<D>[];
|
|
215
|
+
|
|
216
|
+
if (props.enableRowActions && props.positionActionsColumn === 'last') {
|
|
217
|
+
trailingDisplayColumns.push(
|
|
218
|
+
...leadingDisplayColumns.splice(
|
|
219
|
+
leadingDisplayColumns.findIndex(
|
|
220
|
+
(col) => col.id === 'mrt-row-actions',
|
|
221
|
+
),
|
|
222
|
+
1,
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return [leadingDisplayColumns, trailingDisplayColumns];
|
|
228
|
+
}, [
|
|
229
|
+
props.editingMode,
|
|
230
|
+
props.enableEditing,
|
|
231
|
+
props.enableExpandAll,
|
|
232
|
+
props.enableExpanding,
|
|
233
|
+
props.enableGrouping,
|
|
234
|
+
props.enableRowActions,
|
|
235
|
+
props.enableRowNumbers,
|
|
236
|
+
props.enableRowSelection,
|
|
237
|
+
props.enableSelectAll,
|
|
238
|
+
props.localization,
|
|
239
|
+
props.muiTableBodyCellProps,
|
|
240
|
+
props.muiTableHeadCellProps,
|
|
241
|
+
props.positionActionsColumn,
|
|
242
|
+
table,
|
|
243
|
+
]);
|
|
228
244
|
|
|
229
245
|
const columns = useMemo(
|
|
230
246
|
() => [
|
|
231
|
-
...
|
|
247
|
+
...leadingDisplayColumns,
|
|
232
248
|
...props.columns.map((column) =>
|
|
233
249
|
column.columns
|
|
234
250
|
? createGroup(table, column as any, currentFilterFns)
|
|
235
251
|
: createDataColumn(table, column as any, currentFilterFns),
|
|
236
252
|
),
|
|
253
|
+
...trailingDisplayColumns,
|
|
237
254
|
],
|
|
238
255
|
[table, props.columns, currentFilterFns],
|
|
239
256
|
);
|