material-react-table 0.7.4 → 0.7.5
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 +17 -21
- package/dist/enums.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +84 -80
- 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 +84 -80
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/{MRT_FilterTypeMenu.d.ts → MRT_FilterOptionMenu.d.ts} +1 -1
- package/dist/utils.d.ts +6 -6
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +26 -21
- package/src/enums.ts +1 -1
- package/src/head/MRT_TableHeadCell.tsx +3 -5
- package/src/inputs/MRT_FilterTextField.tsx +16 -16
- package/src/inputs/MRT_SearchTextField.tsx +2 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
- package/src/menus/{MRT_FilterTypeMenu.tsx → MRT_FilterOptionMenu.tsx} +35 -33
- package/src/table/MRT_TableRoot.tsx +26 -26
- package/src/utils.ts +10 -10
package/dist/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
-
import { MRT_ColumnDef,
|
|
2
|
+
import { MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
3
3
|
export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
|
|
4
|
-
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>,
|
|
5
|
-
[key: string]:
|
|
4
|
+
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
5
|
+
[key: string]: MRT_FilterFn<{}>;
|
|
6
6
|
}) => ColumnDef<D>;
|
|
7
|
-
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>,
|
|
8
|
-
[key: string]:
|
|
7
|
+
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
8
|
+
[key: string]: MRT_FilterFn<{}>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.7.
|
|
2
|
+
"version": "0.7.5",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"react": ">=16.8"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@tanstack/react-table": "^8.0.0-alpha.
|
|
100
|
+
"@tanstack/react-table": "^8.0.0-alpha.47",
|
|
101
101
|
"match-sorter": "^6.3.1"
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -31,7 +31,8 @@ import {
|
|
|
31
31
|
Column,
|
|
32
32
|
ColumnDef,
|
|
33
33
|
DefaultGenerics,
|
|
34
|
-
|
|
34
|
+
FilterFn,
|
|
35
|
+
FilterFnOption,
|
|
35
36
|
Header,
|
|
36
37
|
HeaderGroup,
|
|
37
38
|
Options,
|
|
@@ -44,20 +45,21 @@ import {
|
|
|
44
45
|
} from '@tanstack/react-table';
|
|
45
46
|
import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
|
|
46
47
|
import { MRT_Default_Icons, MRT_Icons } from './icons';
|
|
47
|
-
import {
|
|
48
|
+
import { MRT_FILTER_OPTION } from './enums';
|
|
48
49
|
import { MRT_TableRoot } from './table/MRT_TableRoot';
|
|
49
50
|
|
|
50
51
|
export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
|
|
51
52
|
Omit<
|
|
52
53
|
Options<D>,
|
|
53
|
-
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
|
|
54
|
+
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn' | 'filterFns'
|
|
54
55
|
>
|
|
55
56
|
> & {
|
|
56
57
|
columns: MRT_ColumnDef<D>[];
|
|
57
58
|
data: D[];
|
|
59
|
+
expandRowsFn?: (dataRow: D) => D[];
|
|
60
|
+
filterFns?: MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol;
|
|
58
61
|
initialState?: Partial<MRT_TableState<D>>;
|
|
59
62
|
state?: Partial<MRT_TableState<D>>;
|
|
60
|
-
expandRowsFn?: (dataRow: D) => D[];
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
export interface MRT_RowModel<D extends Record<string, any> = {}> {
|
|
@@ -96,17 +98,16 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
96
98
|
options: MaterialReactTableProps<D> & {
|
|
97
99
|
icons: MRT_Icons;
|
|
98
100
|
idPrefix: string;
|
|
99
|
-
filterTypes: { [key in MRT_FILTER_TYPE]: any };
|
|
100
101
|
localization: MRT_Localization;
|
|
101
102
|
};
|
|
102
103
|
setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell<D> | null>>;
|
|
103
104
|
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
|
|
104
|
-
|
|
105
|
+
setCurrentFilterFns: Dispatch<
|
|
105
106
|
SetStateAction<{
|
|
106
|
-
[key: string]:
|
|
107
|
+
[key: string]: MRT_FilterFn<D>;
|
|
107
108
|
}>
|
|
108
109
|
>;
|
|
109
|
-
|
|
110
|
+
setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterFn<D>>>;
|
|
110
111
|
setIsDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
111
112
|
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
112
113
|
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
@@ -119,8 +120,8 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
|
|
|
119
120
|
> & {
|
|
120
121
|
currentEditingCell: MRT_Cell<D> | null;
|
|
121
122
|
currentEditingRow: MRT_Row<D> | null;
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
currentFilterFns: Record<string, string | Function>;
|
|
124
|
+
currentGlobalFilterFn: Record<string, string | Function>;
|
|
124
125
|
isDensePadding: boolean;
|
|
125
126
|
isFullScreen: boolean;
|
|
126
127
|
showFilters: boolean;
|
|
@@ -130,23 +131,19 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
|
|
|
130
131
|
|
|
131
132
|
export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
132
133
|
ColumnDef<D>,
|
|
133
|
-
'header' | 'footer' | 'columns'
|
|
134
|
+
'header' | 'footer' | 'columns' | 'filterFn'
|
|
134
135
|
> & {
|
|
135
136
|
Edit?: ({
|
|
136
137
|
cell,
|
|
137
138
|
tableInstance,
|
|
138
|
-
}:
|
|
139
|
-
{
|
|
139
|
+
}: {
|
|
140
140
|
cell: MRT_Cell<D>;
|
|
141
141
|
tableInstance: MRT_TableInstance<D>;
|
|
142
|
-
// onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
143
142
|
}) => ReactNode;
|
|
144
143
|
Filter?: ({
|
|
145
|
-
// onChange,
|
|
146
144
|
header,
|
|
147
145
|
tableInstance,
|
|
148
146
|
}: {
|
|
149
|
-
// onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
150
147
|
header: MRT_Header<D>;
|
|
151
148
|
tableInstance: MRT_TableInstance<D>;
|
|
152
149
|
}) => ReactNode;
|
|
@@ -176,8 +173,8 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
176
173
|
enableClickToCopy?: boolean;
|
|
177
174
|
enableColumnActions?: boolean;
|
|
178
175
|
enableEditing?: boolean;
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
|
|
177
|
+
filterFn?: MRT_FilterFn;
|
|
181
178
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
182
179
|
footer?: string;
|
|
183
180
|
header: string;
|
|
@@ -322,7 +319,13 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
|
|
|
322
319
|
row: MRT_Row<D>;
|
|
323
320
|
};
|
|
324
321
|
|
|
325
|
-
export type
|
|
322
|
+
export type MRT_FilterFn<D extends Record<string, any> = {}> =
|
|
323
|
+
| FilterFn<D>
|
|
324
|
+
| FilterFnOption<D>
|
|
325
|
+
| MRT_FILTER_OPTION
|
|
326
|
+
| number
|
|
327
|
+
| string
|
|
328
|
+
| symbol;
|
|
326
329
|
|
|
327
330
|
export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
328
331
|
MRT_TableOptions<D> & {
|
|
@@ -344,8 +347,8 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
344
347
|
enableToolbarBottom?: boolean;
|
|
345
348
|
enableToolbarInternalActions?: boolean;
|
|
346
349
|
enableToolbarTop?: boolean;
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
|
|
351
|
+
enabledGlobalFilterOptions?: (MRT_FILTER_OPTION | string)[];
|
|
349
352
|
icons?: Partial<MRT_Icons>;
|
|
350
353
|
idPrefix?: string;
|
|
351
354
|
isLoading?: boolean;
|
|
@@ -757,6 +760,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
757
760
|
|
|
758
761
|
export default <D extends Record<string, any> = {}>({
|
|
759
762
|
autoResetExpanded = false,
|
|
763
|
+
autoResetSorting = false,
|
|
760
764
|
columnResizeMode = 'onEnd',
|
|
761
765
|
editingMode = 'row',
|
|
762
766
|
enableColumnActions = true,
|
|
@@ -789,6 +793,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
789
793
|
}: MaterialReactTableProps<D>) => (
|
|
790
794
|
<MRT_TableRoot
|
|
791
795
|
autoResetExpanded={autoResetExpanded}
|
|
796
|
+
autoResetSorting={autoResetSorting}
|
|
792
797
|
columnResizeMode={columnResizeMode}
|
|
793
798
|
editingMode={editingMode}
|
|
794
799
|
enableColumnActions={enableColumnActions}
|
package/src/enums.ts
CHANGED
|
@@ -60,20 +60,18 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
60
60
|
: localization.sortedByColumnAsc.replace('{column}', column.header)
|
|
61
61
|
: localization.unsorted;
|
|
62
62
|
|
|
63
|
-
const
|
|
63
|
+
const filterFn = getState()?.currentFilterFns?.[header.id];
|
|
64
64
|
|
|
65
65
|
const filterTooltip = !!column.getColumnFilterValue()
|
|
66
66
|
? localization.filteringByColumn
|
|
67
67
|
.replace('{column}', String(column.header))
|
|
68
68
|
.replace(
|
|
69
69
|
'{filterType}',
|
|
70
|
-
|
|
70
|
+
filterFn instanceof Function
|
|
71
71
|
? ''
|
|
72
72
|
: // @ts-ignore
|
|
73
73
|
localization[
|
|
74
|
-
`filter${
|
|
75
|
-
filterType.charAt(0).toUpperCase() + filterType.slice(1)
|
|
76
|
-
}`
|
|
74
|
+
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
77
75
|
],
|
|
78
76
|
)
|
|
79
77
|
.replace('{filterValue}', column.getColumnFilterValue() as string)
|
|
@@ -16,8 +16,8 @@ import {
|
|
|
16
16
|
Tooltip,
|
|
17
17
|
} from '@mui/material';
|
|
18
18
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
20
|
+
import { MRT_FILTER_OPTION } from '../enums';
|
|
21
21
|
|
|
22
22
|
interface Props {
|
|
23
23
|
header: MRT_Header;
|
|
@@ -33,12 +33,12 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
33
33
|
localization,
|
|
34
34
|
muiTableHeadCellFilterTextFieldProps,
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
setCurrentFilterFns,
|
|
37
37
|
} = tableInstance;
|
|
38
38
|
|
|
39
39
|
const { column } = header;
|
|
40
40
|
|
|
41
|
-
const {
|
|
41
|
+
const { currentFilterFns } = getState();
|
|
42
42
|
|
|
43
43
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
44
44
|
|
|
@@ -82,9 +82,9 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
82
82
|
const handleClearFilterChip = () => {
|
|
83
83
|
setFilterValue('');
|
|
84
84
|
column.setColumnFilterValue(undefined);
|
|
85
|
-
|
|
85
|
+
setCurrentFilterFns((prev) => ({
|
|
86
86
|
...prev,
|
|
87
|
-
[header.id]:
|
|
87
|
+
[header.id]: MRT_FILTER_OPTION.BEST_MATCH,
|
|
88
88
|
}));
|
|
89
89
|
};
|
|
90
90
|
|
|
@@ -93,16 +93,16 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field`;
|
|
96
|
-
const
|
|
96
|
+
const filterFn = currentFilterFns?.[header.id];
|
|
97
97
|
const isSelectFilter = !!column.filterSelectOptions;
|
|
98
98
|
const filterChipLabel =
|
|
99
|
-
!(
|
|
100
|
-
[
|
|
101
|
-
|
|
99
|
+
!(filterFn instanceof Function) &&
|
|
100
|
+
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(
|
|
101
|
+
filterFn as MRT_FILTER_OPTION,
|
|
102
102
|
)
|
|
103
103
|
? //@ts-ignore
|
|
104
104
|
localization[
|
|
105
|
-
`filter${
|
|
105
|
+
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
106
106
|
]
|
|
107
107
|
: '';
|
|
108
108
|
const filterPlaceholder = localization.filterByColumn?.replace(
|
|
@@ -125,14 +125,14 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
125
125
|
}}
|
|
126
126
|
helperText={
|
|
127
127
|
<label htmlFor={filterId}>
|
|
128
|
-
{
|
|
128
|
+
{filterFn instanceof Function
|
|
129
129
|
? localization.filterMode.replace(
|
|
130
130
|
'{filterType}',
|
|
131
131
|
// @ts-ignore
|
|
132
132
|
localization[
|
|
133
133
|
`filter${
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
filterFn.name.charAt(0).toUpperCase() +
|
|
135
|
+
filterFn.name.slice(1)
|
|
136
136
|
}`
|
|
137
137
|
] ?? '',
|
|
138
138
|
) ?? ''
|
|
@@ -141,7 +141,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
141
141
|
// @ts-ignore
|
|
142
142
|
localization[
|
|
143
143
|
`filter${
|
|
144
|
-
|
|
144
|
+
filterFn.charAt(0).toUpperCase() + filterFn.slice(1)
|
|
145
145
|
}`
|
|
146
146
|
],
|
|
147
147
|
)}
|
|
@@ -248,7 +248,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
248
248
|
);
|
|
249
249
|
})}
|
|
250
250
|
</TextField>
|
|
251
|
-
<
|
|
251
|
+
<MRT_FilterOptionMenu
|
|
252
252
|
anchorEl={anchorEl}
|
|
253
253
|
header={header}
|
|
254
254
|
setAnchorEl={setAnchorEl}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
TextField,
|
|
14
14
|
Tooltip,
|
|
15
15
|
} from '@mui/material';
|
|
16
|
-
import {
|
|
16
|
+
import { MRT_FilterOptionMenu } from '../menus/MRT_FilterOptionMenu';
|
|
17
17
|
import { MRT_TableInstance } from '..';
|
|
18
18
|
|
|
19
19
|
interface Props {
|
|
@@ -105,7 +105,7 @@ export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
|
105
105
|
{...textFieldProps}
|
|
106
106
|
sx={{ justifySelf: 'end', ...textFieldProps?.sx }}
|
|
107
107
|
/>
|
|
108
|
-
<
|
|
108
|
+
<MRT_FilterOptionMenu
|
|
109
109
|
anchorEl={anchorEl}
|
|
110
110
|
setAnchorEl={setAnchorEl}
|
|
111
111
|
tableInstance={tableInstance}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC, useState } from 'react';
|
|
2
2
|
import { Box, IconButton, ListItemIcon, Menu, MenuItem } from '@mui/material';
|
|
3
3
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
-
import {
|
|
4
|
+
import { MRT_FilterOptionMenu } from './MRT_FilterOptionMenu';
|
|
5
5
|
import { MRT_ShowHideColumnsMenu } from './MRT_ShowHideColumnsMenu';
|
|
6
6
|
|
|
7
7
|
export const commonMenuItemStyles = {
|
|
@@ -240,7 +240,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
240
240
|
</IconButton>
|
|
241
241
|
)}
|
|
242
242
|
</MenuItem>,
|
|
243
|
-
<
|
|
243
|
+
<MRT_FilterOptionMenu
|
|
244
244
|
anchorEl={filterMenuAnchorEl}
|
|
245
245
|
header={header}
|
|
246
246
|
key={2}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Menu, MenuItem } from '@mui/material';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
3
|
+
import type { MRT_FilterFn, MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
import { MRT_FILTER_OPTION } from '../enums';
|
|
5
5
|
import {
|
|
6
6
|
bestMatch,
|
|
7
7
|
bestMatchFirst,
|
|
@@ -30,7 +30,7 @@ interface Props {
|
|
|
30
30
|
tableInstance: MRT_TableInstance;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export const
|
|
33
|
+
export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
34
34
|
anchorEl,
|
|
35
35
|
header,
|
|
36
36
|
onSelect,
|
|
@@ -39,16 +39,16 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
39
39
|
}) => {
|
|
40
40
|
const {
|
|
41
41
|
getState,
|
|
42
|
-
options: {
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
options: { enabledGlobalFilterOptions, localization },
|
|
43
|
+
setCurrentFilterFns,
|
|
44
|
+
setCurrentGlobalFilterFn,
|
|
45
45
|
} = tableInstance;
|
|
46
46
|
|
|
47
|
-
const { isDensePadding,
|
|
47
|
+
const { isDensePadding, currentFilterFns, currentGlobalFilterFn } =
|
|
48
48
|
getState();
|
|
49
49
|
|
|
50
|
-
const
|
|
51
|
-
type:
|
|
50
|
+
const filterOptions: {
|
|
51
|
+
type: MRT_FILTER_OPTION;
|
|
52
52
|
label: string;
|
|
53
53
|
divider: boolean;
|
|
54
54
|
fn: Function;
|
|
@@ -56,104 +56,106 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
56
56
|
() =>
|
|
57
57
|
[
|
|
58
58
|
{
|
|
59
|
-
type:
|
|
59
|
+
type: MRT_FILTER_OPTION.BEST_MATCH_FIRST,
|
|
60
60
|
label: localization.filterBestMatchFirst,
|
|
61
61
|
divider: false,
|
|
62
62
|
fn: bestMatchFirst,
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
type:
|
|
65
|
+
type: MRT_FILTER_OPTION.BEST_MATCH,
|
|
66
66
|
label: localization.filterBestMatch,
|
|
67
67
|
divider: !!header,
|
|
68
68
|
fn: bestMatch,
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
|
-
type:
|
|
71
|
+
type: MRT_FILTER_OPTION.CONTAINS,
|
|
72
72
|
label: localization.filterContains,
|
|
73
73
|
divider: false,
|
|
74
74
|
fn: contains,
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
|
-
type:
|
|
77
|
+
type: MRT_FILTER_OPTION.STARTS_WITH,
|
|
78
78
|
label: localization.filterStartsWith,
|
|
79
79
|
divider: false,
|
|
80
80
|
fn: startsWith,
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
|
-
type:
|
|
83
|
+
type: MRT_FILTER_OPTION.ENDS_WITH,
|
|
84
84
|
label: localization.filterEndsWith,
|
|
85
85
|
divider: true,
|
|
86
86
|
fn: endsWith,
|
|
87
87
|
},
|
|
88
88
|
{
|
|
89
|
-
type:
|
|
89
|
+
type: MRT_FILTER_OPTION.EQUALS,
|
|
90
90
|
label: localization.filterEquals,
|
|
91
91
|
divider: false,
|
|
92
92
|
fn: equals,
|
|
93
93
|
},
|
|
94
94
|
{
|
|
95
|
-
type:
|
|
95
|
+
type: MRT_FILTER_OPTION.NOT_EQUALS,
|
|
96
96
|
label: localization.filterNotEquals,
|
|
97
97
|
divider: true,
|
|
98
98
|
fn: notEquals,
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
|
-
type:
|
|
101
|
+
type: MRT_FILTER_OPTION.GREATER_THAN,
|
|
102
102
|
label: localization.filterGreaterThan,
|
|
103
103
|
divider: false,
|
|
104
104
|
fn: greaterThan,
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
|
-
type:
|
|
107
|
+
type: MRT_FILTER_OPTION.LESS_THAN,
|
|
108
108
|
label: localization.filterLessThan,
|
|
109
109
|
divider: true,
|
|
110
110
|
fn: lessThan,
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
type:
|
|
113
|
+
type: MRT_FILTER_OPTION.EMPTY,
|
|
114
114
|
label: localization.filterEmpty,
|
|
115
115
|
divider: false,
|
|
116
116
|
fn: empty,
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
|
-
type:
|
|
119
|
+
type: MRT_FILTER_OPTION.NOT_EMPTY,
|
|
120
120
|
label: localization.filterNotEmpty,
|
|
121
121
|
divider: false,
|
|
122
122
|
fn: notEmpty,
|
|
123
123
|
},
|
|
124
124
|
].filter((filterType) =>
|
|
125
125
|
header
|
|
126
|
-
? !header.column.
|
|
127
|
-
header.column.
|
|
128
|
-
: (!
|
|
129
|
-
|
|
126
|
+
? !header.column.enabledColumnFilterOptions ||
|
|
127
|
+
header.column.enabledColumnFilterOptions.includes(filterType.type)
|
|
128
|
+
: (!enabledGlobalFilterOptions ||
|
|
129
|
+
enabledGlobalFilterOptions.includes(filterType.type)) &&
|
|
130
130
|
[
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
MRT_FILTER_OPTION.BEST_MATCH_FIRST,
|
|
132
|
+
MRT_FILTER_OPTION.BEST_MATCH,
|
|
133
133
|
].includes(filterType.type),
|
|
134
134
|
),
|
|
135
135
|
[],
|
|
136
136
|
);
|
|
137
137
|
|
|
138
|
-
const handleSelectFilterType = (value:
|
|
138
|
+
const handleSelectFilterType = (value: MRT_FILTER_OPTION) => {
|
|
139
139
|
if (header) {
|
|
140
|
-
|
|
140
|
+
setCurrentFilterFns((prev: { [key: string]: MRT_FilterFn }) => ({
|
|
141
141
|
...prev,
|
|
142
142
|
[header.id]: value,
|
|
143
143
|
}));
|
|
144
|
-
if (
|
|
144
|
+
if (
|
|
145
|
+
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(value)
|
|
146
|
+
) {
|
|
145
147
|
header.column.setColumnFilterValue(' ');
|
|
146
148
|
}
|
|
147
149
|
} else {
|
|
148
|
-
|
|
150
|
+
setCurrentGlobalFilterFn(value);
|
|
149
151
|
}
|
|
150
152
|
setAnchorEl(null);
|
|
151
153
|
onSelect?.();
|
|
152
154
|
};
|
|
153
155
|
|
|
154
156
|
const filterType = !!header
|
|
155
|
-
?
|
|
156
|
-
:
|
|
157
|
+
? currentFilterFns[header.id]
|
|
158
|
+
: currentGlobalFilterFn;
|
|
157
159
|
|
|
158
160
|
return (
|
|
159
161
|
<Menu
|
|
@@ -165,7 +167,7 @@ export const MRT_FilterTypeMenu: FC<Props> = ({
|
|
|
165
167
|
dense: isDensePadding,
|
|
166
168
|
}}
|
|
167
169
|
>
|
|
168
|
-
{
|
|
170
|
+
{filterOptions.map(({ type, label, divider, fn }, index) => (
|
|
169
171
|
<MenuItem
|
|
170
172
|
divider={divider}
|
|
171
173
|
key={index}
|