material-react-table 0.24.0 → 0.26.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/README.md +11 -9
- package/dist/MaterialReactTable.d.ts +18 -16
- package/dist/{utils.d.ts → column.utils.d.ts} +3 -3
- package/dist/filtersFns.d.ts +22 -54
- package/dist/localization.d.ts +3 -0
- package/dist/material-react-table.cjs.development.js +155 -99
- 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 +155 -99
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_TableRoot.d.ts +1 -1
- package/package.json +3 -3
- package/src/MaterialReactTable.tsx +29 -24
- package/src/body/MRT_TableBodyCell.tsx +3 -1
- package/src/{utils.ts → column.utils.ts} +2 -1
- package/src/filtersFns.ts +47 -13
- package/src/head/MRT_TableHeadCell.tsx +29 -29
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +4 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +13 -18
- package/src/localization.ts +6 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +16 -15
- package/src/menus/MRT_FilterOptionMenu.tsx +105 -72
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +1 -1
- package/src/table/MRT_TableRoot.tsx +57 -40
@@ -1,13 +1,7 @@
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
2
|
-
import { Menu, MenuItem } from '@mui/material';
|
2
|
+
import { Box, Menu, MenuItem } from '@mui/material';
|
3
3
|
import type { MRT_FilterOption, MRT_Header, MRT_TableInstance } from '..';
|
4
4
|
|
5
|
-
const commonMenuItemStyles = {
|
6
|
-
py: '6px',
|
7
|
-
my: 0,
|
8
|
-
alignItems: 'center',
|
9
|
-
};
|
10
|
-
|
11
5
|
interface Props {
|
12
6
|
anchorEl: HTMLElement | null;
|
13
7
|
header?: MRT_Header;
|
@@ -42,75 +36,107 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
42
36
|
|
43
37
|
const filterOptions = useMemo(
|
44
38
|
() =>
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
39
|
+
(
|
40
|
+
[
|
41
|
+
{
|
42
|
+
option: 'fuzzy',
|
43
|
+
symbol: '≈',
|
44
|
+
label: localization.filterFuzzy,
|
45
|
+
divider: false,
|
46
|
+
},
|
47
|
+
{
|
48
|
+
option: 'contains',
|
49
|
+
symbol: '[]',
|
50
|
+
label: localization.filterContains,
|
51
|
+
divider: false,
|
52
|
+
},
|
53
|
+
{
|
54
|
+
option: 'startsWith',
|
55
|
+
symbol: 'a',
|
56
|
+
label: localization.filterStartsWith,
|
57
|
+
divider: false,
|
58
|
+
},
|
59
|
+
{
|
60
|
+
option: 'endsWith',
|
61
|
+
symbol: 'z',
|
62
|
+
label: localization.filterEndsWith,
|
63
|
+
divider: true,
|
64
|
+
},
|
65
|
+
{
|
66
|
+
option: 'equals',
|
67
|
+
symbol: '=',
|
68
|
+
label: localization.filterEquals,
|
69
|
+
divider: false,
|
70
|
+
},
|
71
|
+
{
|
72
|
+
option: 'notEquals',
|
73
|
+
symbol: '≠',
|
74
|
+
label: localization.filterNotEquals,
|
75
|
+
divider: true,
|
76
|
+
},
|
77
|
+
{
|
78
|
+
option: 'between',
|
79
|
+
symbol: '⇿',
|
80
|
+
label: localization.filterBetween,
|
81
|
+
divider: false,
|
82
|
+
},
|
83
|
+
{
|
84
|
+
option: 'betweenInclusive',
|
85
|
+
symbol: '⬌',
|
86
|
+
label: localization.filterBetweenInclusive,
|
87
|
+
divider: true,
|
88
|
+
},
|
89
|
+
{
|
90
|
+
option: 'greaterThan',
|
91
|
+
symbol: '>',
|
92
|
+
label: localization.filterGreaterThan,
|
93
|
+
divider: false,
|
94
|
+
},
|
95
|
+
{
|
96
|
+
option: 'greaterThanOrEqualTo',
|
97
|
+
symbol: '≥',
|
98
|
+
label: localization.filterGreaterThanOrEqualTo,
|
99
|
+
divider: false,
|
100
|
+
},
|
101
|
+
{
|
102
|
+
option: 'lessThan',
|
103
|
+
symbol: '<',
|
104
|
+
label: localization.filterLessThan,
|
105
|
+
divider: false,
|
106
|
+
},
|
107
|
+
{
|
108
|
+
option: 'lessThanOrEqualTo',
|
109
|
+
symbol: '≤',
|
110
|
+
label: localization.filterLessThanOrEqualTo,
|
111
|
+
divider: true,
|
112
|
+
},
|
113
|
+
{
|
114
|
+
option: 'empty',
|
115
|
+
symbol: '∅',
|
116
|
+
label: localization.filterEmpty,
|
117
|
+
divider: false,
|
118
|
+
},
|
119
|
+
{
|
120
|
+
option: 'notEmpty',
|
121
|
+
symbol: '!∅',
|
122
|
+
label: localization.filterNotEmpty,
|
123
|
+
divider: false,
|
124
|
+
},
|
125
|
+
] as Array<{
|
126
|
+
divider: boolean;
|
127
|
+
fn: Function;
|
128
|
+
label: string;
|
129
|
+
option: MRT_FilterOption;
|
130
|
+
symbol?: string;
|
131
|
+
}>
|
132
|
+
).filter((filterType) =>
|
102
133
|
columnDef
|
103
134
|
? allowedColumnFilterOptions === undefined ||
|
104
135
|
allowedColumnFilterOptions?.includes(filterType.option)
|
105
136
|
: (!enabledGlobalFilterOptions ||
|
106
137
|
enabledGlobalFilterOptions.includes(filterType.option)) &&
|
107
138
|
['fuzzy', 'contains'].includes(filterType.option),
|
108
|
-
)
|
109
|
-
option: MRT_FilterOption;
|
110
|
-
label: string;
|
111
|
-
divider: boolean;
|
112
|
-
fn: Function;
|
113
|
-
}>,
|
139
|
+
),
|
114
140
|
[],
|
115
141
|
);
|
116
142
|
|
@@ -148,15 +174,22 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
148
174
|
dense: density === 'compact',
|
149
175
|
}}
|
150
176
|
>
|
151
|
-
{filterOptions.map(({ option, label, divider }, index) => (
|
177
|
+
{filterOptions.map(({ option, label, divider, symbol }, index) => (
|
152
178
|
<MenuItem
|
153
179
|
divider={divider}
|
154
180
|
key={index}
|
155
181
|
onClick={() => handleSelectFilterType(option)}
|
156
182
|
selected={option === filterOption}
|
157
|
-
sx={
|
183
|
+
sx={{
|
184
|
+
py: '6px',
|
185
|
+
my: 0,
|
186
|
+
alignItems: 'center',
|
187
|
+
display: 'flex',
|
188
|
+
gap: '2ch',
|
189
|
+
}}
|
158
190
|
value={option}
|
159
191
|
>
|
192
|
+
<Box sx={{ fontSize: '1.25rem', width: '2ch' }}>{symbol}</Box>
|
160
193
|
{label}
|
161
194
|
</MenuItem>
|
162
195
|
))}
|
@@ -2,7 +2,7 @@ import React, { FC, useMemo, useState } from 'react';
|
|
2
2
|
import { Button, Menu, Divider, Box } from '@mui/material';
|
3
3
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
4
4
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
5
|
-
import { getDefaultColumnOrderIds } from '../utils';
|
5
|
+
import { getDefaultColumnOrderIds } from '../column.utils';
|
6
6
|
|
7
7
|
interface Props {
|
8
8
|
anchorEl: HTMLElement | null;
|
@@ -15,7 +15,7 @@ import {
|
|
15
15
|
} from '@mui/material';
|
16
16
|
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
17
17
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
18
|
-
import { reorderColumn } from '../utils';
|
18
|
+
import { reorderColumn } from '../column.utils';
|
19
19
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
20
20
|
|
21
21
|
interface Props {
|
@@ -10,28 +10,44 @@ import {
|
|
10
10
|
getSortedRowModel,
|
11
11
|
useReactTable,
|
12
12
|
} from '@tanstack/react-table';
|
13
|
-
import {
|
14
|
-
MRT_Cell,
|
15
|
-
MRT_Column,
|
16
|
-
MRT_ColumnDef,
|
17
|
-
MRT_FilterOption,
|
18
|
-
MRT_Row,
|
19
|
-
MRT_TableInstance,
|
20
|
-
MRT_TableState,
|
21
|
-
} from '..';
|
13
|
+
import { Box, Dialog, Grow } from '@mui/material';
|
22
14
|
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
23
15
|
import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
|
24
16
|
import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
|
25
17
|
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
26
|
-
import { MaterialReactTableProps } from '../MaterialReactTable';
|
27
18
|
import { MRT_TablePaper } from './MRT_TablePaper';
|
28
|
-
import { Box, Dialog, Grow } from '@mui/material';
|
29
19
|
import {
|
30
20
|
prepareColumns,
|
31
21
|
getAllLeafColumnDefs,
|
32
22
|
getDefaultColumnOrderIds,
|
33
|
-
} from '../utils';
|
23
|
+
} from '../column.utils';
|
34
24
|
import { MRT_FilterFns } from '../filtersFns';
|
25
|
+
import type {
|
26
|
+
MRT_Cell,
|
27
|
+
MRT_Column,
|
28
|
+
MRT_ColumnDef,
|
29
|
+
MRT_FilterOption,
|
30
|
+
MRT_Row,
|
31
|
+
MRT_TableInstance,
|
32
|
+
MRT_TableState,
|
33
|
+
MaterialReactTableProps,
|
34
|
+
} from '..';
|
35
|
+
|
36
|
+
const defaultDisplayColumnDefOptions = {
|
37
|
+
columnDefType: 'display',
|
38
|
+
enableClickToCopy: false,
|
39
|
+
enableColumnActions: false,
|
40
|
+
enableColumnDragging: false,
|
41
|
+
enableColumnFilter: false,
|
42
|
+
enableColumnOrdering: false,
|
43
|
+
enableEditing: false,
|
44
|
+
enableGlobalFilter: false,
|
45
|
+
enableGrouping: false,
|
46
|
+
enableHiding: false,
|
47
|
+
enablePinning: false,
|
48
|
+
enableResizing: false,
|
49
|
+
enableSorting: false,
|
50
|
+
} as Partial<MRT_ColumnDef>;
|
35
51
|
|
36
52
|
export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
37
53
|
props: MaterialReactTableProps<TData>,
|
@@ -54,17 +70,21 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
54
70
|
initialState.columnOrder ?? [],
|
55
71
|
);
|
56
72
|
const [currentDraggingColumn, setCurrentDraggingColumn] =
|
57
|
-
useState<MRT_Column<TData> | null>(
|
73
|
+
useState<MRT_Column<TData> | null>(
|
74
|
+
initialState.currentDraggingColumn ?? null,
|
75
|
+
);
|
58
76
|
const [currentDraggingRow, setCurrentDraggingRow] =
|
59
|
-
useState<MRT_Row<TData> | null>(null);
|
77
|
+
useState<MRT_Row<TData> | null>(initialState.currentDraggingRow ?? null);
|
60
78
|
const [currentEditingCell, setCurrentEditingCell] =
|
61
|
-
useState<MRT_Cell<TData> | null>(initialState
|
79
|
+
useState<MRT_Cell<TData> | null>(initialState.currentEditingCell ?? null);
|
62
80
|
const [currentEditingRow, setCurrentEditingRow] =
|
63
|
-
useState<MRT_Row<TData> | null>(initialState
|
81
|
+
useState<MRT_Row<TData> | null>(initialState.currentEditingRow ?? null);
|
64
82
|
const [currentHoveredColumn, setCurrentHoveredColumn] =
|
65
|
-
useState<MRT_Column<TData> | null>(
|
83
|
+
useState<MRT_Column<TData> | null>(
|
84
|
+
initialState.currentHoveredColumn ?? null,
|
85
|
+
);
|
66
86
|
const [currentHoveredRow, setCurrentHoveredRow] =
|
67
|
-
useState<MRT_Row<TData> | null>(null);
|
87
|
+
useState<MRT_Row<TData> | null>(initialState.currentHoveredRow ?? null);
|
68
88
|
const [density, setDensity] = useState(
|
69
89
|
initialState?.density ?? 'comfortable',
|
70
90
|
);
|
@@ -80,7 +100,6 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
80
100
|
const [showGlobalFilter, setShowGlobalFilter] = useState(
|
81
101
|
initialState?.showGlobalFilter ?? false,
|
82
102
|
);
|
83
|
-
|
84
103
|
const [currentFilterFns, setCurrentFilterFns] = useState<{
|
85
104
|
[key: string]: MRT_FilterOption;
|
86
105
|
}>(() =>
|
@@ -100,7 +119,6 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
100
119
|
),
|
101
120
|
),
|
102
121
|
);
|
103
|
-
|
104
122
|
const [currentGlobalFilterFn, setCurrentGlobalFilterFn] =
|
105
123
|
useState<MRT_FilterOption>(
|
106
124
|
props.globalFilterFn instanceof String
|
@@ -113,12 +131,11 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
113
131
|
(
|
114
132
|
[
|
115
133
|
columnOrder.includes('mrt-row-drag') && {
|
116
|
-
columnDefType: 'display',
|
117
134
|
header: props.localization?.move,
|
118
|
-
id: 'mrt-row-drag',
|
119
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
120
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
121
135
|
size: 60,
|
136
|
+
...defaultDisplayColumnDefOptions,
|
137
|
+
...props.displayColumnDefOptions?.['mrt-row-drag'],
|
138
|
+
id: 'mrt-row-drag',
|
122
139
|
},
|
123
140
|
columnOrder.includes('mrt-row-actions') && {
|
124
141
|
Cell: ({ cell }) => (
|
@@ -127,12 +144,11 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
127
144
|
table={table}
|
128
145
|
/>
|
129
146
|
),
|
130
|
-
columnDefType: 'display',
|
131
147
|
header: props.localization?.actions,
|
132
|
-
id: 'mrt-row-actions',
|
133
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
134
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
135
148
|
size: 70,
|
149
|
+
...defaultDisplayColumnDefOptions,
|
150
|
+
...props.displayColumnDefOptions?.['mrt-row-actions'],
|
151
|
+
id: 'mrt-row-actions',
|
136
152
|
},
|
137
153
|
columnOrder.includes('mrt-row-expand') && {
|
138
154
|
Cell: ({ cell }) => (
|
@@ -142,12 +158,11 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
142
158
|
props.enableExpandAll ? (
|
143
159
|
<MRT_ExpandAllButton table={table} />
|
144
160
|
) : null,
|
145
|
-
columnDefType: 'display',
|
146
161
|
header: props.localization?.expand,
|
147
|
-
id: 'mrt-row-expand',
|
148
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
149
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
150
162
|
size: 60,
|
163
|
+
...defaultDisplayColumnDefOptions,
|
164
|
+
...props.displayColumnDefOptions?.['mrt-row-expand'],
|
165
|
+
id: 'mrt-row-expand',
|
151
166
|
},
|
152
167
|
columnOrder.includes('mrt-row-select') && {
|
153
168
|
Cell: ({ cell }) => (
|
@@ -157,33 +172,35 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
157
172
|
props.enableSelectAll ? (
|
158
173
|
<MRT_SelectCheckbox selectAll table={table} />
|
159
174
|
) : null,
|
160
|
-
columnDefType: 'display',
|
161
175
|
header: props.localization?.select,
|
162
|
-
id: 'mrt-row-select',
|
163
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
164
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
165
176
|
size: 60,
|
177
|
+
...defaultDisplayColumnDefOptions,
|
178
|
+
...props.displayColumnDefOptions?.['mrt-row-select'],
|
179
|
+
id: 'mrt-row-select',
|
166
180
|
},
|
167
181
|
columnOrder.includes('mrt-row-numbers') && {
|
168
182
|
Cell: ({ cell }) => cell.row.index + 1,
|
169
183
|
Header: () => props.localization?.rowNumber,
|
170
|
-
columnDefType: 'display',
|
171
184
|
header: props.localization?.rowNumbers,
|
172
|
-
id: 'mrt-row-numbers',
|
173
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
174
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
175
185
|
size: 60,
|
186
|
+
...defaultDisplayColumnDefOptions,
|
187
|
+
...props.displayColumnDefOptions?.['mrt-row-numbers'],
|
188
|
+
id: 'mrt-row-numbers',
|
176
189
|
},
|
177
190
|
] as MRT_ColumnDef<TData>[]
|
178
191
|
).filter(Boolean),
|
179
192
|
[
|
180
193
|
columnOrder,
|
194
|
+
props.displayColumnDefOptions,
|
181
195
|
props.editingMode,
|
196
|
+
props.enableColumnDragging,
|
197
|
+
props.enableColumnOrdering,
|
182
198
|
props.enableEditing,
|
183
199
|
props.enableExpandAll,
|
184
200
|
props.enableExpanding,
|
185
201
|
props.enableGrouping,
|
186
202
|
props.enableRowActions,
|
203
|
+
props.enableRowDragging,
|
187
204
|
props.enableRowNumbers,
|
188
205
|
props.enableRowOrdering,
|
189
206
|
props.enableRowSelection,
|