material-react-table 0.38.4 → 0.39.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/cjs/MaterialReactTable.d.ts +25 -4
- package/dist/cjs/column.utils.d.ts +1 -0
- package/dist/cjs/index.js +41 -30
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/menus/MRT_FilterOptionMenu.d.ts +2 -7
- package/dist/esm/MaterialReactTable.d.ts +25 -4
- package/dist/esm/column.utils.d.ts +1 -0
- package/dist/esm/material-react-table.esm.js +41 -30
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/menus/MRT_FilterOptionMenu.d.ts +2 -7
- package/dist/index.d.ts +26 -5
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +41 -7
- package/src/column.utils.ts +1 -1
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +3 -2
- package/src/inputs/MRT_FilterTextField.tsx +5 -8
- package/src/inputs/MRT_GlobalFilterTextField.tsx +2 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +3 -3
- package/src/menus/MRT_FilterOptionMenu.tsx +50 -33
- package/src/table/MRT_TableRoot.tsx +3 -4
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
2
|
+
import type { MRT_Header, MRT_InternalFilterOption, MRT_TableInstance } from '..';
|
|
3
3
|
import { MRT_Localization } from '../localization';
|
|
4
|
-
export declare const
|
|
5
|
-
option: string;
|
|
6
|
-
symbol: string;
|
|
7
|
-
label: string;
|
|
8
|
-
divider: boolean;
|
|
9
|
-
}[];
|
|
4
|
+
export declare const mrtFilterOptions: (localization: MRT_Localization) => MRT_InternalFilterOption[];
|
|
10
5
|
interface Props<TData extends Record<string, any> = {}> {
|
|
11
6
|
anchorEl: HTMLElement | null;
|
|
12
7
|
header?: MRT_Header;
|
package/dist/index.d.ts
CHANGED
|
@@ -346,7 +346,7 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
346
346
|
enableClickToCopy?: boolean;
|
|
347
347
|
enableColumnActions?: boolean;
|
|
348
348
|
enableColumnDragging?: boolean;
|
|
349
|
-
|
|
349
|
+
enableColumnFilterModes?: boolean;
|
|
350
350
|
enableColumnOrdering?: boolean;
|
|
351
351
|
enableEditing?: boolean;
|
|
352
352
|
filterFn?: MRT_FilterFn<TData>;
|
|
@@ -408,6 +408,10 @@ 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
|
+
renderColumnFilterModeMenuItems?: ({ table, column, }: {
|
|
412
|
+
table: MRT_TableInstance<TData>;
|
|
413
|
+
column: MRT_Column<TData>;
|
|
414
|
+
}) => ReactNode[];
|
|
411
415
|
sortingFn?: MRT_SortingFn;
|
|
412
416
|
};
|
|
413
417
|
declare type MRT_DefinedColumnDef<TData extends Record<string, any> = {}> = Omit<MRT_ColumnDef<TData>, 'id'> & {
|
|
@@ -441,6 +445,12 @@ declare type MRT_SortingOption = LiteralUnion<string & keyof typeof MRT_SortingF
|
|
|
441
445
|
declare type MRT_SortingFn<TData extends Record<string, any> = {}> = SortingFn<TData> | MRT_SortingOption;
|
|
442
446
|
declare type MRT_FilterOption = LiteralUnion<string & keyof typeof MRT_FilterFns>;
|
|
443
447
|
declare type MRT_FilterFn<TData extends Record<string, any> = {}> = FilterFn<TData> | MRT_FilterOption;
|
|
448
|
+
declare type MRT_InternalFilterOption = {
|
|
449
|
+
option: string;
|
|
450
|
+
symbol: string;
|
|
451
|
+
label: string;
|
|
452
|
+
divider: boolean;
|
|
453
|
+
};
|
|
444
454
|
declare type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row-expand' | 'mrt-row-numbers' | 'mrt-row-select';
|
|
445
455
|
/**
|
|
446
456
|
* `columns` and `data` props are the only required props, but there are over 150 other optional props.
|
|
@@ -464,13 +474,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
464
474
|
enableClickToCopy?: boolean;
|
|
465
475
|
enableColumnActions?: boolean;
|
|
466
476
|
enableColumnDragging?: boolean;
|
|
467
|
-
|
|
477
|
+
enableColumnFilterModes?: boolean;
|
|
468
478
|
enableColumnOrdering?: boolean;
|
|
469
479
|
enableDensityToggle?: boolean;
|
|
470
480
|
enableEditing?: boolean;
|
|
471
481
|
enableExpandAll?: boolean;
|
|
472
482
|
enableFullScreenToggle?: boolean;
|
|
473
|
-
|
|
483
|
+
enableGlobalFilterModes?: boolean;
|
|
474
484
|
enableGlobalFilterRankedResults?: boolean;
|
|
475
485
|
enablePagination?: boolean;
|
|
476
486
|
enableRowActions?: boolean;
|
|
@@ -652,10 +662,21 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
652
662
|
renderBottomToolbarCustomActions?: ({ table, }: {
|
|
653
663
|
table: MRT_TableInstance<TData>;
|
|
654
664
|
}) => ReactNode;
|
|
665
|
+
renderColumnFilterModeMenuItems?: ({ column, internalFilterOptions, onSelectFilterMode, table, }: {
|
|
666
|
+
column: MRT_Column<TData>;
|
|
667
|
+
internalFilterOptions: MRT_InternalFilterOption[];
|
|
668
|
+
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
669
|
+
table: MRT_TableInstance<TData>;
|
|
670
|
+
}) => ReactNode;
|
|
655
671
|
renderDetailPanel?: ({ row, table, }: {
|
|
656
672
|
row: MRT_Row<TData>;
|
|
657
673
|
table: MRT_TableInstance<TData>;
|
|
658
674
|
}) => ReactNode;
|
|
675
|
+
renderGlobalFilterModeMenuItems?: ({ internalFilterOptions, onSelectFilterMode, table, }: {
|
|
676
|
+
internalFilterOptions: MRT_InternalFilterOption[];
|
|
677
|
+
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
678
|
+
table: MRT_TableInstance<TData>;
|
|
679
|
+
}) => ReactNode[];
|
|
659
680
|
renderRowActionMenuItems?: ({ closeMenu, row, table, }: {
|
|
660
681
|
closeMenu: () => void;
|
|
661
682
|
row: MRT_Row<TData>;
|
|
@@ -680,7 +701,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
680
701
|
table: MRT_TableInstance<TData>;
|
|
681
702
|
}) => Partial<Options<HTMLDivElement>>);
|
|
682
703
|
};
|
|
683
|
-
declare const _default: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, editingMode, enableBottomToolbar, enableColumnActions,
|
|
704
|
+
declare const _default: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, editingMode, enableBottomToolbar, enableColumnActions, enableColumnFilterModes, enableColumnFilters, enableColumnOrdering, enableColumnResizing, enableDensityToggle, enableExpandAll, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableGlobalFilterModes, enableGlobalFilterRankedResults, enableGrouping, enableHiding, enableMultiRowSelection, enableMultiSort, enablePagination, enablePinning, enableRowSelection, enableSelectAll, enableSorting, enableStickyHeader, enableTableFooter, enableTableHead, enableToolbarInternalActions, enableTopToolbar, filterFns, icons, localization, positionActionsColumn, positionExpandColumn, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, rowNumberMode, selectAllMode, sortingFns, ...rest }: MaterialReactTableProps<TData>) => JSX.Element;
|
|
684
705
|
|
|
685
706
|
interface Props$6<TData extends Record<string, any> = {}> {
|
|
686
707
|
cell: MRT_Cell<TData>;
|
|
@@ -719,4 +740,4 @@ interface Props<TData extends Record<string, any> = {}> extends IconButtonProps
|
|
|
719
740
|
}
|
|
720
741
|
declare const MRT_ToggleGlobalFilterButton: <TData extends Record<string, any> = {}>({ table, ...rest }: Props<TData>) => JSX.Element;
|
|
721
742
|
|
|
722
|
-
export { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MaterialReactTableProps, _default as default };
|
|
743
|
+
export { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_InternalFilterOption, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MaterialReactTableProps, _default as default };
|
package/package.json
CHANGED
|
@@ -260,7 +260,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
260
260
|
enableClickToCopy?: boolean;
|
|
261
261
|
enableColumnActions?: boolean;
|
|
262
262
|
enableColumnDragging?: boolean;
|
|
263
|
-
|
|
263
|
+
enableColumnFilterModes?: boolean;
|
|
264
264
|
enableColumnOrdering?: boolean;
|
|
265
265
|
enableEditing?: boolean;
|
|
266
266
|
filterFn?: MRT_FilterFn<TData>;
|
|
@@ -362,6 +362,13 @@ 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
|
+
renderColumnFilterModeMenuItems?: ({
|
|
366
|
+
table,
|
|
367
|
+
column,
|
|
368
|
+
}: {
|
|
369
|
+
table: MRT_TableInstance<TData>;
|
|
370
|
+
column: MRT_Column<TData>;
|
|
371
|
+
}) => ReactNode[];
|
|
365
372
|
sortingFn?: MRT_SortingFn;
|
|
366
373
|
};
|
|
367
374
|
|
|
@@ -432,6 +439,13 @@ export type MRT_FilterFn<TData extends Record<string, any> = {}> =
|
|
|
432
439
|
| FilterFn<TData>
|
|
433
440
|
| MRT_FilterOption;
|
|
434
441
|
|
|
442
|
+
export type MRT_InternalFilterOption = {
|
|
443
|
+
option: string;
|
|
444
|
+
symbol: string;
|
|
445
|
+
label: string;
|
|
446
|
+
divider: boolean;
|
|
447
|
+
};
|
|
448
|
+
|
|
435
449
|
export type MRT_DisplayColumnIds =
|
|
436
450
|
| 'mrt-row-actions'
|
|
437
451
|
| 'mrt-row-drag'
|
|
@@ -472,13 +486,13 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
472
486
|
enableClickToCopy?: boolean;
|
|
473
487
|
enableColumnActions?: boolean;
|
|
474
488
|
enableColumnDragging?: boolean;
|
|
475
|
-
|
|
489
|
+
enableColumnFilterModes?: boolean;
|
|
476
490
|
enableColumnOrdering?: boolean;
|
|
477
491
|
enableDensityToggle?: boolean;
|
|
478
492
|
enableEditing?: boolean;
|
|
479
493
|
enableExpandAll?: boolean;
|
|
480
494
|
enableFullScreenToggle?: boolean;
|
|
481
|
-
|
|
495
|
+
enableGlobalFilterModes?: boolean;
|
|
482
496
|
enableGlobalFilterRankedResults?: boolean;
|
|
483
497
|
enablePagination?: boolean;
|
|
484
498
|
enableRowActions?: boolean;
|
|
@@ -768,6 +782,17 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
768
782
|
}: {
|
|
769
783
|
table: MRT_TableInstance<TData>;
|
|
770
784
|
}) => ReactNode;
|
|
785
|
+
renderColumnFilterModeMenuItems?: ({
|
|
786
|
+
column,
|
|
787
|
+
internalFilterOptions,
|
|
788
|
+
onSelectFilterMode,
|
|
789
|
+
table,
|
|
790
|
+
}: {
|
|
791
|
+
column: MRT_Column<TData>;
|
|
792
|
+
internalFilterOptions: MRT_InternalFilterOption[];
|
|
793
|
+
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
794
|
+
table: MRT_TableInstance<TData>;
|
|
795
|
+
}) => ReactNode;
|
|
771
796
|
renderDetailPanel?: ({
|
|
772
797
|
row,
|
|
773
798
|
table,
|
|
@@ -775,6 +800,15 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
775
800
|
row: MRT_Row<TData>;
|
|
776
801
|
table: MRT_TableInstance<TData>;
|
|
777
802
|
}) => ReactNode;
|
|
803
|
+
renderGlobalFilterModeMenuItems?: ({
|
|
804
|
+
internalFilterOptions,
|
|
805
|
+
onSelectFilterMode,
|
|
806
|
+
table,
|
|
807
|
+
}: {
|
|
808
|
+
internalFilterOptions: MRT_InternalFilterOption[];
|
|
809
|
+
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
|
810
|
+
table: MRT_TableInstance<TData>;
|
|
811
|
+
}) => ReactNode[];
|
|
778
812
|
renderRowActionMenuItems?: ({
|
|
779
813
|
closeMenu,
|
|
780
814
|
row,
|
|
@@ -831,7 +865,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
831
865
|
editingMode = 'modal',
|
|
832
866
|
enableBottomToolbar = true,
|
|
833
867
|
enableColumnActions = true,
|
|
834
|
-
|
|
868
|
+
enableColumnFilterModes = false,
|
|
835
869
|
enableColumnFilters = true,
|
|
836
870
|
enableColumnOrdering = false,
|
|
837
871
|
enableColumnResizing = false,
|
|
@@ -840,7 +874,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
840
874
|
enableFilters = true,
|
|
841
875
|
enableFullScreenToggle = true,
|
|
842
876
|
enableGlobalFilter = true,
|
|
843
|
-
|
|
877
|
+
enableGlobalFilterModes = false,
|
|
844
878
|
enableGlobalFilterRankedResults = true,
|
|
845
879
|
enableGrouping = false,
|
|
846
880
|
enableHiding = true,
|
|
@@ -878,7 +912,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
878
912
|
editingMode={editingMode}
|
|
879
913
|
enableBottomToolbar={enableBottomToolbar}
|
|
880
914
|
enableColumnActions={enableColumnActions}
|
|
881
|
-
|
|
915
|
+
enableColumnFilterModes={enableColumnFilterModes}
|
|
882
916
|
enableColumnFilters={enableColumnFilters}
|
|
883
917
|
enableColumnOrdering={enableColumnOrdering}
|
|
884
918
|
enableColumnResizing={enableColumnResizing}
|
|
@@ -887,7 +921,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
887
921
|
enableFilters={enableFilters}
|
|
888
922
|
enableFullScreenToggle={enableFullScreenToggle}
|
|
889
923
|
enableGlobalFilter={enableGlobalFilter}
|
|
890
|
-
|
|
924
|
+
enableGlobalFilterModes={enableGlobalFilterModes}
|
|
891
925
|
enableGlobalFilterRankedResults={enableGlobalFilterRankedResults}
|
|
892
926
|
enableGrouping={enableGrouping}
|
|
893
927
|
enableHiding={enableHiding}
|
package/src/column.utils.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const defaultDisplayColumnDefOptions = {
|
|
|
25
25
|
enableSorting: false,
|
|
26
26
|
} as Partial<MRT_ColumnDef>;
|
|
27
27
|
|
|
28
|
-
const getColumnId = <TData extends Record<string, any> = {}>(
|
|
28
|
+
export const getColumnId = <TData extends Record<string, any> = {}>(
|
|
29
29
|
columnDef: MRT_ColumnDef<TData>,
|
|
30
30
|
): string =>
|
|
31
31
|
columnDef.id ?? columnDef.accessorKey?.toString?.() ?? columnDef.header;
|
|
@@ -14,13 +14,14 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
|
14
14
|
table,
|
|
15
15
|
}) => {
|
|
16
16
|
const { getState } = table;
|
|
17
|
-
const {
|
|
17
|
+
const { showColumnFilters } = getState();
|
|
18
18
|
const { column } = header;
|
|
19
|
+
const { columnDef } = column;
|
|
19
20
|
|
|
20
21
|
return (
|
|
21
22
|
<Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
|
|
22
23
|
{['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
23
|
-
|
|
24
|
+
columnDef._filterFn,
|
|
24
25
|
) ? (
|
|
25
26
|
<MRT_FilterRangeFields header={header} table={table} />
|
|
26
27
|
) : (
|
|
@@ -33,9 +33,8 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
33
33
|
table,
|
|
34
34
|
}) => {
|
|
35
35
|
const {
|
|
36
|
-
getState,
|
|
37
36
|
options: {
|
|
38
|
-
|
|
37
|
+
enableColumnFilterModes,
|
|
39
38
|
columnFilterModeOptions,
|
|
40
39
|
icons: { FilterListIcon, CloseIcon },
|
|
41
40
|
localization,
|
|
@@ -46,7 +45,6 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
46
45
|
} = table;
|
|
47
46
|
const { column } = header;
|
|
48
47
|
const { columnDef } = column;
|
|
49
|
-
const { columnFilterFns } = getState();
|
|
50
48
|
|
|
51
49
|
const mTableHeadCellFilterTextFieldProps =
|
|
52
50
|
muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
@@ -78,8 +76,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
78
76
|
const isTextboxFilter =
|
|
79
77
|
columnDef.filterVariant === 'text' ||
|
|
80
78
|
(!isSelectFilter && !isMultiSelectFilter);
|
|
81
|
-
|
|
82
|
-
const currentFilterOption = columnFilterFns?.[header.id];
|
|
79
|
+
const currentFilterOption = columnDef._filterFn;
|
|
83
80
|
const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
|
|
84
81
|
? //@ts-ignore
|
|
85
82
|
localization[
|
|
@@ -99,8 +96,8 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
99
96
|
const allowedColumnFilterOptions =
|
|
100
97
|
columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
|
|
101
98
|
const showChangeModeButton =
|
|
102
|
-
|
|
103
|
-
columnDef.
|
|
99
|
+
enableColumnFilterModes &&
|
|
100
|
+
columnDef.enableColumnFilterModes !== false &&
|
|
104
101
|
!rangeFilterIndex &&
|
|
105
102
|
(allowedColumnFilterOptions === undefined ||
|
|
106
103
|
!!allowedColumnFilterOptions?.length);
|
|
@@ -299,7 +296,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
299
296
|
}}
|
|
300
297
|
sx={(theme) => ({
|
|
301
298
|
p: 0,
|
|
302
|
-
minWidth: !filterChipLabel ? '
|
|
299
|
+
minWidth: !filterChipLabel ? '120px' : 'auto',
|
|
303
300
|
width: '100%',
|
|
304
301
|
'& .MuiSelect-icon': {
|
|
305
302
|
mr: '1.5rem',
|
|
@@ -23,7 +23,7 @@ export const MRT_GlobalFilterTextField = <
|
|
|
23
23
|
getState,
|
|
24
24
|
setGlobalFilter,
|
|
25
25
|
options: {
|
|
26
|
-
|
|
26
|
+
enableGlobalFilterModes,
|
|
27
27
|
icons: { SearchIcon, CloseIcon },
|
|
28
28
|
localization,
|
|
29
29
|
muiSearchTextFieldProps,
|
|
@@ -69,7 +69,7 @@ export const MRT_GlobalFilterTextField = <
|
|
|
69
69
|
value={searchValue ?? ''}
|
|
70
70
|
variant="standard"
|
|
71
71
|
InputProps={{
|
|
72
|
-
startAdornment:
|
|
72
|
+
startAdornment: enableGlobalFilterModes ? (
|
|
73
73
|
<InputAdornment position="start">
|
|
74
74
|
<Tooltip arrow title={localization.changeSearchMode}>
|
|
75
75
|
<IconButton
|
|
@@ -34,7 +34,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
34
34
|
toggleAllColumnsVisible,
|
|
35
35
|
setColumnOrder,
|
|
36
36
|
options: {
|
|
37
|
-
|
|
37
|
+
enableColumnFilterModes,
|
|
38
38
|
enableColumnFilters,
|
|
39
39
|
enableColumnResizing,
|
|
40
40
|
enableGrouping,
|
|
@@ -138,8 +138,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
138
138
|
columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
|
|
139
139
|
|
|
140
140
|
const showFilterModeSubMenu =
|
|
141
|
-
|
|
142
|
-
columnDef.
|
|
141
|
+
enableColumnFilterModes &&
|
|
142
|
+
columnDef.enableColumnFilterModes !== false &&
|
|
143
143
|
!isSelectFilter &&
|
|
144
144
|
(allowedColumnFilterOptions === undefined ||
|
|
145
145
|
!!allowedColumnFilterOptions?.length);
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import { Box, Menu, MenuItem } from '@mui/material';
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
MRT_FilterOption,
|
|
5
|
+
MRT_Header,
|
|
6
|
+
MRT_InternalFilterOption,
|
|
7
|
+
MRT_TableInstance,
|
|
8
|
+
} from '..';
|
|
4
9
|
import { MRT_Localization } from '../localization';
|
|
5
10
|
|
|
6
|
-
export const
|
|
11
|
+
export const mrtFilterOptions = (
|
|
7
12
|
localization: MRT_Localization,
|
|
8
|
-
):
|
|
9
|
-
option: string;
|
|
10
|
-
symbol: string;
|
|
11
|
-
label: string;
|
|
12
|
-
divider: boolean;
|
|
13
|
-
}[] => [
|
|
13
|
+
): MRT_InternalFilterOption[] => [
|
|
14
14
|
{
|
|
15
15
|
option: 'fuzzy',
|
|
16
16
|
symbol: '≈',
|
|
@@ -118,31 +118,33 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
|
118
118
|
enabledGlobalFilterOptions,
|
|
119
119
|
columnFilterModeOptions,
|
|
120
120
|
localization,
|
|
121
|
+
renderColumnFilterModeMenuItems,
|
|
122
|
+
renderGlobalFilterModeMenuItems,
|
|
121
123
|
},
|
|
122
124
|
setColumnFilterFns,
|
|
123
125
|
setGlobalFilterFn,
|
|
124
126
|
} = table;
|
|
125
|
-
const {
|
|
127
|
+
const { globalFilterFn, density } = getState();
|
|
126
128
|
const { column } = header ?? {};
|
|
127
129
|
const { columnDef } = column ?? {};
|
|
128
130
|
|
|
129
131
|
const allowedColumnFilterOptions =
|
|
130
132
|
columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
|
|
131
133
|
|
|
132
|
-
const
|
|
134
|
+
const internalFilterOptions = useMemo(
|
|
133
135
|
() =>
|
|
134
|
-
|
|
136
|
+
mrtFilterOptions(localization).filter((filterOption) =>
|
|
135
137
|
columnDef
|
|
136
138
|
? allowedColumnFilterOptions === undefined ||
|
|
137
139
|
allowedColumnFilterOptions?.includes(filterOption.option)
|
|
138
140
|
: (!enabledGlobalFilterOptions ||
|
|
139
141
|
enabledGlobalFilterOptions.includes(filterOption.option)) &&
|
|
140
|
-
['fuzzy', 'contains'].includes(filterOption.option),
|
|
142
|
+
['fuzzy', 'contains', 'startsWith'].includes(filterOption.option),
|
|
141
143
|
),
|
|
142
144
|
[],
|
|
143
145
|
);
|
|
144
146
|
|
|
145
|
-
const
|
|
147
|
+
const handleSelectFilterMode = (option: MRT_FilterOption) => {
|
|
146
148
|
if (header && column) {
|
|
147
149
|
setColumnFilterFns((prev: { [key: string]: any }) => ({
|
|
148
150
|
...prev,
|
|
@@ -162,7 +164,8 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
|
162
164
|
onSelect?.();
|
|
163
165
|
};
|
|
164
166
|
|
|
165
|
-
const filterOption =
|
|
167
|
+
const filterOption =
|
|
168
|
+
!!header && columnDef ? columnDef._filterFn : globalFilterFn;
|
|
166
169
|
|
|
167
170
|
return (
|
|
168
171
|
<Menu
|
|
@@ -174,25 +177,39 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
|
174
177
|
dense: density === 'compact',
|
|
175
178
|
}}
|
|
176
179
|
>
|
|
177
|
-
{
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
180
|
+
{(header && column
|
|
181
|
+
? renderColumnFilterModeMenuItems?.({
|
|
182
|
+
column: column as any,
|
|
183
|
+
internalFilterOptions,
|
|
184
|
+
onSelectFilterMode: handleSelectFilterMode,
|
|
185
|
+
table,
|
|
186
|
+
})
|
|
187
|
+
: renderGlobalFilterModeMenuItems?.({
|
|
188
|
+
internalFilterOptions,
|
|
189
|
+
onSelectFilterMode: handleSelectFilterMode,
|
|
190
|
+
table,
|
|
191
|
+
})) ??
|
|
192
|
+
internalFilterOptions.map(
|
|
193
|
+
({ option, label, divider, symbol }, index) => (
|
|
194
|
+
<MenuItem
|
|
195
|
+
divider={divider}
|
|
196
|
+
key={index}
|
|
197
|
+
onClick={() => handleSelectFilterMode(option as MRT_FilterOption)}
|
|
198
|
+
selected={option === filterOption}
|
|
199
|
+
sx={{
|
|
200
|
+
alignItems: 'center',
|
|
201
|
+
display: 'flex',
|
|
202
|
+
gap: '2ch',
|
|
203
|
+
my: 0,
|
|
204
|
+
py: '6px',
|
|
205
|
+
}}
|
|
206
|
+
value={option}
|
|
207
|
+
>
|
|
208
|
+
<Box sx={{ fontSize: '1.25rem', width: '2ch' }}>{symbol}</Box>
|
|
209
|
+
{label}
|
|
210
|
+
</MenuItem>
|
|
211
|
+
),
|
|
212
|
+
)}
|
|
196
213
|
</Menu>
|
|
197
214
|
);
|
|
198
215
|
};
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
getDefaultColumnFilterFn,
|
|
25
25
|
defaultDisplayColumnDefOptions,
|
|
26
26
|
showExpandColumn,
|
|
27
|
+
getColumnId,
|
|
27
28
|
} from '../column.utils';
|
|
28
29
|
import type {
|
|
29
30
|
MRT_Cell,
|
|
@@ -65,13 +66,11 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
65
66
|
{},
|
|
66
67
|
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef<TData>[]).map(
|
|
67
68
|
(col) => ({
|
|
68
|
-
[
|
|
69
|
+
[getColumnId(col)]:
|
|
69
70
|
col.filterFn instanceof Function
|
|
70
71
|
? col.filterFn.name ?? 'custom'
|
|
71
72
|
: col.filterFn ??
|
|
72
|
-
initialState?.columnFilterFns?.[
|
|
73
|
-
col.id?.toString() ?? col.accessorKey?.toString() ?? ''
|
|
74
|
-
] ??
|
|
73
|
+
initialState?.columnFilterFns?.[getColumnId(col)] ??
|
|
75
74
|
getDefaultColumnFilterFn(col),
|
|
76
75
|
}),
|
|
77
76
|
),
|