material-react-table 0.35.2 → 0.36.2
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 +8 -32
- package/dist/cjs/body/MRT_EditRowModal.d.ts +8 -0
- package/dist/cjs/buttons/MRT_EditActionButtons.d.ts +5 -5
- package/dist/cjs/index.js +92 -58
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_EditCellTextField.d.ts +5 -5
- package/dist/esm/MaterialReactTable.d.ts +8 -32
- package/dist/esm/body/MRT_EditRowModal.d.ts +8 -0
- package/dist/esm/buttons/MRT_EditActionButtons.d.ts +5 -5
- package/dist/esm/inputs/MRT_EditCellTextField.d.ts +5 -5
- package/dist/esm/material-react-table.esm.js +93 -59
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/index.d.ts +8 -32
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +8 -59
- package/src/body/MRT_EditRowModal.tsx +57 -0
- package/src/body/MRT_TableBodyCell.tsx +19 -10
- package/src/buttons/MRT_EditActionButtons.tsx +36 -21
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -1
- package/src/column.utils.ts +4 -2
- package/src/inputs/MRT_EditCellTextField.tsx +36 -40
- package/src/table/MRT_TableRoot.tsx +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, ReactNode,
|
|
1
|
+
import { Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
|
|
2
2
|
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, ToolbarProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, AlertProps } from '@mui/material';
|
|
3
3
|
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
4
4
|
import { Options } from 'react-virtual';
|
|
@@ -356,15 +356,15 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
356
356
|
* @default gets set to the same value as `accessorKey` by default
|
|
357
357
|
*/
|
|
358
358
|
id?: LiteralUnion<string & keyof TData>;
|
|
359
|
-
muiTableBodyCellCopyButtonProps?: ButtonProps | (({
|
|
359
|
+
muiTableBodyCellCopyButtonProps?: ButtonProps | (({ cell, table, }: {
|
|
360
360
|
table: MRT_TableInstance<TData>;
|
|
361
361
|
cell: MRT_Cell<TData>;
|
|
362
362
|
}) => ButtonProps);
|
|
363
|
-
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({
|
|
364
|
-
table: MRT_TableInstance<TData>;
|
|
363
|
+
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, table, }: {
|
|
365
364
|
cell: MRT_Cell<TData>;
|
|
365
|
+
table: MRT_TableInstance<TData>;
|
|
366
366
|
}) => TextFieldProps);
|
|
367
|
-
muiTableBodyCellProps?: TableCellProps | (({
|
|
367
|
+
muiTableBodyCellProps?: TableCellProps | (({ cell, table, }: {
|
|
368
368
|
table: MRT_TableInstance<TData>;
|
|
369
369
|
cell: MRT_Cell<TData>;
|
|
370
370
|
}) => TableCellProps);
|
|
@@ -389,18 +389,6 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
389
389
|
table: MRT_TableInstance<TData>;
|
|
390
390
|
column: MRT_Column<TData>;
|
|
391
391
|
}) => TableCellProps);
|
|
392
|
-
onCellEditBlur?: ({ cell, event, table, value, }: {
|
|
393
|
-
event: FocusEvent<HTMLInputElement>;
|
|
394
|
-
cell: MRT_Cell<TData>;
|
|
395
|
-
table: MRT_TableInstance<TData>;
|
|
396
|
-
value: string;
|
|
397
|
-
}) => void;
|
|
398
|
-
onCellEditChange?: ({ cell, event, table, value, }: {
|
|
399
|
-
event: ChangeEvent<HTMLInputElement>;
|
|
400
|
-
cell: MRT_Cell<TData>;
|
|
401
|
-
table: MRT_TableInstance<TData>;
|
|
402
|
-
value: string;
|
|
403
|
-
}) => void;
|
|
404
392
|
sortingFn?: MRT_SortingFn;
|
|
405
393
|
};
|
|
406
394
|
declare type MRT_DefinedColumnDef<TData extends Record<string, any> = {}> = Omit<MRT_ColumnDef<TData>, 'id'> & {
|
|
@@ -452,7 +440,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
452
440
|
displayColumnDefOptions?: Partial<{
|
|
453
441
|
[key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
|
|
454
442
|
}>;
|
|
455
|
-
editingMode?: 'table' | 'row' | 'cell';
|
|
443
|
+
editingMode?: 'table' | 'modal' | 'row' | 'cell';
|
|
456
444
|
enableBottomToolbar?: boolean;
|
|
457
445
|
enableClickToCopy?: boolean;
|
|
458
446
|
enableColumnActions?: boolean;
|
|
@@ -508,9 +496,9 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
508
496
|
table: MRT_TableInstance<TData>;
|
|
509
497
|
cell: MRT_Cell<TData>;
|
|
510
498
|
}) => ButtonProps);
|
|
511
|
-
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({
|
|
512
|
-
table: MRT_TableInstance<TData>;
|
|
499
|
+
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, table, }: {
|
|
513
500
|
cell: MRT_Cell<TData>;
|
|
501
|
+
table: MRT_TableInstance<TData>;
|
|
514
502
|
}) => TextFieldProps);
|
|
515
503
|
muiTableBodyCellProps?: TableCellProps | (({ table, cell, }: {
|
|
516
504
|
table: MRT_TableInstance<TData>;
|
|
@@ -591,18 +579,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
591
579
|
muiTableTopToolbarProps?: ToolbarProps | (({ table }: {
|
|
592
580
|
table: MRT_TableInstance<TData>;
|
|
593
581
|
}) => ToolbarProps);
|
|
594
|
-
onCellEditBlur?: ({ cell, event, table, value, }: {
|
|
595
|
-
event: FocusEvent<HTMLInputElement>;
|
|
596
|
-
cell: MRT_Cell<TData>;
|
|
597
|
-
table: MRT_TableInstance<TData>;
|
|
598
|
-
value: string;
|
|
599
|
-
}) => void;
|
|
600
|
-
onCellEditChange?: ({ cell, event, table, value, }: {
|
|
601
|
-
event: ChangeEvent<HTMLInputElement>;
|
|
602
|
-
cell: MRT_Cell<TData>;
|
|
603
|
-
table: MRT_TableInstance<TData>;
|
|
604
|
-
value: string;
|
|
605
|
-
}) => void;
|
|
606
582
|
onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
|
|
607
583
|
event: DragEvent<HTMLButtonElement>;
|
|
608
584
|
draggedColumn: MRT_Column<TData>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
ChangeEvent,
|
|
3
|
-
Dispatch,
|
|
4
|
-
DragEvent,
|
|
5
|
-
FocusEvent,
|
|
6
|
-
ReactNode,
|
|
7
|
-
SetStateAction,
|
|
8
|
-
} from 'react';
|
|
1
|
+
import React, { Dispatch, DragEvent, ReactNode, SetStateAction } from 'react';
|
|
9
2
|
import type {
|
|
10
3
|
AlertProps,
|
|
11
4
|
ButtonProps,
|
|
@@ -263,8 +256,8 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
263
256
|
muiTableBodyCellCopyButtonProps?:
|
|
264
257
|
| ButtonProps
|
|
265
258
|
| (({
|
|
266
|
-
table,
|
|
267
259
|
cell,
|
|
260
|
+
table,
|
|
268
261
|
}: {
|
|
269
262
|
table: MRT_TableInstance<TData>;
|
|
270
263
|
cell: MRT_Cell<TData>;
|
|
@@ -272,17 +265,17 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
272
265
|
muiTableBodyCellEditTextFieldProps?:
|
|
273
266
|
| TextFieldProps
|
|
274
267
|
| (({
|
|
275
|
-
table,
|
|
276
268
|
cell,
|
|
269
|
+
table,
|
|
277
270
|
}: {
|
|
278
|
-
table: MRT_TableInstance<TData>;
|
|
279
271
|
cell: MRT_Cell<TData>;
|
|
272
|
+
table: MRT_TableInstance<TData>;
|
|
280
273
|
}) => TextFieldProps);
|
|
281
274
|
muiTableBodyCellProps?:
|
|
282
275
|
| TableCellProps
|
|
283
276
|
| (({
|
|
284
|
-
table,
|
|
285
277
|
cell,
|
|
278
|
+
table,
|
|
286
279
|
}: {
|
|
287
280
|
table: MRT_TableInstance<TData>;
|
|
288
281
|
cell: MRT_Cell<TData>;
|
|
@@ -334,28 +327,6 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
334
327
|
table: MRT_TableInstance<TData>;
|
|
335
328
|
column: MRT_Column<TData>;
|
|
336
329
|
}) => TableCellProps);
|
|
337
|
-
onCellEditBlur?: ({
|
|
338
|
-
cell,
|
|
339
|
-
event,
|
|
340
|
-
table,
|
|
341
|
-
value,
|
|
342
|
-
}: {
|
|
343
|
-
event: FocusEvent<HTMLInputElement>;
|
|
344
|
-
cell: MRT_Cell<TData>;
|
|
345
|
-
table: MRT_TableInstance<TData>;
|
|
346
|
-
value: string;
|
|
347
|
-
}) => void;
|
|
348
|
-
onCellEditChange?: ({
|
|
349
|
-
cell,
|
|
350
|
-
event,
|
|
351
|
-
table,
|
|
352
|
-
value,
|
|
353
|
-
}: {
|
|
354
|
-
event: ChangeEvent<HTMLInputElement>;
|
|
355
|
-
cell: MRT_Cell<TData>;
|
|
356
|
-
table: MRT_TableInstance<TData>;
|
|
357
|
-
value: string;
|
|
358
|
-
}) => void;
|
|
359
330
|
sortingFn?: MRT_SortingFn;
|
|
360
331
|
};
|
|
361
332
|
|
|
@@ -461,7 +432,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
461
432
|
displayColumnDefOptions?: Partial<{
|
|
462
433
|
[key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
|
|
463
434
|
}>;
|
|
464
|
-
editingMode?: 'table' | 'row' | 'cell';
|
|
435
|
+
editingMode?: 'table' | 'modal' | 'row' | 'cell';
|
|
465
436
|
enableBottomToolbar?: boolean;
|
|
466
437
|
enableClickToCopy?: boolean;
|
|
467
438
|
enableColumnActions?: boolean;
|
|
@@ -539,11 +510,11 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
539
510
|
muiTableBodyCellEditTextFieldProps?:
|
|
540
511
|
| TextFieldProps
|
|
541
512
|
| (({
|
|
542
|
-
table,
|
|
543
513
|
cell,
|
|
514
|
+
table,
|
|
544
515
|
}: {
|
|
545
|
-
table: MRT_TableInstance<TData>;
|
|
546
516
|
cell: MRT_Cell<TData>;
|
|
517
|
+
table: MRT_TableInstance<TData>;
|
|
547
518
|
}) => TextFieldProps);
|
|
548
519
|
muiTableBodyCellProps?:
|
|
549
520
|
| TableCellProps
|
|
@@ -693,28 +664,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
693
664
|
muiTableTopToolbarProps?:
|
|
694
665
|
| ToolbarProps
|
|
695
666
|
| (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
|
|
696
|
-
onCellEditBlur?: ({
|
|
697
|
-
cell,
|
|
698
|
-
event,
|
|
699
|
-
table,
|
|
700
|
-
value,
|
|
701
|
-
}: {
|
|
702
|
-
event: FocusEvent<HTMLInputElement>;
|
|
703
|
-
cell: MRT_Cell<TData>;
|
|
704
|
-
table: MRT_TableInstance<TData>;
|
|
705
|
-
value: string;
|
|
706
|
-
}) => void;
|
|
707
|
-
onCellEditChange?: ({
|
|
708
|
-
cell,
|
|
709
|
-
event,
|
|
710
|
-
table,
|
|
711
|
-
value,
|
|
712
|
-
}: {
|
|
713
|
-
event: ChangeEvent<HTMLInputElement>;
|
|
714
|
-
cell: MRT_Cell<TData>;
|
|
715
|
-
table: MRT_TableInstance<TData>;
|
|
716
|
-
value: string;
|
|
717
|
-
}) => void;
|
|
718
667
|
onColumnDrop?: ({
|
|
719
668
|
event,
|
|
720
669
|
draggedColumn,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogActions,
|
|
5
|
+
DialogContent,
|
|
6
|
+
DialogTitle,
|
|
7
|
+
Stack,
|
|
8
|
+
} from '@mui/material';
|
|
9
|
+
import { MRT_EditActionButtons } from '../buttons/MRT_EditActionButtons';
|
|
10
|
+
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
11
|
+
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
12
|
+
|
|
13
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
14
|
+
open: boolean;
|
|
15
|
+
row: MRT_Row<TData>;
|
|
16
|
+
table: MRT_TableInstance<TData>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const MRT_EditRowModal = <TData extends Record<string, any> = {}>({
|
|
20
|
+
open,
|
|
21
|
+
row,
|
|
22
|
+
table,
|
|
23
|
+
}: Props<TData>) => {
|
|
24
|
+
const {
|
|
25
|
+
options: { localization },
|
|
26
|
+
} = table;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Dialog open={open}>
|
|
30
|
+
<DialogTitle textAlign="center">{localization.edit}</DialogTitle>
|
|
31
|
+
<DialogContent>
|
|
32
|
+
<Stack
|
|
33
|
+
sx={{
|
|
34
|
+
width: '100%',
|
|
35
|
+
minWidth: { xs: '300px', sm: '360px', md: '400px' },
|
|
36
|
+
gap: '1.5rem',
|
|
37
|
+
}}
|
|
38
|
+
>
|
|
39
|
+
{row
|
|
40
|
+
.getVisibleCells()
|
|
41
|
+
.filter((cell) => cell.column.columnDef.columnDefType === 'data')
|
|
42
|
+
.map((cell) => (
|
|
43
|
+
<MRT_EditCellTextField
|
|
44
|
+
cell={cell}
|
|
45
|
+
key={cell.id}
|
|
46
|
+
showLabel
|
|
47
|
+
table={table}
|
|
48
|
+
/>
|
|
49
|
+
))}
|
|
50
|
+
</Stack>
|
|
51
|
+
</DialogContent>
|
|
52
|
+
<DialogActions sx={{ p: '1.25rem' }}>
|
|
53
|
+
<MRT_EditActionButtons row={row} table={table} variant="text" />
|
|
54
|
+
</DialogActions>
|
|
55
|
+
</Dialog>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -87,6 +87,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
87
87
|
|
|
88
88
|
const isEditing =
|
|
89
89
|
isEditable &&
|
|
90
|
+
editingMode !== 'modal' &&
|
|
90
91
|
(editingMode === 'table' ||
|
|
91
92
|
editingRow?.id === row.id ||
|
|
92
93
|
editingCell?.id === cell.id);
|
|
@@ -238,13 +239,13 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
238
239
|
: undefined,
|
|
239
240
|
'&:hover': {
|
|
240
241
|
backgroundColor:
|
|
241
|
-
enableHover &&
|
|
242
|
+
enableHover &&
|
|
243
|
+
enableEditing &&
|
|
244
|
+
columnDef.enableEditing !== false &&
|
|
245
|
+
['table', 'cell'].includes(editingMode ?? '')
|
|
242
246
|
? theme.palette.mode === 'dark'
|
|
243
|
-
? `${lighten(
|
|
244
|
-
|
|
245
|
-
0.13,
|
|
246
|
-
)} !important`
|
|
247
|
-
: `${darken(theme.palette.background.default, 0.07)} !important`
|
|
247
|
+
? `${lighten(theme.palette.background.default, 0.2)} !important`
|
|
248
|
+
: `${darken(theme.palette.background.default, 0.1)} !important`
|
|
248
249
|
: undefined,
|
|
249
250
|
},
|
|
250
251
|
...(tableCellProps?.sx instanceof Function
|
|
@@ -274,7 +275,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
274
275
|
rowRef={rowRef}
|
|
275
276
|
table={table}
|
|
276
277
|
/>
|
|
277
|
-
) : columnDefType === 'display'
|
|
278
|
+
) : columnDefType === 'display' &&
|
|
279
|
+
(column.id === 'mrt-row-select' ||
|
|
280
|
+
column.id === 'mrt-row-expand' ||
|
|
281
|
+
!row.getIsGrouped()) ? (
|
|
278
282
|
columnDef.Cell?.({ cell, column, table })
|
|
279
283
|
) : isEditing ? (
|
|
280
284
|
<MRT_EditCellTextField cell={cell} table={table} />
|
|
@@ -283,15 +287,20 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
283
287
|
<>
|
|
284
288
|
<MRT_CopyButton cell={cell} table={table}>
|
|
285
289
|
<>
|
|
286
|
-
{
|
|
287
|
-
|
|
290
|
+
{row.getIsGrouped() && !cell.getIsGrouped()
|
|
291
|
+
? null
|
|
292
|
+
: columnDef?.Cell?.({ cell, column, table }) ??
|
|
293
|
+
cell.renderValue()}
|
|
288
294
|
</>
|
|
289
295
|
</MRT_CopyButton>
|
|
290
296
|
{cell.getIsGrouped() && <> ({row.subRows?.length})</>}
|
|
291
297
|
</>
|
|
292
298
|
) : (
|
|
293
299
|
<>
|
|
294
|
-
{
|
|
300
|
+
{row.getIsGrouped() && !cell.getIsGrouped()
|
|
301
|
+
? null
|
|
302
|
+
: columnDef?.Cell?.({ cell, column, table }) ??
|
|
303
|
+
cell.renderValue()}
|
|
295
304
|
{cell.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
|
|
296
305
|
</>
|
|
297
306
|
)}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { Box, IconButton, Tooltip } from '@mui/material';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Box, Button, IconButton, Tooltip } from '@mui/material';
|
|
3
3
|
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
|
-
interface Props {
|
|
6
|
-
row: MRT_Row
|
|
7
|
-
table: MRT_TableInstance
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
6
|
+
row: MRT_Row<TData>;
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
8
|
+
variant?: 'icon' | 'text';
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export const MRT_EditActionButtons
|
|
11
|
+
export const MRT_EditActionButtons = <TData extends Record<string, any> = {}>({
|
|
12
|
+
row,
|
|
13
|
+
table,
|
|
14
|
+
variant = 'icon',
|
|
15
|
+
}: Props<TData>) => {
|
|
11
16
|
const {
|
|
12
17
|
getState,
|
|
13
18
|
options: {
|
|
@@ -20,7 +25,6 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
|
|
|
20
25
|
const { editingRow } = getState();
|
|
21
26
|
|
|
22
27
|
const handleCancel = () => {
|
|
23
|
-
row._valuesCache = { ...row.original };
|
|
24
28
|
setEditingRow(null);
|
|
25
29
|
};
|
|
26
30
|
|
|
@@ -35,20 +39,31 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
|
|
|
35
39
|
|
|
36
40
|
return (
|
|
37
41
|
<Box sx={{ display: 'flex', gap: '0.75rem' }}>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
{variant === 'icon' ? (
|
|
43
|
+
<>
|
|
44
|
+
<Tooltip arrow title={localization.cancel}>
|
|
45
|
+
<IconButton aria-label={localization.cancel} onClick={handleCancel}>
|
|
46
|
+
<CancelIcon />
|
|
47
|
+
</IconButton>
|
|
48
|
+
</Tooltip>
|
|
49
|
+
<Tooltip arrow title={localization.save}>
|
|
50
|
+
<IconButton
|
|
51
|
+
aria-label={localization.save}
|
|
52
|
+
color="info"
|
|
53
|
+
onClick={handleSave}
|
|
54
|
+
>
|
|
55
|
+
<SaveIcon />
|
|
56
|
+
</IconButton>
|
|
57
|
+
</Tooltip>
|
|
58
|
+
</>
|
|
59
|
+
) : (
|
|
60
|
+
<>
|
|
61
|
+
<Button onClick={handleCancel}>{localization.cancel}</Button>
|
|
62
|
+
<Button onClick={handleSave} variant="contained">
|
|
63
|
+
{localization.save}
|
|
64
|
+
</Button>
|
|
65
|
+
</>
|
|
66
|
+
)}
|
|
52
67
|
</Box>
|
|
53
68
|
);
|
|
54
69
|
};
|
|
@@ -24,6 +24,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
|
|
|
24
24
|
const {
|
|
25
25
|
getState,
|
|
26
26
|
options: {
|
|
27
|
+
editingMode,
|
|
27
28
|
enableEditing,
|
|
28
29
|
icons: { EditIcon, MoreHorizIcon },
|
|
29
30
|
localization,
|
|
@@ -52,7 +53,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
|
|
|
52
53
|
<>
|
|
53
54
|
{renderRowActions ? (
|
|
54
55
|
<>{renderRowActions({ row, table })}</>
|
|
55
|
-
) : row.id === editingRow?.id ? (
|
|
56
|
+
) : row.id === editingRow?.id && editingMode === 'row' ? (
|
|
56
57
|
<MRT_EditActionButtons row={row} table={table} />
|
|
57
58
|
) : !renderRowActionMenuItems && enableEditing ? (
|
|
58
59
|
<Tooltip placement="right" arrow title={localization.edit}>
|
package/src/column.utils.ts
CHANGED
|
@@ -116,7 +116,8 @@ export const getLeadingDisplayColumnIds = <
|
|
|
116
116
|
[
|
|
117
117
|
(props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
|
|
118
118
|
((props.positionActionsColumn === 'first' && props.enableRowActions) ||
|
|
119
|
-
(props.enableEditing &&
|
|
119
|
+
(props.enableEditing &&
|
|
120
|
+
['row', 'modal'].includes(props.editingMode ?? ''))) &&
|
|
120
121
|
'mrt-row-actions',
|
|
121
122
|
props.positionExpandColumn === 'first' &&
|
|
122
123
|
(props.enableExpanding ||
|
|
@@ -133,7 +134,8 @@ export const getTrailingDisplayColumnIds = <
|
|
|
133
134
|
props: MaterialReactTableProps<TData>,
|
|
134
135
|
) => [
|
|
135
136
|
((props.positionActionsColumn === 'last' && props.enableRowActions) ||
|
|
136
|
-
(props.enableEditing &&
|
|
137
|
+
(props.enableEditing &&
|
|
138
|
+
['row', 'modal'].includes(props.editingMode ?? ''))) &&
|
|
137
139
|
'mrt-row-actions',
|
|
138
140
|
props.positionExpandColumn === 'last' &&
|
|
139
141
|
(props.enableExpanding ||
|
|
@@ -1,53 +1,30 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
FocusEvent,
|
|
5
|
-
MouseEvent,
|
|
6
|
-
useState,
|
|
7
|
-
} from 'react';
|
|
8
|
-
import { TextField } from '@mui/material';
|
|
9
|
-
import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
|
|
1
|
+
import React, { ChangeEvent, FocusEvent, MouseEvent, useState } from 'react';
|
|
2
|
+
import { TextField, TextFieldProps } from '@mui/material';
|
|
3
|
+
import type { MRT_Cell, MRT_TableInstance } from '..';
|
|
10
4
|
|
|
11
|
-
interface Props {
|
|
12
|
-
cell: MRT_Cell
|
|
13
|
-
table: MRT_TableInstance
|
|
5
|
+
interface Props<TData extends Record<string, any> = {}> {
|
|
6
|
+
cell: MRT_Cell<TData>;
|
|
7
|
+
table: MRT_TableInstance<TData>;
|
|
8
|
+
showLabel?: boolean;
|
|
14
9
|
}
|
|
15
10
|
|
|
16
|
-
export const MRT_EditCellTextField
|
|
11
|
+
export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
|
|
12
|
+
cell,
|
|
13
|
+
showLabel,
|
|
14
|
+
table,
|
|
15
|
+
}: Props<TData>) => {
|
|
17
16
|
const {
|
|
18
17
|
getState,
|
|
19
|
-
options: {
|
|
20
|
-
tableId,
|
|
21
|
-
muiTableBodyCellEditTextFieldProps,
|
|
22
|
-
onCellEditBlur,
|
|
23
|
-
onCellEditChange,
|
|
24
|
-
},
|
|
18
|
+
options: { tableId, muiTableBodyCellEditTextFieldProps },
|
|
25
19
|
setEditingCell,
|
|
26
20
|
setEditingRow,
|
|
27
21
|
} = table;
|
|
28
|
-
const { column
|
|
22
|
+
const { column } = cell;
|
|
29
23
|
const { columnDef } = column;
|
|
30
24
|
const { editingRow } = getState();
|
|
31
25
|
|
|
32
26
|
const [value, setValue] = useState(() => cell.getValue<string>());
|
|
33
27
|
|
|
34
|
-
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
35
|
-
setValue(event.target.value);
|
|
36
|
-
columnDef.onCellEditChange?.({ event, cell, table, value });
|
|
37
|
-
onCellEditChange?.({ event, cell, table, value });
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
41
|
-
if (editingRow) {
|
|
42
|
-
if (!row._valuesCache) row._valuesCache = {};
|
|
43
|
-
(row._valuesCache as Record<string, any>)[column.id] = value;
|
|
44
|
-
setEditingRow({ ...editingRow } as MRT_Row);
|
|
45
|
-
}
|
|
46
|
-
setEditingCell(null);
|
|
47
|
-
columnDef.onCellEditBlur?.({ event, cell, table, value });
|
|
48
|
-
onCellEditBlur?.({ event, cell, table, value });
|
|
49
|
-
};
|
|
50
|
-
|
|
51
28
|
const mTableBodyCellEditTextFieldProps =
|
|
52
29
|
muiTableBodyCellEditTextFieldProps instanceof Function
|
|
53
30
|
? muiTableBodyCellEditTextFieldProps({ cell, table })
|
|
@@ -61,26 +38,45 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
|
|
|
61
38
|
})
|
|
62
39
|
: columnDef.muiTableBodyCellEditTextFieldProps;
|
|
63
40
|
|
|
64
|
-
const textFieldProps = {
|
|
41
|
+
const textFieldProps: TextFieldProps = {
|
|
65
42
|
...mTableBodyCellEditTextFieldProps,
|
|
66
43
|
...mcTableBodyCellEditTextFieldProps,
|
|
67
44
|
};
|
|
68
45
|
|
|
46
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
47
|
+
textFieldProps.onChange?.(event);
|
|
48
|
+
setValue(event.target.value);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
52
|
+
textFieldProps.onBlur?.(event);
|
|
53
|
+
if (editingRow) {
|
|
54
|
+
setEditingRow({
|
|
55
|
+
...editingRow,
|
|
56
|
+
_valuesCache: { ...editingRow._valuesCache, [column.id]: value },
|
|
57
|
+
} as any);
|
|
58
|
+
}
|
|
59
|
+
setEditingCell(null);
|
|
60
|
+
};
|
|
61
|
+
|
|
69
62
|
if (columnDef.Edit) {
|
|
70
63
|
return <>{columnDef.Edit?.({ cell, column, table })}</>;
|
|
71
64
|
}
|
|
72
65
|
|
|
73
66
|
return (
|
|
74
67
|
<TextField
|
|
68
|
+
disabled={columnDef.enableEditing === false}
|
|
69
|
+
fullWidth
|
|
75
70
|
id={`mrt-${tableId}-edit-cell-text-field-${cell.id}`}
|
|
71
|
+
label={showLabel ? column.columnDef.header : undefined}
|
|
76
72
|
margin="none"
|
|
77
|
-
onBlur={handleBlur}
|
|
78
|
-
onChange={handleChange}
|
|
79
73
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
80
74
|
placeholder={columnDef.header}
|
|
81
75
|
value={value}
|
|
82
76
|
variant="standard"
|
|
83
77
|
{...textFieldProps}
|
|
78
|
+
onBlur={handleBlur}
|
|
79
|
+
onChange={handleChange}
|
|
84
80
|
/>
|
|
85
81
|
);
|
|
86
82
|
};
|
|
@@ -33,6 +33,7 @@ import type {
|
|
|
33
33
|
MRT_TableState,
|
|
34
34
|
MaterialReactTableProps,
|
|
35
35
|
} from '..';
|
|
36
|
+
import { MRT_EditRowModal } from '../body/MRT_EditRowModal';
|
|
36
37
|
|
|
37
38
|
export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
38
39
|
props: MaterialReactTableProps<TData>,
|
|
@@ -300,6 +301,9 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
300
301
|
<MRT_TablePaper table={table} />
|
|
301
302
|
</Dialog>
|
|
302
303
|
{!isFullScreen && <MRT_TablePaper table={table} />}
|
|
304
|
+
{editingRow && props.editingMode === 'modal' && (
|
|
305
|
+
<MRT_EditRowModal row={editingRow as any} table={table} open />
|
|
306
|
+
)}
|
|
303
307
|
</>
|
|
304
308
|
);
|
|
305
309
|
};
|