material-react-table 0.8.7 → 0.8.10
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 +29 -15
- package/dist/MaterialReactTable.d.ts +10 -8
- package/dist/material-react-table.cjs.development.js +1774 -4839
- 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 +91 -74
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +5 -4
- package/src/MaterialReactTable.tsx +29 -24
- package/src/body/MRT_TableBodyCell.tsx +13 -10
- package/src/buttons/MRT_CopyButton.tsx +6 -3
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +4 -3
- package/src/footer/MRT_TableFooterCell.tsx +10 -6
- package/src/head/MRT_TableHeadCell.tsx +36 -32
- package/src/inputs/MRT_EditCellTextField.tsx +15 -9
- package/src/inputs/MRT_FilterTextField.tsx +15 -10
- package/src/menus/MRT_ColumnActionMenu.tsx +10 -8
- package/src/menus/MRT_FilterOptionMenu.tsx +11 -7
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.
|
|
2
|
+
"version": "0.8.10",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
|
-
"description": "A fully featured Material UI implementation of
|
|
5
|
+
"description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
6
6
|
"author": "Kevin Vandy",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"react-table",
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"react-dom": "^17.0.2",
|
|
82
82
|
"react-is": "^18.1.0",
|
|
83
83
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
84
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
84
85
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
85
86
|
"size-limit": "^7.0.8",
|
|
86
87
|
"storybook-dark-mode": "^1.1.0",
|
|
@@ -98,7 +99,7 @@
|
|
|
98
99
|
"dependencies": {
|
|
99
100
|
"@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
|
|
100
101
|
"@tanstack/react-table": "^8.0.0-alpha.89",
|
|
101
|
-
"react-dnd": "^
|
|
102
|
-
"react-dnd-html5-backend": "^
|
|
102
|
+
"react-dnd": "^16.0.1",
|
|
103
|
+
"react-dnd-html5-backend": "^16.0.1"
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -137,7 +137,7 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
|
|
|
137
137
|
|
|
138
138
|
export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
139
139
|
ColumnDef<D>,
|
|
140
|
-
'header' | 'footer' | 'columns' | 'filterFn'
|
|
140
|
+
'accessorFN' | 'header' | 'footer' | 'columns' | 'filterFn'
|
|
141
141
|
> & {
|
|
142
142
|
Edit?: ({
|
|
143
143
|
cell,
|
|
@@ -153,20 +153,24 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
153
153
|
header: MRT_Header<D>;
|
|
154
154
|
tableInstance: MRT_TableInstance<D>;
|
|
155
155
|
}) => ReactNode;
|
|
156
|
-
Footer?:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
156
|
+
Footer?:
|
|
157
|
+
| ReactNode
|
|
158
|
+
| (({
|
|
159
|
+
footer,
|
|
160
|
+
tableInstance,
|
|
161
|
+
}: {
|
|
162
|
+
footer: MRT_Header<D>;
|
|
163
|
+
tableInstance: MRT_TableInstance<D>;
|
|
164
|
+
}) => ReactNode);
|
|
165
|
+
Header?:
|
|
166
|
+
| ReactNode
|
|
167
|
+
| (({
|
|
168
|
+
header,
|
|
169
|
+
tableInstance,
|
|
170
|
+
}: {
|
|
171
|
+
header: MRT_Header<D>;
|
|
172
|
+
tableInstance: MRT_TableInstance<D>;
|
|
173
|
+
}) => ReactNode);
|
|
170
174
|
Cell?: ({
|
|
171
175
|
cell,
|
|
172
176
|
tableInstance,
|
|
@@ -174,7 +178,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
174
178
|
cell: MRT_Cell<D>;
|
|
175
179
|
tableInstance: MRT_TableInstance<D>;
|
|
176
180
|
}) => ReactNode;
|
|
177
|
-
|
|
181
|
+
accessorFN?: (row: D) => any;
|
|
178
182
|
columns?: MRT_ColumnDef<D>[];
|
|
179
183
|
enableClickToCopy?: boolean;
|
|
180
184
|
enableColumnActions?: boolean;
|
|
@@ -185,6 +189,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
185
189
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
186
190
|
footer?: string;
|
|
187
191
|
header: string;
|
|
192
|
+
id: keyof D | string;
|
|
188
193
|
muiTableBodyCellCopyButtonProps?:
|
|
189
194
|
| ButtonProps
|
|
190
195
|
| (({
|
|
@@ -280,13 +285,12 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
280
285
|
export type MRT_Column<D extends Record<string, any> = {}> = Omit<
|
|
281
286
|
Column<D>,
|
|
282
287
|
'header' | 'footer' | 'columns'
|
|
283
|
-
> &
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
};
|
|
288
|
+
> & {
|
|
289
|
+
columns?: MRT_Column<D>[];
|
|
290
|
+
columnDef: MRT_ColumnDef<D>;
|
|
291
|
+
header: string;
|
|
292
|
+
footer: string;
|
|
293
|
+
};
|
|
290
294
|
|
|
291
295
|
export type MRT_Header<D extends Record<string, any> = {}> = Omit<
|
|
292
296
|
Header<D>,
|
|
@@ -304,12 +308,13 @@ export type MRT_HeaderGroup<D extends Record<string, any> = {}> = Omit<
|
|
|
304
308
|
|
|
305
309
|
export type MRT_Row<D extends Record<string, any> = {}> = Omit<
|
|
306
310
|
Row<D>,
|
|
307
|
-
'getVisibleCells' | 'getAllCells' | 'subRows' | 'original'
|
|
311
|
+
'getVisibleCells' | 'getAllCells' | 'subRows' | 'original' | '_valuesCache'
|
|
308
312
|
> & {
|
|
309
313
|
getAllCells: () => MRT_Cell<D>[];
|
|
310
314
|
getVisibleCells: () => MRT_Cell<D>[];
|
|
311
315
|
subRows?: MRT_Row<D>[];
|
|
312
316
|
original: D;
|
|
317
|
+
_valuesCache?: D;
|
|
313
318
|
};
|
|
314
319
|
|
|
315
320
|
export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
|
|
@@ -39,15 +39,17 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
39
39
|
|
|
40
40
|
const { column, row } = cell;
|
|
41
41
|
|
|
42
|
+
const { columnDef } = column;
|
|
43
|
+
|
|
42
44
|
const mTableCellBodyProps =
|
|
43
45
|
muiTableBodyCellProps instanceof Function
|
|
44
46
|
? muiTableBodyCellProps({ cell, tableInstance })
|
|
45
47
|
: muiTableBodyCellProps;
|
|
46
48
|
|
|
47
49
|
const mcTableCellBodyProps =
|
|
48
|
-
|
|
49
|
-
?
|
|
50
|
-
:
|
|
50
|
+
columnDef.muiTableBodyCellProps instanceof Function
|
|
51
|
+
? columnDef.muiTableBodyCellProps({ cell, tableInstance })
|
|
52
|
+
: columnDef.muiTableBodyCellProps;
|
|
51
53
|
|
|
52
54
|
const tableCellProps = {
|
|
53
55
|
...mTableCellBodyProps,
|
|
@@ -64,7 +66,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
64
66
|
);
|
|
65
67
|
|
|
66
68
|
const isEditable =
|
|
67
|
-
(enableEditing ||
|
|
69
|
+
(enableEditing || columnDef.enableEditing) &&
|
|
70
|
+
columnDef.enableEditing !== false;
|
|
68
71
|
|
|
69
72
|
const isEditing =
|
|
70
73
|
isEditable &&
|
|
@@ -74,8 +77,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
74
77
|
|
|
75
78
|
const handleDoubleClick = (_event: MouseEvent<HTMLTableCellElement>) => {
|
|
76
79
|
if (
|
|
77
|
-
(enableEditing ||
|
|
78
|
-
|
|
80
|
+
(enableEditing || columnDef.enableEditing) &&
|
|
81
|
+
columnDef.enableEditing !== false &&
|
|
79
82
|
editingMode === 'cell'
|
|
80
83
|
) {
|
|
81
84
|
setCurrentEditingCell(cell);
|
|
@@ -160,7 +163,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
160
163
|
})}
|
|
161
164
|
style={{
|
|
162
165
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
163
|
-
minWidth: `max(${column.getSize()}px, ${
|
|
166
|
+
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
|
164
167
|
width: column.getSize(),
|
|
165
168
|
}}
|
|
166
169
|
>
|
|
@@ -173,7 +176,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
173
176
|
{...muiTableBodyCellSkeletonProps}
|
|
174
177
|
/>
|
|
175
178
|
) : column.columnDefType === 'display' ? (
|
|
176
|
-
|
|
179
|
+
columnDef.Cell?.({ cell, tableInstance })
|
|
177
180
|
) : cell.getIsPlaceholder() ||
|
|
178
181
|
(row.getIsGrouped() &&
|
|
179
182
|
column.id !==
|
|
@@ -181,8 +184,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
181
184
|
cell.renderAggregatedCell()
|
|
182
185
|
) : isEditing ? (
|
|
183
186
|
<MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
|
|
184
|
-
) : (enableClickToCopy ||
|
|
185
|
-
|
|
187
|
+
) : (enableClickToCopy || columnDef.enableClickToCopy) &&
|
|
188
|
+
columnDef.enableClickToCopy !== false ? (
|
|
186
189
|
<>
|
|
187
190
|
<MRT_CopyButton cell={cell} tableInstance={tableInstance}>
|
|
188
191
|
<>
|
|
@@ -31,9 +31,12 @@ export const MRT_CopyButton: FC<Props> = ({
|
|
|
31
31
|
: muiTableBodyCellCopyButtonProps;
|
|
32
32
|
|
|
33
33
|
const mcTableBodyCellCopyButtonProps =
|
|
34
|
-
cell.column.muiTableBodyCellCopyButtonProps instanceof Function
|
|
35
|
-
? cell.column.muiTableBodyCellCopyButtonProps({
|
|
36
|
-
|
|
34
|
+
cell.column.columnDef.muiTableBodyCellCopyButtonProps instanceof Function
|
|
35
|
+
? cell.column.columnDef.muiTableBodyCellCopyButtonProps({
|
|
36
|
+
cell,
|
|
37
|
+
tableInstance,
|
|
38
|
+
})
|
|
39
|
+
: cell.column.columnDef.muiTableBodyCellCopyButtonProps;
|
|
37
40
|
|
|
38
41
|
const buttonProps = {
|
|
39
42
|
...mTableBodyCellCopyButtonProps,
|
|
@@ -36,12 +36,13 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
|
|
|
36
36
|
: muiTableHeadCellColumnActionsButtonProps;
|
|
37
37
|
|
|
38
38
|
const mcTableHeadCellColumnActionsButtonProps =
|
|
39
|
-
column.muiTableHeadCellColumnActionsButtonProps instanceof
|
|
40
|
-
|
|
39
|
+
column.columnDef.muiTableHeadCellColumnActionsButtonProps instanceof
|
|
40
|
+
Function
|
|
41
|
+
? column.columnDef.muiTableHeadCellColumnActionsButtonProps({
|
|
41
42
|
column,
|
|
42
43
|
tableInstance,
|
|
43
44
|
})
|
|
44
|
-
: column.muiTableHeadCellColumnActionsButtonProps;
|
|
45
|
+
: column.columnDef.muiTableHeadCellColumnActionsButtonProps;
|
|
45
46
|
|
|
46
47
|
const iconButtonProps = {
|
|
47
48
|
...mTableHeadCellColumnActionsButtonProps,
|
|
@@ -17,15 +17,17 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
17
17
|
|
|
18
18
|
const { column } = footer;
|
|
19
19
|
|
|
20
|
+
const { columnDef } = column;
|
|
21
|
+
|
|
20
22
|
const mTableFooterCellProps =
|
|
21
23
|
muiTableFooterCellProps instanceof Function
|
|
22
24
|
? muiTableFooterCellProps({ column, tableInstance })
|
|
23
25
|
: muiTableFooterCellProps;
|
|
24
26
|
|
|
25
27
|
const mcTableFooterCellProps =
|
|
26
|
-
|
|
27
|
-
?
|
|
28
|
-
:
|
|
28
|
+
columnDef.muiTableFooterCellProps instanceof Function
|
|
29
|
+
? columnDef.muiTableFooterCellProps({ column, tableInstance })
|
|
30
|
+
: columnDef.muiTableFooterCellProps;
|
|
29
31
|
|
|
30
32
|
const tableCellProps = {
|
|
31
33
|
...mTableFooterCellProps,
|
|
@@ -57,11 +59,13 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
57
59
|
<>
|
|
58
60
|
{footer.isPlaceholder
|
|
59
61
|
? null
|
|
60
|
-
:
|
|
62
|
+
: columnDef.Footer instanceof Function
|
|
63
|
+
? columnDef.Footer?.({
|
|
61
64
|
footer,
|
|
62
65
|
tableInstance,
|
|
63
|
-
})
|
|
64
|
-
|
|
66
|
+
})
|
|
67
|
+
: columnDef.Footer ??
|
|
68
|
+
columnDef.footer ??
|
|
65
69
|
footer.renderFooter() ??
|
|
66
70
|
null}
|
|
67
71
|
</>
|
|
@@ -41,25 +41,31 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
41
41
|
|
|
42
42
|
const { column } = header;
|
|
43
43
|
|
|
44
|
+
const { columnDef, columnDefType } = column;
|
|
45
|
+
|
|
44
46
|
const mTableHeadCellProps =
|
|
45
47
|
muiTableHeadCellProps instanceof Function
|
|
46
48
|
? muiTableHeadCellProps({ column, tableInstance })
|
|
47
49
|
: muiTableHeadCellProps;
|
|
48
50
|
|
|
49
51
|
const mcTableHeadCellProps =
|
|
50
|
-
|
|
51
|
-
?
|
|
52
|
-
:
|
|
52
|
+
columnDef.muiTableHeadCellProps instanceof Function
|
|
53
|
+
? columnDef.muiTableHeadCellProps({ column, tableInstance })
|
|
54
|
+
: columnDef.muiTableHeadCellProps;
|
|
53
55
|
|
|
54
56
|
const tableCellProps = {
|
|
55
57
|
...mTableHeadCellProps,
|
|
56
58
|
...mcTableHeadCellProps,
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
const headerElement = (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const headerElement = (
|
|
62
|
+
column.columnDef?.Header instanceof Function
|
|
63
|
+
? column.columnDef?.Header?.({
|
|
64
|
+
header,
|
|
65
|
+
tableInstance,
|
|
66
|
+
})
|
|
67
|
+
: column.columnDef?.Header ?? header.renderHeader()
|
|
68
|
+
) as ReactNode;
|
|
63
69
|
|
|
64
70
|
const getIsLastLeftPinnedColumn = () => {
|
|
65
71
|
return (
|
|
@@ -83,13 +89,13 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
83
89
|
|
|
84
90
|
return (
|
|
85
91
|
<TableCell
|
|
86
|
-
align={
|
|
92
|
+
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
87
93
|
colSpan={header.colSpan}
|
|
88
94
|
{...tableCellProps}
|
|
89
|
-
ref={
|
|
95
|
+
ref={columnDefType === 'data' ? dropRef : undefined}
|
|
90
96
|
sx={(theme: Theme) => ({
|
|
91
97
|
backgroundColor:
|
|
92
|
-
column.getIsPinned() &&
|
|
98
|
+
column.getIsPinned() && columnDefType !== 'group'
|
|
93
99
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
94
100
|
: 'inherit',
|
|
95
101
|
backgroundImage: 'inherit',
|
|
@@ -106,19 +112,19 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
106
112
|
: undefined,
|
|
107
113
|
overflow: 'visible',
|
|
108
114
|
p: isDensePadding
|
|
109
|
-
?
|
|
115
|
+
? columnDefType === 'display'
|
|
110
116
|
? '0 0.5rem'
|
|
111
117
|
: '0.5rem'
|
|
112
|
-
:
|
|
118
|
+
: columnDefType === 'display'
|
|
113
119
|
? '0.5rem 0.75rem'
|
|
114
120
|
: '1rem',
|
|
115
|
-
pb:
|
|
121
|
+
pb: columnDefType === 'display' ? 0 : undefined,
|
|
116
122
|
position:
|
|
117
|
-
column.getIsPinned() &&
|
|
123
|
+
column.getIsPinned() && columnDefType !== 'group'
|
|
118
124
|
? 'sticky'
|
|
119
125
|
: undefined,
|
|
120
126
|
pt:
|
|
121
|
-
|
|
127
|
+
columnDefType === 'display'
|
|
122
128
|
? 0
|
|
123
129
|
: isDensePadding
|
|
124
130
|
? '0.75rem'
|
|
@@ -129,18 +135,18 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
129
135
|
verticalAlign: 'text-top',
|
|
130
136
|
zIndex: column.getIsResizing()
|
|
131
137
|
? 3
|
|
132
|
-
: column.getIsPinned() &&
|
|
138
|
+
: column.getIsPinned() && columnDefType !== 'group'
|
|
133
139
|
? 2
|
|
134
140
|
: 1,
|
|
135
141
|
...(tableCellProps?.sx as any),
|
|
136
142
|
})}
|
|
137
143
|
style={{
|
|
138
144
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
139
|
-
minWidth: `max(${column.getSize()}px, ${
|
|
145
|
+
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
|
140
146
|
width: header.getSize(),
|
|
141
147
|
}}
|
|
142
148
|
>
|
|
143
|
-
{header.isPlaceholder ? null :
|
|
149
|
+
{header.isPlaceholder ? null : columnDefType === 'display' ? (
|
|
144
150
|
headerElement
|
|
145
151
|
) : (
|
|
146
152
|
<Box
|
|
@@ -149,7 +155,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
149
155
|
alignItems: 'flex-start',
|
|
150
156
|
display: 'flex',
|
|
151
157
|
justifyContent:
|
|
152
|
-
|
|
158
|
+
columnDefType === 'group' ? 'center' : 'space-between',
|
|
153
159
|
opacity: isDragging ? 0.5 : 1,
|
|
154
160
|
width: '100%',
|
|
155
161
|
}}
|
|
@@ -159,25 +165,23 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
159
165
|
sx={{
|
|
160
166
|
alignItems: 'center',
|
|
161
167
|
cursor:
|
|
162
|
-
column.getCanSort() &&
|
|
168
|
+
column.getCanSort() && columnDefType !== 'group'
|
|
163
169
|
? 'pointer'
|
|
164
170
|
: undefined,
|
|
165
171
|
display: 'flex',
|
|
166
172
|
flexWrap: 'nowrap',
|
|
167
173
|
whiteSpace:
|
|
168
|
-
(
|
|
169
|
-
? 'nowrap'
|
|
170
|
-
: 'normal',
|
|
174
|
+
(columnDef.header?.length ?? 0) < 24 ? 'nowrap' : 'normal',
|
|
171
175
|
}}
|
|
172
176
|
>
|
|
173
177
|
{headerElement}
|
|
174
|
-
{
|
|
178
|
+
{columnDefType === 'data' && column.getCanSort() && (
|
|
175
179
|
<MRT_TableHeadCellSortLabel
|
|
176
180
|
header={header}
|
|
177
181
|
tableInstance={tableInstance}
|
|
178
182
|
/>
|
|
179
183
|
)}
|
|
180
|
-
{
|
|
184
|
+
{columnDefType === 'data' &&
|
|
181
185
|
enableColumnFilters &&
|
|
182
186
|
column.getCanFilter() && (
|
|
183
187
|
<MRT_TableHeadCellFilterLabel
|
|
@@ -187,19 +191,19 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
187
191
|
)}
|
|
188
192
|
</Box>
|
|
189
193
|
<Box sx={{ whiteSpace: 'nowrap' }}>
|
|
190
|
-
{
|
|
194
|
+
{columnDefType === 'data' &&
|
|
191
195
|
((enableColumnOrdering &&
|
|
192
|
-
|
|
193
|
-
(enableGrouping &&
|
|
196
|
+
columnDef.enableColumnOrdering !== false) ||
|
|
197
|
+
(enableGrouping && columnDef.enableGrouping !== false)) && (
|
|
194
198
|
<MRT_TableHeadCellGrabHandle
|
|
195
199
|
header={header}
|
|
196
200
|
ref={dragRef as Ref<HTMLButtonElement>}
|
|
197
201
|
tableInstance={tableInstance}
|
|
198
202
|
/>
|
|
199
203
|
)}
|
|
200
|
-
{(enableColumnActions ||
|
|
201
|
-
|
|
202
|
-
|
|
204
|
+
{(enableColumnActions || columnDef.enableColumnActions) &&
|
|
205
|
+
columnDef.enableColumnActions !== false &&
|
|
206
|
+
columnDefType !== 'group' && (
|
|
203
207
|
<MRT_ToggleColumnActionMenuButton
|
|
204
208
|
header={header}
|
|
205
209
|
tableInstance={tableInstance}
|
|
@@ -214,7 +218,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
214
218
|
)}
|
|
215
219
|
</Box>
|
|
216
220
|
)}
|
|
217
|
-
{
|
|
221
|
+
{columnDefType === 'data' && column.getCanFilter() && (
|
|
218
222
|
<MRT_TableHeadCellFilterContainer
|
|
219
223
|
header={header}
|
|
220
224
|
tableInstance={tableInstance}
|
|
@@ -31,19 +31,22 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
31
31
|
|
|
32
32
|
const { column, row } = cell;
|
|
33
33
|
|
|
34
|
+
const { columnDef } = column;
|
|
35
|
+
|
|
34
36
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
35
37
|
setValue(event.target.value);
|
|
36
|
-
|
|
38
|
+
columnDef.onCellEditChange?.({ event, cell, tableInstance });
|
|
37
39
|
onCellEditChange?.({ event, cell, tableInstance });
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
41
43
|
if (getState().currentEditingRow) {
|
|
42
|
-
row._valuesCache
|
|
44
|
+
if (!row._valuesCache) row._valuesCache = {};
|
|
45
|
+
(row._valuesCache as Record<string, any>)[column.id] = value;
|
|
43
46
|
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
44
47
|
}
|
|
45
48
|
setCurrentEditingCell(null);
|
|
46
|
-
|
|
49
|
+
columnDef.onCellEditBlur?.({ event, cell, tableInstance });
|
|
47
50
|
onCellEditBlur?.({ event, cell, tableInstance });
|
|
48
51
|
};
|
|
49
52
|
|
|
@@ -53,17 +56,20 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
53
56
|
: muiTableBodyCellEditTextFieldProps;
|
|
54
57
|
|
|
55
58
|
const mcTableBodyCellEditTextFieldProps =
|
|
56
|
-
|
|
57
|
-
?
|
|
58
|
-
|
|
59
|
+
columnDef.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
60
|
+
? columnDef.muiTableBodyCellEditTextFieldProps({
|
|
61
|
+
cell,
|
|
62
|
+
tableInstance,
|
|
63
|
+
})
|
|
64
|
+
: columnDef.muiTableBodyCellEditTextFieldProps;
|
|
59
65
|
|
|
60
66
|
const textFieldProps = {
|
|
61
67
|
...mTableBodyCellEditTextFieldProps,
|
|
62
68
|
...mcTableBodyCellEditTextFieldProps,
|
|
63
69
|
};
|
|
64
70
|
|
|
65
|
-
if (enableEditing &&
|
|
66
|
-
return <>{
|
|
71
|
+
if (enableEditing && columnDef.enableEditing !== false && columnDef.Edit) {
|
|
72
|
+
return <>{columnDef.Edit?.({ cell, tableInstance })}</>;
|
|
67
73
|
}
|
|
68
74
|
|
|
69
75
|
return (
|
|
@@ -73,7 +79,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
73
79
|
onBlur={handleBlur}
|
|
74
80
|
onChange={handleChange}
|
|
75
81
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
76
|
-
placeholder={
|
|
82
|
+
placeholder={columnDef.header}
|
|
77
83
|
value={value}
|
|
78
84
|
variant="standard"
|
|
79
85
|
{...textFieldProps}
|
|
@@ -43,6 +43,8 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
43
43
|
|
|
44
44
|
const { column } = header;
|
|
45
45
|
|
|
46
|
+
const { columnDef } = column;
|
|
47
|
+
|
|
46
48
|
const { currentFilterFns } = getState();
|
|
47
49
|
|
|
48
50
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
@@ -53,9 +55,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
53
55
|
: muiTableHeadCellFilterTextFieldProps;
|
|
54
56
|
|
|
55
57
|
const mcTableHeadCellFilterTextFieldProps =
|
|
56
|
-
|
|
57
|
-
?
|
|
58
|
-
|
|
58
|
+
columnDef.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
59
|
+
? columnDef.muiTableHeadCellFilterTextFieldProps({
|
|
60
|
+
column,
|
|
61
|
+
tableInstance,
|
|
62
|
+
})
|
|
63
|
+
: columnDef.muiTableHeadCellFilterTextFieldProps;
|
|
59
64
|
|
|
60
65
|
const textFieldProps = {
|
|
61
66
|
...mTableHeadCellFilterTextFieldProps,
|
|
@@ -109,15 +114,15 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
109
114
|
}));
|
|
110
115
|
};
|
|
111
116
|
|
|
112
|
-
if (
|
|
113
|
-
return <>{
|
|
117
|
+
if (columnDef.Filter) {
|
|
118
|
+
return <>{columnDef.Filter?.({ header, tableInstance })}</>;
|
|
114
119
|
}
|
|
115
120
|
|
|
116
121
|
const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field${
|
|
117
122
|
inputIndex ?? ''
|
|
118
123
|
}`;
|
|
119
124
|
const filterFn = currentFilterFns?.[header.id];
|
|
120
|
-
const isSelectFilter = !!
|
|
125
|
+
const isSelectFilter = !!columnDef.filterSelectOptions;
|
|
121
126
|
const filterChipLabel =
|
|
122
127
|
!(filterFn instanceof Function) &&
|
|
123
128
|
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(
|
|
@@ -132,14 +137,14 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
132
137
|
inputIndex === undefined
|
|
133
138
|
? localization.filterByColumn?.replace(
|
|
134
139
|
'{column}',
|
|
135
|
-
String(
|
|
140
|
+
String(columnDef.header),
|
|
136
141
|
)
|
|
137
142
|
: inputIndex === 0
|
|
138
143
|
? localization.min
|
|
139
144
|
: inputIndex === 1
|
|
140
145
|
? localization.max
|
|
141
146
|
: '';
|
|
142
|
-
|
|
147
|
+
console.log({ textFieldProps });
|
|
143
148
|
return (
|
|
144
149
|
<>
|
|
145
150
|
<TextField
|
|
@@ -252,7 +257,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
252
257
|
sx={{
|
|
253
258
|
m: '-0.25rem',
|
|
254
259
|
p: 0,
|
|
255
|
-
minWidth: !filterChipLabel ? '
|
|
260
|
+
minWidth: !filterChipLabel ? '8rem' : 'auto',
|
|
256
261
|
width: 'calc(100% + 0.5rem)',
|
|
257
262
|
mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
|
|
258
263
|
'& .MuiSelect-icon': {
|
|
@@ -266,7 +271,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
266
271
|
{localization.clearFilter}
|
|
267
272
|
</MenuItem>
|
|
268
273
|
)}
|
|
269
|
-
{
|
|
274
|
+
{columnDef?.filterSelectOptions?.map((option) => {
|
|
270
275
|
let value;
|
|
271
276
|
let text;
|
|
272
277
|
if (typeof option === 'string') {
|
|
@@ -60,6 +60,8 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
60
60
|
|
|
61
61
|
const { column } = header;
|
|
62
62
|
|
|
63
|
+
const { columnDef } = column;
|
|
64
|
+
|
|
63
65
|
const { columnSizing, columnVisibility, isDensePadding } = getState();
|
|
64
66
|
|
|
65
67
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
@@ -178,7 +180,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
178
180
|
</ListItemIcon>
|
|
179
181
|
{localization.sortByColumnAsc?.replace(
|
|
180
182
|
'{column}',
|
|
181
|
-
String(
|
|
183
|
+
String(columnDef.header),
|
|
182
184
|
)}
|
|
183
185
|
</Box>
|
|
184
186
|
</MenuItem>,
|
|
@@ -195,7 +197,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
195
197
|
</ListItemIcon>
|
|
196
198
|
{localization.sortByColumnDesc?.replace(
|
|
197
199
|
'{column}',
|
|
198
|
-
String(
|
|
200
|
+
String(columnDef.header),
|
|
199
201
|
)}
|
|
200
202
|
</Box>
|
|
201
203
|
</MenuItem>,
|
|
@@ -227,10 +229,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
227
229
|
</ListItemIcon>
|
|
228
230
|
{localization.filterByColumn?.replace(
|
|
229
231
|
'{column}',
|
|
230
|
-
String(
|
|
232
|
+
String(columnDef.header),
|
|
231
233
|
)}
|
|
232
234
|
</Box>
|
|
233
|
-
{!
|
|
235
|
+
{!columnDef.filterSelectOptions && (
|
|
234
236
|
<IconButton
|
|
235
237
|
onClick={handleOpenFilterModeMenu}
|
|
236
238
|
onMouseEnter={handleOpenFilterModeMenu}
|
|
@@ -264,7 +266,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
264
266
|
</ListItemIcon>
|
|
265
267
|
{localization[
|
|
266
268
|
column.getIsGrouped() ? 'ungroupByColumn' : 'groupByColumn'
|
|
267
|
-
]?.replace('{column}', String(
|
|
269
|
+
]?.replace('{column}', String(columnDef.header))}
|
|
268
270
|
</Box>
|
|
269
271
|
</MenuItem>,
|
|
270
272
|
]}
|
|
@@ -328,7 +330,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
328
330
|
]}
|
|
329
331
|
{enableHiding && [
|
|
330
332
|
<MenuItem
|
|
331
|
-
disabled={
|
|
333
|
+
disabled={columnDef.enableHiding === false}
|
|
332
334
|
key={0}
|
|
333
335
|
onClick={handleHideColumn}
|
|
334
336
|
sx={commonMenuItemStyles}
|
|
@@ -339,7 +341,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
339
341
|
</ListItemIcon>
|
|
340
342
|
{localization.hideColumn?.replace(
|
|
341
343
|
'{column}',
|
|
342
|
-
String(
|
|
344
|
+
String(columnDef.header),
|
|
343
345
|
)}
|
|
344
346
|
</Box>
|
|
345
347
|
</MenuItem>,
|
|
@@ -358,7 +360,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
358
360
|
</ListItemIcon>
|
|
359
361
|
{localization.showAllColumns?.replace(
|
|
360
362
|
'{column}',
|
|
361
|
-
String(
|
|
363
|
+
String(columnDef.header),
|
|
362
364
|
)}
|
|
363
365
|
</Box>
|
|
364
366
|
<IconButton
|