material-react-table 0.40.3 → 0.40.6
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/cjs/MaterialReactTable.d.ts +14 -2
- package/dist/cjs/index.js +64 -49
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/menus/MRT_FilterOptionMenu.d.ts +1 -1
- package/dist/esm/MaterialReactTable.d.ts +14 -2
- package/dist/esm/material-react-table.esm.js +65 -50
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/menus/MRT_FilterOptionMenu.d.ts +1 -1
- package/dist/index.d.ts +14 -2
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +25 -3
- package/src/body/MRT_TableBody.tsx +9 -7
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +1 -3
- package/src/inputs/MRT_FilterTextField.tsx +11 -3
- package/src/menus/MRT_ColumnActionMenu.tsx +63 -50
- package/src/menus/MRT_FilterOptionMenu.tsx +9 -3
- package/src/table/MRT_TableRoot.tsx +5 -6
|
@@ -4,7 +4,7 @@ import { MRT_Localization } from '../localization';
|
|
|
4
4
|
export declare const mrtFilterOptions: (localization: MRT_Localization) => MRT_InternalFilterOption[];
|
|
5
5
|
interface Props<TData extends Record<string, any> = {}> {
|
|
6
6
|
anchorEl: HTMLElement | null;
|
|
7
|
-
header?: MRT_Header
|
|
7
|
+
header?: MRT_Header<TData>;
|
|
8
8
|
onSelect?: () => void;
|
|
9
9
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
10
10
|
table: MRT_TableInstance<TData>;
|
package/dist/index.d.ts
CHANGED
|
@@ -408,9 +408,16 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
408
408
|
table: MRT_TableInstance<TData>;
|
|
409
409
|
column: MRT_Column<TData>;
|
|
410
410
|
}) => TableCellProps);
|
|
411
|
-
|
|
411
|
+
renderColumnActionsMenuItems?: ({ closeMenu, column, table, }: {
|
|
412
|
+
closeMenu: () => void;
|
|
413
|
+
column: MRT_Column<TData>;
|
|
412
414
|
table: MRT_TableInstance<TData>;
|
|
415
|
+
}) => ReactNode[];
|
|
416
|
+
renderColumnFilterModeMenuItems?: ({ column, internalFilterOptions, onSelectFilterMode, table, }: {
|
|
413
417
|
column: MRT_Column<TData>;
|
|
418
|
+
internalFilterOptions: MRT_InternalFilterOption[];
|
|
419
|
+
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
420
|
+
table: MRT_TableInstance<TData>;
|
|
414
421
|
}) => ReactNode[];
|
|
415
422
|
sortingFn?: MRT_SortingFn;
|
|
416
423
|
};
|
|
@@ -662,12 +669,17 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
662
669
|
renderBottomToolbarCustomActions?: ({ table, }: {
|
|
663
670
|
table: MRT_TableInstance<TData>;
|
|
664
671
|
}) => ReactNode;
|
|
672
|
+
renderColumnActionsMenuItems?: ({ column, closeMenu, table, }: {
|
|
673
|
+
column: MRT_Column<TData>;
|
|
674
|
+
closeMenu: () => void;
|
|
675
|
+
table: MRT_TableInstance<TData>;
|
|
676
|
+
}) => ReactNode[];
|
|
665
677
|
renderColumnFilterModeMenuItems?: ({ column, internalFilterOptions, onSelectFilterMode, table, }: {
|
|
666
678
|
column: MRT_Column<TData>;
|
|
667
679
|
internalFilterOptions: MRT_InternalFilterOption[];
|
|
668
680
|
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
669
681
|
table: MRT_TableInstance<TData>;
|
|
670
|
-
}) => ReactNode;
|
|
682
|
+
}) => ReactNode[];
|
|
671
683
|
renderDetailPanel?: ({ row, table, }: {
|
|
672
684
|
row: MRT_Row<TData>;
|
|
673
685
|
table: MRT_TableInstance<TData>;
|
package/package.json
CHANGED
|
@@ -362,12 +362,25 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
362
362
|
table: MRT_TableInstance<TData>;
|
|
363
363
|
column: MRT_Column<TData>;
|
|
364
364
|
}) => TableCellProps);
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
renderColumnActionsMenuItems?: ({
|
|
366
|
+
closeMenu,
|
|
367
367
|
column,
|
|
368
|
+
table,
|
|
368
369
|
}: {
|
|
370
|
+
closeMenu: () => void;
|
|
371
|
+
column: MRT_Column<TData>;
|
|
369
372
|
table: MRT_TableInstance<TData>;
|
|
373
|
+
}) => ReactNode[];
|
|
374
|
+
renderColumnFilterModeMenuItems?: ({
|
|
375
|
+
column,
|
|
376
|
+
internalFilterOptions,
|
|
377
|
+
onSelectFilterMode,
|
|
378
|
+
table,
|
|
379
|
+
}: {
|
|
370
380
|
column: MRT_Column<TData>;
|
|
381
|
+
internalFilterOptions: MRT_InternalFilterOption[];
|
|
382
|
+
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
383
|
+
table: MRT_TableInstance<TData>;
|
|
371
384
|
}) => ReactNode[];
|
|
372
385
|
sortingFn?: MRT_SortingFn;
|
|
373
386
|
};
|
|
@@ -782,6 +795,15 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
782
795
|
}: {
|
|
783
796
|
table: MRT_TableInstance<TData>;
|
|
784
797
|
}) => ReactNode;
|
|
798
|
+
renderColumnActionsMenuItems?: ({
|
|
799
|
+
column,
|
|
800
|
+
closeMenu,
|
|
801
|
+
table,
|
|
802
|
+
}: {
|
|
803
|
+
column: MRT_Column<TData>;
|
|
804
|
+
closeMenu: () => void;
|
|
805
|
+
table: MRT_TableInstance<TData>;
|
|
806
|
+
}) => ReactNode[];
|
|
785
807
|
renderColumnFilterModeMenuItems?: ({
|
|
786
808
|
column,
|
|
787
809
|
internalFilterOptions,
|
|
@@ -792,7 +814,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
792
814
|
internalFilterOptions: MRT_InternalFilterOption[];
|
|
793
815
|
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
794
816
|
table: MRT_TableInstance<TData>;
|
|
795
|
-
}) => ReactNode;
|
|
817
|
+
}) => ReactNode[];
|
|
796
818
|
renderDetailPanel?: ({
|
|
797
819
|
row,
|
|
798
820
|
table,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC, RefObject,
|
|
1
|
+
import React, { FC, RefObject, useMemo } from 'react';
|
|
2
2
|
import { useVirtual } from 'react-virtual'; //stuck on v2 for now
|
|
3
3
|
// import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
|
|
4
4
|
import { TableBody } from '@mui/material';
|
|
@@ -20,9 +20,11 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
20
20
|
enableGlobalFilterRankedResults,
|
|
21
21
|
enablePagination,
|
|
22
22
|
enableRowVirtualization,
|
|
23
|
+
manualFiltering,
|
|
24
|
+
manualSorting,
|
|
23
25
|
muiTableBodyProps,
|
|
24
|
-
virtualizerProps,
|
|
25
26
|
virtualizerInstanceRef,
|
|
27
|
+
virtualizerProps,
|
|
26
28
|
},
|
|
27
29
|
} = table;
|
|
28
30
|
const { globalFilter, pagination, sorting } = getState();
|
|
@@ -41,6 +43,8 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
41
43
|
if (
|
|
42
44
|
enableGlobalFilterRankedResults &&
|
|
43
45
|
globalFilter &&
|
|
46
|
+
!manualFiltering &&
|
|
47
|
+
!manualSorting &&
|
|
44
48
|
!Object.values(sorting).some(Boolean)
|
|
45
49
|
) {
|
|
46
50
|
const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
|
|
@@ -72,11 +76,9 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
72
76
|
})
|
|
73
77
|
: ({} as any);
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}, [virtualizer]);
|
|
79
|
+
if (virtualizerInstanceRef) {
|
|
80
|
+
virtualizerInstanceRef.current = virtualizer;
|
|
81
|
+
}
|
|
80
82
|
|
|
81
83
|
// const virtualizer: Virtualizer = enableRowVirtualization
|
|
82
84
|
// ? useVirtualizer({
|
|
@@ -9,13 +9,11 @@ interface Props {
|
|
|
9
9
|
|
|
10
10
|
export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
11
11
|
const {
|
|
12
|
-
getState,
|
|
13
12
|
options: {
|
|
14
13
|
icons: { FilterAltIcon },
|
|
15
14
|
localization,
|
|
16
15
|
},
|
|
17
16
|
} = table;
|
|
18
|
-
const { columnFilterFns } = getState();
|
|
19
17
|
const { column } = header;
|
|
20
18
|
const { columnDef } = column;
|
|
21
19
|
|
|
@@ -24,7 +22,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
24
22
|
'betweenInclusive',
|
|
25
23
|
'inNumberRange',
|
|
26
24
|
].includes(columnDef._filterFn);
|
|
27
|
-
const currentFilterOption =
|
|
25
|
+
const currentFilterOption = columnDef._filterFn;
|
|
28
26
|
const filterTooltip = localization.filteringByColumn
|
|
29
27
|
.replace('{column}', String(columnDef.header))
|
|
30
28
|
.replace(
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
debounce,
|
|
13
13
|
IconButton,
|
|
14
14
|
InputAdornment,
|
|
15
|
-
ListItemText,
|
|
16
15
|
MenuItem,
|
|
17
16
|
TextField,
|
|
18
17
|
TextFieldProps,
|
|
@@ -323,7 +322,16 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
323
322
|
text = option.text;
|
|
324
323
|
}
|
|
325
324
|
return (
|
|
326
|
-
<MenuItem
|
|
325
|
+
<MenuItem
|
|
326
|
+
key={value}
|
|
327
|
+
sx={{
|
|
328
|
+
display: 'flex',
|
|
329
|
+
m: 0,
|
|
330
|
+
alignItems: 'center',
|
|
331
|
+
gap: '0.5rem',
|
|
332
|
+
}}
|
|
333
|
+
value={value}
|
|
334
|
+
>
|
|
327
335
|
{isMultiSelectFilter && (
|
|
328
336
|
<Checkbox
|
|
329
337
|
checked={(
|
|
@@ -332,7 +340,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
332
340
|
sx={{ mr: '0.5rem' }}
|
|
333
341
|
/>
|
|
334
342
|
)}
|
|
335
|
-
|
|
343
|
+
{text}
|
|
336
344
|
</MenuItem>
|
|
337
345
|
);
|
|
338
346
|
},
|
|
@@ -34,6 +34,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
34
34
|
toggleAllColumnsVisible,
|
|
35
35
|
setColumnOrder,
|
|
36
36
|
options: {
|
|
37
|
+
columnFilterModeOptions,
|
|
37
38
|
enableColumnFilterModes,
|
|
38
39
|
enableColumnFilters,
|
|
39
40
|
enableColumnResizing,
|
|
@@ -41,7 +42,6 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
41
42
|
enableHiding,
|
|
42
43
|
enablePinning,
|
|
43
44
|
enableSorting,
|
|
44
|
-
columnFilterModeOptions,
|
|
45
45
|
icons: {
|
|
46
46
|
ArrowRightIcon,
|
|
47
47
|
ClearAllIcon,
|
|
@@ -55,6 +55,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
55
55
|
VisibilityOffIcon,
|
|
56
56
|
},
|
|
57
57
|
localization,
|
|
58
|
+
renderColumnActionsMenuItems,
|
|
58
59
|
},
|
|
59
60
|
refs: { filterInputRefs },
|
|
60
61
|
setShowFilters,
|
|
@@ -153,55 +154,67 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
153
154
|
dense: density === 'compact',
|
|
154
155
|
}}
|
|
155
156
|
>
|
|
156
|
-
{
|
|
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
|
-
|
|
157
|
+
{columnDef.renderColumnActionsMenuItems?.({
|
|
158
|
+
closeMenu: () => setAnchorEl(null),
|
|
159
|
+
column,
|
|
160
|
+
table,
|
|
161
|
+
}) ??
|
|
162
|
+
renderColumnActionsMenuItems?.({
|
|
163
|
+
closeMenu: () => setAnchorEl(null),
|
|
164
|
+
column,
|
|
165
|
+
table,
|
|
166
|
+
}) ??
|
|
167
|
+
(enableSorting &&
|
|
168
|
+
column.getCanSort() && [
|
|
169
|
+
<MenuItem
|
|
170
|
+
disabled={!column.getIsSorted()}
|
|
171
|
+
key={0}
|
|
172
|
+
onClick={handleClearSort}
|
|
173
|
+
sx={commonMenuItemStyles}
|
|
174
|
+
>
|
|
175
|
+
<Box sx={commonListItemStyles}>
|
|
176
|
+
<ListItemIcon>
|
|
177
|
+
<ClearAllIcon />
|
|
178
|
+
</ListItemIcon>
|
|
179
|
+
{localization.clearSort}
|
|
180
|
+
</Box>
|
|
181
|
+
</MenuItem>,
|
|
182
|
+
<MenuItem
|
|
183
|
+
disabled={column.getIsSorted() === 'asc'}
|
|
184
|
+
key={1}
|
|
185
|
+
onClick={handleSortAsc}
|
|
186
|
+
sx={commonMenuItemStyles}
|
|
187
|
+
>
|
|
188
|
+
<Box sx={commonListItemStyles}>
|
|
189
|
+
<ListItemIcon>
|
|
190
|
+
<SortIcon
|
|
191
|
+
style={{ transform: 'rotate(180deg) scaleX(-1)' }}
|
|
192
|
+
/>
|
|
193
|
+
</ListItemIcon>
|
|
194
|
+
{localization.sortByColumnAsc?.replace(
|
|
195
|
+
'{column}',
|
|
196
|
+
String(columnDef.header),
|
|
197
|
+
)}
|
|
198
|
+
</Box>
|
|
199
|
+
</MenuItem>,
|
|
200
|
+
<MenuItem
|
|
201
|
+
divider={enableColumnFilters || enableGrouping || enableHiding}
|
|
202
|
+
key={2}
|
|
203
|
+
disabled={column.getIsSorted() === 'desc'}
|
|
204
|
+
onClick={handleSortDesc}
|
|
205
|
+
sx={commonMenuItemStyles}
|
|
206
|
+
>
|
|
207
|
+
<Box sx={commonListItemStyles}>
|
|
208
|
+
<ListItemIcon>
|
|
209
|
+
<SortIcon />
|
|
210
|
+
</ListItemIcon>
|
|
211
|
+
{localization.sortByColumnDesc?.replace(
|
|
212
|
+
'{column}',
|
|
213
|
+
String(columnDef.header),
|
|
214
|
+
)}
|
|
215
|
+
</Box>
|
|
216
|
+
</MenuItem>,
|
|
217
|
+
])}
|
|
205
218
|
{enableColumnFilters &&
|
|
206
219
|
column.getCanFilter() &&
|
|
207
220
|
[
|
|
@@ -99,7 +99,7 @@ export const mrtFilterOptions = (
|
|
|
99
99
|
|
|
100
100
|
interface Props<TData extends Record<string, any> = {}> {
|
|
101
101
|
anchorEl: HTMLElement | null;
|
|
102
|
-
header?: MRT_Header
|
|
102
|
+
header?: MRT_Header<TData>;
|
|
103
103
|
onSelect?: () => void;
|
|
104
104
|
setAnchorEl: (anchorEl: HTMLElement | null) => void;
|
|
105
105
|
table: MRT_TableInstance<TData>;
|
|
@@ -177,8 +177,14 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
|
177
177
|
dense: density === 'compact',
|
|
178
178
|
}}
|
|
179
179
|
>
|
|
180
|
-
{(header && column
|
|
181
|
-
? renderColumnFilterModeMenuItems?.({
|
|
180
|
+
{(header && column && columnDef
|
|
181
|
+
? columnDef.renderColumnFilterModeMenuItems?.({
|
|
182
|
+
column: column as any,
|
|
183
|
+
internalFilterOptions,
|
|
184
|
+
onSelectFilterMode: handleSelectFilterMode,
|
|
185
|
+
table,
|
|
186
|
+
}) ??
|
|
187
|
+
renderColumnFilterModeMenuItems?.({
|
|
182
188
|
column: column as any,
|
|
183
189
|
internalFilterOptions,
|
|
184
190
|
onSelectFilterMode: handleSelectFilterMode,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useMemo, useRef, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
TableState,
|
|
4
4
|
getCoreRowModel,
|
|
@@ -189,6 +189,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
189
189
|
props.displayColumnDefOptions,
|
|
190
190
|
props.editingMode,
|
|
191
191
|
props.enableColumnDragging,
|
|
192
|
+
props.enableColumnFilterModes,
|
|
192
193
|
props.enableColumnOrdering,
|
|
193
194
|
props.enableEditing,
|
|
194
195
|
props.enableExpandAll,
|
|
@@ -303,11 +304,9 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
303
304
|
setShowGlobalFilter: props.onShowGlobalFilterChange ?? setShowGlobalFilter,
|
|
304
305
|
} as MRT_TableInstance<TData>;
|
|
305
306
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
310
|
-
}, [table]);
|
|
307
|
+
if (props.tableInstanceRef) {
|
|
308
|
+
props.tableInstanceRef.current = table;
|
|
309
|
+
}
|
|
311
310
|
|
|
312
311
|
return (
|
|
313
312
|
<>
|