material-react-table 0.36.1 → 0.37.1
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 +7 -3
- package/dist/cjs/MaterialReactTable.d.ts +33 -15
- package/dist/cjs/body/MRT_EditRowModal.d.ts +8 -0
- package/dist/cjs/buttons/MRT_EditActionButtons.d.ts +5 -5
- package/dist/cjs/column.utils.d.ts +2 -1
- package/dist/cjs/index.js +187 -118
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/inputs/MRT_EditCellTextField.d.ts +5 -5
- package/dist/esm/MaterialReactTable.d.ts +33 -15
- package/dist/esm/body/MRT_EditRowModal.d.ts +8 -0
- package/dist/esm/buttons/MRT_EditActionButtons.d.ts +5 -5
- package/dist/esm/column.utils.d.ts +2 -1
- package/dist/esm/inputs/MRT_EditCellTextField.d.ts +5 -5
- package/dist/esm/material-react-table.esm.js +188 -119
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/index.d.ts +33 -15
- package/package.json +4 -4
- package/src/MaterialReactTable.tsx +48 -12
- package/src/body/MRT_EditRowModal.tsx +59 -0
- package/src/body/MRT_TableBodyCell.tsx +12 -16
- package/src/body/MRT_TableBodyRow.tsx +1 -1
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +3 -2
- package/src/buttons/MRT_CopyButton.tsx +2 -2
- package/src/buttons/MRT_EditActionButtons.tsx +49 -25
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -16
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +2 -1
- package/src/column.utils.ts +19 -12
- package/src/inputs/MRT_EditCellTextField.tsx +33 -19
- package/src/inputs/MRT_FilterTextField.tsx +9 -6
- package/src/inputs/MRT_GlobalFilterTextField.tsx +7 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -12
- package/src/table/MRT_TableContainer.tsx +10 -10
- package/src/table/MRT_TableRoot.tsx +48 -30
- package/src/toolbar/MRT_BottomToolbar.tsx +8 -2
- package/src/toolbar/MRT_TopToolbar.tsx +8 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
|
|
1
|
+
import { MutableRefObject, 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';
|
|
@@ -223,9 +223,16 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
|
|
|
223
223
|
getState: () => MRT_TableState<TData>;
|
|
224
224
|
options: MaterialReactTableProps<TData> & {
|
|
225
225
|
icons: MRT_Icons;
|
|
226
|
-
tableId: string;
|
|
227
226
|
localization: MRT_Localization;
|
|
228
227
|
};
|
|
228
|
+
refs: {
|
|
229
|
+
bottomToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
230
|
+
editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
231
|
+
filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
232
|
+
searchInputRef: MutableRefObject<HTMLInputElement>;
|
|
233
|
+
tableContainerRef: MutableRefObject<HTMLDivElement>;
|
|
234
|
+
topToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
235
|
+
};
|
|
229
236
|
setColumnFilterFns: Dispatch<SetStateAction<{
|
|
230
237
|
[key: string]: MRT_FilterOption;
|
|
231
238
|
}>>;
|
|
@@ -269,19 +276,22 @@ declare type MRT_TableState<TData extends Record<string, any> = {}> = TableState
|
|
|
269
276
|
showSkeletons: boolean;
|
|
270
277
|
};
|
|
271
278
|
declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnDef<TData, unknown>, 'aggregatedCell' | 'cell' | 'columns' | 'filterFn' | 'footer' | 'header' | 'id' | 'sortingFn'> & {
|
|
272
|
-
AggregatedCell?: ({ cell, column, table, }: {
|
|
279
|
+
AggregatedCell?: ({ cell, column, row, table, }: {
|
|
273
280
|
cell: MRT_Cell<TData>;
|
|
274
281
|
column: MRT_Column<TData>;
|
|
282
|
+
row: MRT_Row<TData>;
|
|
275
283
|
table: MRT_TableInstance<TData>;
|
|
276
284
|
}) => ReactNode;
|
|
277
|
-
Cell?: ({ cell, column, table, }: {
|
|
285
|
+
Cell?: ({ cell, column, row, table, }: {
|
|
278
286
|
cell: MRT_Cell<TData>;
|
|
279
287
|
column: MRT_Column<TData>;
|
|
288
|
+
row: MRT_Row<TData>;
|
|
280
289
|
table: MRT_TableInstance<TData>;
|
|
281
290
|
}) => ReactNode;
|
|
282
|
-
Edit?: ({ cell, column, table, }: {
|
|
291
|
+
Edit?: ({ cell, column, row, table, }: {
|
|
283
292
|
cell: MRT_Cell<TData>;
|
|
284
293
|
column: MRT_Column<TData>;
|
|
294
|
+
row: MRT_Row<TData>;
|
|
285
295
|
table: MRT_TableInstance<TData>;
|
|
286
296
|
}) => ReactNode;
|
|
287
297
|
Filter?: ({ column, header, table, }: {
|
|
@@ -360,8 +370,10 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
360
370
|
table: MRT_TableInstance<TData>;
|
|
361
371
|
cell: MRT_Cell<TData>;
|
|
362
372
|
}) => ButtonProps);
|
|
363
|
-
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, table, }: {
|
|
373
|
+
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, column, row, table, }: {
|
|
364
374
|
cell: MRT_Cell<TData>;
|
|
375
|
+
column: MRT_Column<TData>;
|
|
376
|
+
row: MRT_Row<TData>;
|
|
365
377
|
table: MRT_TableInstance<TData>;
|
|
366
378
|
}) => TextFieldProps);
|
|
367
379
|
muiTableBodyCellProps?: TableCellProps | (({ cell, table, }: {
|
|
@@ -422,7 +434,7 @@ declare type MRT_SortingOption = LiteralUnion<string & keyof typeof MRT_SortingF
|
|
|
422
434
|
declare type MRT_SortingFn<TData extends Record<string, any> = {}> = SortingFn<TData> | MRT_SortingOption;
|
|
423
435
|
declare type MRT_FilterOption = LiteralUnion<string & keyof typeof MRT_FilterFns>;
|
|
424
436
|
declare type MRT_FilterFn<TData extends Record<string, any> = {}> = FilterFn<TData> | MRT_FilterOption;
|
|
425
|
-
declare type MRT_DisplayColumnIds = 'mrt-row-
|
|
437
|
+
declare type MRT_DisplayColumnIds = 'mrt-row-actions' | 'mrt-row-drag' | 'mrt-row-expand' | 'mrt-row-numbers' | 'mrt-row-select';
|
|
426
438
|
/**
|
|
427
439
|
* `columns` and `data` props are the only required props, but there are over 150 other optional props.
|
|
428
440
|
*
|
|
@@ -440,7 +452,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
440
452
|
displayColumnDefOptions?: Partial<{
|
|
441
453
|
[key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
|
|
442
454
|
}>;
|
|
443
|
-
editingMode?: 'table' | 'row' | 'cell';
|
|
455
|
+
editingMode?: 'table' | 'modal' | 'row' | 'cell';
|
|
444
456
|
enableBottomToolbar?: boolean;
|
|
445
457
|
enableClickToCopy?: boolean;
|
|
446
458
|
enableColumnActions?: boolean;
|
|
@@ -492,17 +504,23 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
492
504
|
table: MRT_TableInstance<TData>;
|
|
493
505
|
row: MRT_Row<TData>;
|
|
494
506
|
}) => CheckboxProps);
|
|
495
|
-
muiTableBodyCellCopyButtonProps?: ButtonProps | (({
|
|
496
|
-
table: MRT_TableInstance<TData>;
|
|
507
|
+
muiTableBodyCellCopyButtonProps?: ButtonProps | (({ cell, column, row, table, }: {
|
|
497
508
|
cell: MRT_Cell<TData>;
|
|
509
|
+
column: MRT_Column<TData>;
|
|
510
|
+
row: MRT_Row<TData>;
|
|
511
|
+
table: MRT_TableInstance<TData>;
|
|
498
512
|
}) => ButtonProps);
|
|
499
|
-
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, table, }: {
|
|
513
|
+
muiTableBodyCellEditTextFieldProps?: TextFieldProps | (({ cell, column, row, table, }: {
|
|
500
514
|
cell: MRT_Cell<TData>;
|
|
515
|
+
column: MRT_Column<TData>;
|
|
516
|
+
row: MRT_Row<TData>;
|
|
501
517
|
table: MRT_TableInstance<TData>;
|
|
502
518
|
}) => TextFieldProps);
|
|
503
|
-
muiTableBodyCellProps?: TableCellProps | (({
|
|
504
|
-
table: MRT_TableInstance<TData>;
|
|
519
|
+
muiTableBodyCellProps?: TableCellProps | (({ cell, column, row, table, }: {
|
|
505
520
|
cell: MRT_Cell<TData>;
|
|
521
|
+
column: MRT_Column<TData>;
|
|
522
|
+
row: MRT_Row<TData>;
|
|
523
|
+
table: MRT_TableInstance<TData>;
|
|
506
524
|
}) => TableCellProps);
|
|
507
525
|
muiTableBodyCellSkeletonProps?: SkeletonProps | (({ table, cell, }: {
|
|
508
526
|
table: MRT_TableInstance<TData>;
|
|
@@ -589,7 +607,8 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
589
607
|
onDensityChange?: OnChangeFn<boolean>;
|
|
590
608
|
onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
|
591
609
|
onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
592
|
-
onEditingRowSave?: ({ row, table, values, }: {
|
|
610
|
+
onEditingRowSave?: ({ exitEditingMode, row, table, values, }: {
|
|
611
|
+
exitEditingMode: () => void;
|
|
593
612
|
row: MRT_Row<TData>;
|
|
594
613
|
table: MRT_TableInstance<TData>;
|
|
595
614
|
values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
|
|
@@ -645,7 +664,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
645
664
|
rowNumberMode?: 'original' | 'static';
|
|
646
665
|
selectAllMode?: 'all' | 'page';
|
|
647
666
|
state?: Partial<MRT_TableState<TData>>;
|
|
648
|
-
tableId?: string;
|
|
649
667
|
virtualizerProps?: Partial<Options<HTMLDivElement>> | (({ table, }: {
|
|
650
668
|
table: MRT_TableInstance<TData>;
|
|
651
669
|
}) => Partial<Options<HTMLDivElement>>);
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.37.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@emotion/styled": "^11.10.0",
|
|
56
56
|
"@faker-js/faker": "^7.4.0",
|
|
57
57
|
"@mui/icons-material": "^5.8.4",
|
|
58
|
-
"@mui/material": "^5.10.
|
|
58
|
+
"@mui/material": "^5.10.1",
|
|
59
59
|
"@rollup/plugin-babel": "^5.3.1",
|
|
60
60
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
61
61
|
"@rollup/plugin-typescript": "^8.3.4",
|
|
@@ -71,14 +71,14 @@
|
|
|
71
71
|
"@types/react": "^18.0.17",
|
|
72
72
|
"@types/react-dom": "^18.0.6",
|
|
73
73
|
"babel-loader": "^8.2.5",
|
|
74
|
-
"eslint": "^8.
|
|
74
|
+
"eslint": "^8.22.0",
|
|
75
75
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
76
76
|
"husky": "^8.0.1",
|
|
77
77
|
"prettier": "^2.7.1",
|
|
78
78
|
"react": "^18.2.0",
|
|
79
79
|
"react-dom": "^18.2.0",
|
|
80
80
|
"react-is": "^18.2.0",
|
|
81
|
-
"rollup": "^2.
|
|
81
|
+
"rollup": "^2.78.0",
|
|
82
82
|
"rollup-plugin-dts": "^4.2.2",
|
|
83
83
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
84
84
|
"size-limit": "^8.0.1",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
Dispatch,
|
|
3
|
+
DragEvent,
|
|
4
|
+
MutableRefObject,
|
|
5
|
+
ReactNode,
|
|
6
|
+
SetStateAction,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import type {
|
|
3
9
|
AlertProps,
|
|
4
10
|
ButtonProps,
|
|
@@ -86,9 +92,16 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
|
|
|
86
92
|
getState: () => MRT_TableState<TData>;
|
|
87
93
|
options: MaterialReactTableProps<TData> & {
|
|
88
94
|
icons: MRT_Icons;
|
|
89
|
-
tableId: string;
|
|
90
95
|
localization: MRT_Localization;
|
|
91
96
|
};
|
|
97
|
+
refs: {
|
|
98
|
+
bottomToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
99
|
+
editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
100
|
+
filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
101
|
+
searchInputRef: MutableRefObject<HTMLInputElement>;
|
|
102
|
+
tableContainerRef: MutableRefObject<HTMLDivElement>;
|
|
103
|
+
topToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
104
|
+
};
|
|
92
105
|
setColumnFilterFns: Dispatch<
|
|
93
106
|
SetStateAction<{ [key: string]: MRT_FilterOption }>
|
|
94
107
|
>;
|
|
@@ -144,28 +157,34 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
144
157
|
AggregatedCell?: ({
|
|
145
158
|
cell,
|
|
146
159
|
column,
|
|
160
|
+
row,
|
|
147
161
|
table,
|
|
148
162
|
}: {
|
|
149
163
|
cell: MRT_Cell<TData>;
|
|
150
164
|
column: MRT_Column<TData>;
|
|
165
|
+
row: MRT_Row<TData>;
|
|
151
166
|
table: MRT_TableInstance<TData>;
|
|
152
167
|
}) => ReactNode;
|
|
153
168
|
Cell?: ({
|
|
154
169
|
cell,
|
|
155
170
|
column,
|
|
171
|
+
row,
|
|
156
172
|
table,
|
|
157
173
|
}: {
|
|
158
174
|
cell: MRT_Cell<TData>;
|
|
159
175
|
column: MRT_Column<TData>;
|
|
176
|
+
row: MRT_Row<TData>;
|
|
160
177
|
table: MRT_TableInstance<TData>;
|
|
161
178
|
}) => ReactNode;
|
|
162
179
|
Edit?: ({
|
|
163
180
|
cell,
|
|
164
181
|
column,
|
|
182
|
+
row,
|
|
165
183
|
table,
|
|
166
184
|
}: {
|
|
167
185
|
cell: MRT_Cell<TData>;
|
|
168
186
|
column: MRT_Column<TData>;
|
|
187
|
+
row: MRT_Row<TData>;
|
|
169
188
|
table: MRT_TableInstance<TData>;
|
|
170
189
|
}) => ReactNode;
|
|
171
190
|
Filter?: ({
|
|
@@ -266,9 +285,13 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
266
285
|
| TextFieldProps
|
|
267
286
|
| (({
|
|
268
287
|
cell,
|
|
288
|
+
column,
|
|
289
|
+
row,
|
|
269
290
|
table,
|
|
270
291
|
}: {
|
|
271
292
|
cell: MRT_Cell<TData>;
|
|
293
|
+
column: MRT_Column<TData>;
|
|
294
|
+
row: MRT_Row<TData>;
|
|
272
295
|
table: MRT_TableInstance<TData>;
|
|
273
296
|
}) => TextFieldProps);
|
|
274
297
|
muiTableBodyCellProps?:
|
|
@@ -398,11 +421,11 @@ export type MRT_FilterFn<TData extends Record<string, any> = {}> =
|
|
|
398
421
|
| MRT_FilterOption;
|
|
399
422
|
|
|
400
423
|
export type MRT_DisplayColumnIds =
|
|
401
|
-
| 'mrt-row-drag'
|
|
402
424
|
| 'mrt-row-actions'
|
|
425
|
+
| 'mrt-row-drag'
|
|
403
426
|
| 'mrt-row-expand'
|
|
404
|
-
| 'mrt-row-
|
|
405
|
-
| 'mrt-row-
|
|
427
|
+
| 'mrt-row-numbers'
|
|
428
|
+
| 'mrt-row-select';
|
|
406
429
|
|
|
407
430
|
/**
|
|
408
431
|
* `columns` and `data` props are the only required props, but there are over 150 other optional props.
|
|
@@ -432,7 +455,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
432
455
|
displayColumnDefOptions?: Partial<{
|
|
433
456
|
[key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
|
|
434
457
|
}>;
|
|
435
|
-
editingMode?: 'table' | 'row' | 'cell';
|
|
458
|
+
editingMode?: 'table' | 'modal' | 'row' | 'cell';
|
|
436
459
|
enableBottomToolbar?: boolean;
|
|
437
460
|
enableClickToCopy?: boolean;
|
|
438
461
|
enableColumnActions?: boolean;
|
|
@@ -501,29 +524,41 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
501
524
|
muiTableBodyCellCopyButtonProps?:
|
|
502
525
|
| ButtonProps
|
|
503
526
|
| (({
|
|
504
|
-
table,
|
|
505
527
|
cell,
|
|
528
|
+
column,
|
|
529
|
+
row,
|
|
530
|
+
table,
|
|
506
531
|
}: {
|
|
507
|
-
table: MRT_TableInstance<TData>;
|
|
508
532
|
cell: MRT_Cell<TData>;
|
|
533
|
+
column: MRT_Column<TData>;
|
|
534
|
+
row: MRT_Row<TData>;
|
|
535
|
+
table: MRT_TableInstance<TData>;
|
|
509
536
|
}) => ButtonProps);
|
|
510
537
|
muiTableBodyCellEditTextFieldProps?:
|
|
511
538
|
| TextFieldProps
|
|
512
539
|
| (({
|
|
513
540
|
cell,
|
|
541
|
+
column,
|
|
542
|
+
row,
|
|
514
543
|
table,
|
|
515
544
|
}: {
|
|
516
545
|
cell: MRT_Cell<TData>;
|
|
546
|
+
column: MRT_Column<TData>;
|
|
547
|
+
row: MRT_Row<TData>;
|
|
517
548
|
table: MRT_TableInstance<TData>;
|
|
518
549
|
}) => TextFieldProps);
|
|
519
550
|
muiTableBodyCellProps?:
|
|
520
551
|
| TableCellProps
|
|
521
552
|
| (({
|
|
522
|
-
table,
|
|
523
553
|
cell,
|
|
554
|
+
column,
|
|
555
|
+
row,
|
|
556
|
+
table,
|
|
524
557
|
}: {
|
|
525
|
-
table: MRT_TableInstance<TData>;
|
|
526
558
|
cell: MRT_Cell<TData>;
|
|
559
|
+
column: MRT_Column<TData>;
|
|
560
|
+
row: MRT_Row<TData>;
|
|
561
|
+
table: MRT_TableInstance<TData>;
|
|
527
562
|
}) => TableCellProps);
|
|
528
563
|
muiTableBodyCellSkeletonProps?:
|
|
529
564
|
| SkeletonProps
|
|
@@ -677,10 +712,12 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
677
712
|
onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
|
678
713
|
onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
679
714
|
onEditingRowSave?: ({
|
|
715
|
+
exitEditingMode,
|
|
680
716
|
row,
|
|
681
717
|
table,
|
|
682
718
|
values,
|
|
683
719
|
}: {
|
|
720
|
+
exitEditingMode: () => void;
|
|
684
721
|
row: MRT_Row<TData>;
|
|
685
722
|
table: MRT_TableInstance<TData>;
|
|
686
723
|
values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
|
|
@@ -752,7 +789,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
752
789
|
rowNumberMode?: 'original' | 'static';
|
|
753
790
|
selectAllMode?: 'all' | 'page';
|
|
754
791
|
state?: Partial<MRT_TableState<TData>>;
|
|
755
|
-
tableId?: string;
|
|
756
792
|
virtualizerProps?:
|
|
757
793
|
| Partial<VirtualizerOptions<HTMLDivElement>>
|
|
758
794
|
| (({
|
|
@@ -774,7 +810,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
774
810
|
autoResetExpanded = false,
|
|
775
811
|
columnResizeMode = 'onEnd',
|
|
776
812
|
defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
|
|
777
|
-
editingMode = '
|
|
813
|
+
editingMode = 'modal',
|
|
778
814
|
enableBottomToolbar = true,
|
|
779
815
|
enableColumnActions = true,
|
|
780
816
|
enableColumnFilterChangeMode = false,
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
<form onSubmit={(e) => e.preventDefault()}>
|
|
33
|
+
<Stack
|
|
34
|
+
sx={{
|
|
35
|
+
width: '100%',
|
|
36
|
+
minWidth: { xs: '300px', sm: '360px', md: '400px' },
|
|
37
|
+
gap: '1.5rem',
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
{row
|
|
41
|
+
.getAllCells()
|
|
42
|
+
.filter((cell) => cell.column.columnDef.columnDefType === 'data')
|
|
43
|
+
.map((cell) => (
|
|
44
|
+
<MRT_EditCellTextField
|
|
45
|
+
cell={cell as any}
|
|
46
|
+
key={cell.id}
|
|
47
|
+
showLabel
|
|
48
|
+
table={table as any}
|
|
49
|
+
/>
|
|
50
|
+
))}
|
|
51
|
+
</Stack>
|
|
52
|
+
</form>
|
|
53
|
+
</DialogContent>
|
|
54
|
+
<DialogActions sx={{ p: '1.25rem' }}>
|
|
55
|
+
<MRT_EditActionButtons row={row} table={table} variant="text" />
|
|
56
|
+
</DialogActions>
|
|
57
|
+
</Dialog>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -48,8 +48,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
48
48
|
muiTableBodyCellProps,
|
|
49
49
|
muiTableBodyCellSkeletonProps,
|
|
50
50
|
rowNumberMode,
|
|
51
|
-
tableId,
|
|
52
51
|
},
|
|
52
|
+
refs: { editInputRefs },
|
|
53
53
|
setEditingCell,
|
|
54
54
|
setHoveredColumn,
|
|
55
55
|
} = table;
|
|
@@ -68,7 +68,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
68
68
|
|
|
69
69
|
const mTableCellBodyProps =
|
|
70
70
|
muiTableBodyCellProps instanceof Function
|
|
71
|
-
? muiTableBodyCellProps({ cell, table })
|
|
71
|
+
? muiTableBodyCellProps({ cell, column, row, table })
|
|
72
72
|
: muiTableBodyCellProps;
|
|
73
73
|
|
|
74
74
|
const mcTableCellBodyProps =
|
|
@@ -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);
|
|
@@ -114,15 +115,13 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
114
115
|
editingMode === 'cell'
|
|
115
116
|
) {
|
|
116
117
|
setEditingCell(cell);
|
|
117
|
-
|
|
118
|
-
const textField =
|
|
119
|
-
`mrt-${tableId}-edit-cell-text-field-${cell.id}`,
|
|
120
|
-
) as HTMLInputElement;
|
|
118
|
+
queueMicrotask(() => {
|
|
119
|
+
const textField = editInputRefs.current[column.id];
|
|
121
120
|
if (textField) {
|
|
122
121
|
textField.focus();
|
|
123
122
|
textField.select();
|
|
124
123
|
}
|
|
125
|
-
}
|
|
124
|
+
});
|
|
126
125
|
}
|
|
127
126
|
};
|
|
128
127
|
|
|
@@ -241,13 +240,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
241
240
|
enableHover &&
|
|
242
241
|
enableEditing &&
|
|
243
242
|
columnDef.enableEditing !== false &&
|
|
244
|
-
editingMode
|
|
243
|
+
['table', 'cell'].includes(editingMode ?? '')
|
|
245
244
|
? theme.palette.mode === 'dark'
|
|
246
|
-
? `${lighten(
|
|
247
|
-
|
|
248
|
-
0.13,
|
|
249
|
-
)} !important`
|
|
250
|
-
: `${darken(theme.palette.background.default, 0.07)} !important`
|
|
245
|
+
? `${lighten(theme.palette.background.default, 0.2)} !important`
|
|
246
|
+
: `${darken(theme.palette.background.default, 0.1)} !important`
|
|
251
247
|
: undefined,
|
|
252
248
|
},
|
|
253
249
|
...(tableCellProps?.sx instanceof Function
|
|
@@ -281,7 +277,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
281
277
|
(column.id === 'mrt-row-select' ||
|
|
282
278
|
column.id === 'mrt-row-expand' ||
|
|
283
279
|
!row.getIsGrouped()) ? (
|
|
284
|
-
columnDef.Cell?.({ cell, column, table })
|
|
280
|
+
columnDef.Cell?.({ cell, column, row, table })
|
|
285
281
|
) : isEditing ? (
|
|
286
282
|
<MRT_EditCellTextField cell={cell} table={table} />
|
|
287
283
|
) : (enableClickToCopy || columnDef.enableClickToCopy) &&
|
|
@@ -291,7 +287,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
291
287
|
<>
|
|
292
288
|
{row.getIsGrouped() && !cell.getIsGrouped()
|
|
293
289
|
? null
|
|
294
|
-
: columnDef?.Cell?.({ cell, column, table }) ??
|
|
290
|
+
: columnDef?.Cell?.({ cell, column, row, table }) ??
|
|
295
291
|
cell.renderValue()}
|
|
296
292
|
</>
|
|
297
293
|
</MRT_CopyButton>
|
|
@@ -301,7 +297,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
301
297
|
<>
|
|
302
298
|
{row.getIsGrouped() && !cell.getIsGrouped()
|
|
303
299
|
? null
|
|
304
|
-
: columnDef?.Cell?.({ cell, column, table }) ??
|
|
300
|
+
: columnDef?.Cell?.({ cell, column, row, table }) ??
|
|
305
301
|
cell.renderValue()}
|
|
306
302
|
{cell.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
|
|
307
303
|
</>
|
|
@@ -76,8 +76,8 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
|
|
|
76
76
|
{row?.getVisibleCells()?.map?.((cell) => (
|
|
77
77
|
<MRT_TableBodyCell
|
|
78
78
|
cell={cell}
|
|
79
|
-
key={cell.id}
|
|
80
79
|
enableHover={tableRowProps?.hover !== false}
|
|
80
|
+
key={cell.id}
|
|
81
81
|
rowIndex={rowIndex}
|
|
82
82
|
rowRef={rowRef}
|
|
83
83
|
table={table}
|
|
@@ -16,15 +16,16 @@ export const MRT_TableBodyRowGrabHandle: FC<Props> = ({
|
|
|
16
16
|
const {
|
|
17
17
|
options: { muiTableBodyRowDragHandleProps, onRowDrop },
|
|
18
18
|
} = table;
|
|
19
|
+
const { row } = cell;
|
|
19
20
|
|
|
20
21
|
const iconButtonProps =
|
|
21
22
|
muiTableBodyRowDragHandleProps instanceof Function
|
|
22
|
-
? muiTableBodyRowDragHandleProps({ row
|
|
23
|
+
? muiTableBodyRowDragHandleProps({ row, table })
|
|
23
24
|
: muiTableBodyRowDragHandleProps;
|
|
24
25
|
|
|
25
26
|
const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
|
|
26
27
|
e.dataTransfer.setDragImage(rowRef.current as HTMLElement, 0, 0);
|
|
27
|
-
table.setDraggingRow(
|
|
28
|
+
table.setDraggingRow(row as any);
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
const handleDragEnd = (event: DragEvent<HTMLButtonElement>) => {
|
|
@@ -12,7 +12,7 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
|
|
|
12
12
|
const {
|
|
13
13
|
options: { localization, muiTableBodyCellCopyButtonProps },
|
|
14
14
|
} = table;
|
|
15
|
-
const { column } = cell;
|
|
15
|
+
const { column, row } = cell;
|
|
16
16
|
const { columnDef } = column;
|
|
17
17
|
|
|
18
18
|
const [copied, setCopied] = useState(false);
|
|
@@ -25,7 +25,7 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
|
|
|
25
25
|
|
|
26
26
|
const mTableBodyCellCopyButtonProps =
|
|
27
27
|
muiTableBodyCellCopyButtonProps instanceof Function
|
|
28
|
-
? muiTableBodyCellCopyButtonProps({ cell, table })
|
|
28
|
+
? muiTableBodyCellCopyButtonProps({ cell, column, row, table })
|
|
29
29
|
: muiTableBodyCellCopyButtonProps;
|
|
30
30
|
|
|
31
31
|
const mcTableBodyCellCopyButtonProps =
|
|
@@ -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: {
|
|
@@ -15,40 +20,59 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, table }) => {
|
|
|
15
20
|
localization,
|
|
16
21
|
onEditingRowSave,
|
|
17
22
|
},
|
|
23
|
+
refs: { editInputRefs },
|
|
18
24
|
setEditingRow,
|
|
19
25
|
} = table;
|
|
20
26
|
const { editingRow } = getState();
|
|
21
27
|
|
|
22
|
-
const handleCancel = () =>
|
|
23
|
-
row._valuesCache = { ...row.original };
|
|
24
|
-
setEditingRow(null);
|
|
25
|
-
};
|
|
28
|
+
const handleCancel = () => setEditingRow(null);
|
|
26
29
|
|
|
27
30
|
const handleSave = () => {
|
|
31
|
+
//look for auto-filled input values
|
|
32
|
+
Object.values(editInputRefs?.current)?.forEach((input) => {
|
|
33
|
+
if (
|
|
34
|
+
input.value !== undefined &&
|
|
35
|
+
Object.hasOwn(editingRow?._valuesCache as object, input.name)
|
|
36
|
+
) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
editingRow._valuesCache[input.name] = input.value;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
28
41
|
onEditingRowSave?.({
|
|
42
|
+
exitEditingMode: () => setEditingRow(null),
|
|
29
43
|
row: editingRow ?? row,
|
|
30
44
|
table,
|
|
31
45
|
values: editingRow?._valuesCache ?? { ...row.original },
|
|
32
46
|
});
|
|
33
|
-
setEditingRow(null);
|
|
34
47
|
};
|
|
35
48
|
|
|
36
49
|
return (
|
|
37
50
|
<Box sx={{ display: 'flex', gap: '0.75rem' }}>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
{variant === 'icon' ? (
|
|
52
|
+
<>
|
|
53
|
+
<Tooltip arrow title={localization.cancel}>
|
|
54
|
+
<IconButton aria-label={localization.cancel} onClick={handleCancel}>
|
|
55
|
+
<CancelIcon />
|
|
56
|
+
</IconButton>
|
|
57
|
+
</Tooltip>
|
|
58
|
+
<Tooltip arrow title={localization.save}>
|
|
59
|
+
<IconButton
|
|
60
|
+
aria-label={localization.save}
|
|
61
|
+
color="info"
|
|
62
|
+
onClick={handleSave}
|
|
63
|
+
>
|
|
64
|
+
<SaveIcon />
|
|
65
|
+
</IconButton>
|
|
66
|
+
</Tooltip>
|
|
67
|
+
</>
|
|
68
|
+
) : (
|
|
69
|
+
<>
|
|
70
|
+
<Button onClick={handleCancel}>{localization.cancel}</Button>
|
|
71
|
+
<Button onClick={handleSave} variant="contained">
|
|
72
|
+
{localization.save}
|
|
73
|
+
</Button>
|
|
74
|
+
</>
|
|
75
|
+
)}
|
|
52
76
|
</Box>
|
|
53
77
|
);
|
|
54
78
|
};
|
|
@@ -17,30 +17,17 @@ export const MRT_ToggleGlobalFilterButton = <
|
|
|
17
17
|
getState,
|
|
18
18
|
options: {
|
|
19
19
|
icons: { SearchIcon, SearchOffIcon },
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
localization,
|
|
22
|
-
muiSearchTextFieldProps,
|
|
23
22
|
},
|
|
23
|
+
refs: { searchInputRef },
|
|
24
24
|
setShowGlobalFilter,
|
|
25
25
|
} = table;
|
|
26
26
|
const { showGlobalFilter } = getState();
|
|
27
27
|
|
|
28
|
-
const textFieldProps =
|
|
29
|
-
muiSearchTextFieldProps instanceof Function
|
|
30
|
-
? muiSearchTextFieldProps({ table })
|
|
31
|
-
: muiSearchTextFieldProps;
|
|
32
|
-
|
|
33
28
|
const handleToggleSearch = () => {
|
|
34
29
|
setShowGlobalFilter(!showGlobalFilter);
|
|
35
|
-
|
|
36
|
-
() =>
|
|
37
|
-
document
|
|
38
|
-
.getElementById(
|
|
39
|
-
textFieldProps?.id ?? `mrt-${tableId}-search-text-field`,
|
|
40
|
-
)
|
|
41
|
-
?.focus(),
|
|
42
|
-
200,
|
|
43
|
-
);
|
|
30
|
+
queueMicrotask(() => searchInputRef.current?.focus());
|
|
44
31
|
};
|
|
45
32
|
|
|
46
33
|
return (
|