material-react-table 0.7.0-alpha.4 → 0.7.0-alpha.7

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.0-alpha.4",
2
+ "version": "0.7.0-alpha.7",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -2,6 +2,7 @@ import React, {
2
2
  ChangeEvent,
3
3
  Dispatch,
4
4
  FC,
5
+ FocusEvent,
5
6
  MouseEvent,
6
7
  ReactNode,
7
8
  SetStateAction,
@@ -46,6 +47,11 @@ import { MRT_Default_Icons, MRT_Icons } from './icons';
46
47
  import { MRT_FILTER_TYPE } from './enums';
47
48
  import { MRT_TableRoot } from './table/MRT_TableRoot';
48
49
 
50
+ //@ts-ignore
51
+ global.performance = global.performance || {
52
+ now: () => new Date().getTime(),
53
+ };
54
+
49
55
  export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
50
56
  Omit<
51
57
  Options<D>,
@@ -241,6 +247,15 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
241
247
  tableInstance: MRT_TableInstance;
242
248
  column: MRT_ColumnInstance<D>;
243
249
  }) => TableCellProps);
250
+ onCellEditBlur?: ({
251
+ cell,
252
+ event,
253
+ tableInstance,
254
+ }: {
255
+ event: FocusEvent<HTMLInputElement>;
256
+ cell: MRT_Cell<D>;
257
+ tableInstance: MRT_TableInstance<D>;
258
+ }) => void;
244
259
  onCellEditChange?: ({
245
260
  cell,
246
261
  event,
@@ -321,7 +336,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
321
336
  enablePagination?: boolean;
322
337
  enableRowActions?: boolean;
323
338
  enableStickyHeader?: boolean;
324
- enableRowEditing?: boolean;
339
+ enableEditing?: boolean;
325
340
  enableRowNumbers?: boolean;
326
341
  enableSelectAll?: boolean;
327
342
  enabledGlobalFilterTypes?: (MRT_FILTER_TYPE | string)[];
@@ -582,7 +597,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
582
597
  row: MRT_Row<D>;
583
598
  tableInstance: MRT_TableInstance<D>;
584
599
  }) => void;
585
- onRowEditSubmit?: ({
600
+ onEditSubmit?: ({
586
601
  row,
587
602
  tableInstance,
588
603
  }: {
@@ -16,6 +16,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
16
16
  options: {
17
17
  enableClickToCopy,
18
18
  enableColumnPinning,
19
+ enableEditing,
19
20
  isLoading,
20
21
  muiTableBodyCellProps,
21
22
  muiTableBodyCellSkeletonProps,
@@ -93,7 +94,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
93
94
  column.id !==
94
95
  row.groupingColumnId) ? null : cell.getIsAggregated() ? (
95
96
  cell.renderAggregatedCell()
96
- ) : column.enableEditing && currentEditingRow?.id === row.id ? (
97
+ ) : (enableEditing && column.enableEditing !== false) && currentEditingRow?.id === row.id ? (
97
98
  <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
98
99
  ) : (enableClickToCopy || column.enableClickToCopy) &&
99
100
  column.enableClickToCopy !== false ? (
@@ -14,7 +14,7 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, tableInstance }) => {
14
14
  options: {
15
15
  icons: { CancelIcon, SaveIcon },
16
16
  localization,
17
- onRowEditSubmit,
17
+ onEditSubmit,
18
18
  setCurrentEditingRow,
19
19
  },
20
20
  } = tableInstance;
@@ -27,7 +27,7 @@ export const MRT_EditActionButtons: FC<Props> = ({ row, tableInstance }) => {
27
27
  };
28
28
 
29
29
  const handleSave = () => {
30
- onRowEditSubmit?.({ row: currentEditingRow ?? row, tableInstance });
30
+ onEditSubmit?.({ row: currentEditingRow ?? row, tableInstance });
31
31
  setCurrentEditingRow(null);
32
32
  };
33
33
 
@@ -27,7 +27,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
27
27
  const {
28
28
  getState,
29
29
  options: {
30
- enableRowEditing,
30
+ enableEditing,
31
31
  icons: { EditIcon, MoreHorizIcon },
32
32
  localization,
33
33
  renderRowActionMenuItems,
@@ -46,7 +46,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
46
46
  setAnchorEl(event.currentTarget);
47
47
  };
48
48
 
49
- const handleEdit = () => {
49
+ const handleStartEditMode = () => {
50
50
  setCurrentEditingRow({ ...row });
51
51
  setAnchorEl(null);
52
52
  };
@@ -57,9 +57,9 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
57
57
  <>{renderRowActions({ row, tableInstance })}</>
58
58
  ) : row.id === currentEditingRow?.id ? (
59
59
  <MRT_EditActionButtons row={row} tableInstance={tableInstance} />
60
- ) : !renderRowActionMenuItems && enableRowEditing ? (
60
+ ) : !renderRowActionMenuItems && enableEditing ? (
61
61
  <Tooltip placement="right" arrow title={localization.edit}>
62
- <IconButton sx={commonIconButtonStyles} onClick={handleEdit}>
62
+ <IconButton sx={commonIconButtonStyles} onClick={handleStartEditMode}>
63
63
  <EditIcon />
64
64
  </IconButton>
65
65
  </Tooltip>
@@ -82,7 +82,7 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({
82
82
  </Tooltip>
83
83
  <MRT_RowActionMenu
84
84
  anchorEl={anchorEl}
85
- handleEdit={handleEdit}
85
+ handleEdit={handleStartEditMode}
86
86
  row={row}
87
87
  setAnchorEl={setAnchorEl}
88
88
  tableInstance={tableInstance}
@@ -1,6 +1,12 @@
1
- import React, { ChangeEvent, FC, MouseEvent } from 'react';
1
+ import React, {
2
+ ChangeEvent,
3
+ FC,
4
+ FocusEvent,
5
+ MouseEvent,
6
+ useState,
7
+ } from 'react';
2
8
  import { TextField } from '@mui/material';
3
- import type { MRT_Cell, MRT_TableInstance } from '..';
9
+ import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
4
10
 
5
11
  interface Props {
6
12
  cell: MRT_Cell;
@@ -10,19 +16,28 @@ interface Props {
10
16
  export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
11
17
  const {
12
18
  getState,
13
- options: { enableRowEditing, muiTableBodyCellEditTextFieldProps },
19
+ options: {
20
+ enableEditing,
21
+ muiTableBodyCellEditTextFieldProps,
22
+ setCurrentEditingRow,
23
+ },
14
24
  } = tableInstance;
15
25
 
26
+ const [value, setValue] = useState(cell.value);
27
+
16
28
  const { column, row } = cell;
17
29
 
18
30
  const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
31
+ setValue(event.target.value);
32
+ column.onCellEditChange?.({ event, cell, tableInstance });
33
+ };
34
+
35
+ const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
19
36
  if (getState().currentEditingRow) {
20
- row.values[column.id] = event.target.value;
21
- // setCurrentEditingRow({
22
- // ...getState().currentEditingRow,
23
- // });
37
+ row.values[column.id] = value;
38
+ setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
24
39
  }
25
- column.onCellEditChange?.({ event, cell, tableInstance });
40
+ column.onCellEditBlur?.({ event, cell, tableInstance });
26
41
  };
27
42
 
28
43
  const mTableBodyCellEditTextFieldProps =
@@ -40,17 +55,18 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
40
55
  ...mcTableBodyCellEditTextFieldProps,
41
56
  };
42
57
 
43
- if (enableRowEditing && column.enableEditing !== false && column.Edit) {
58
+ if (enableEditing && column.enableEditing !== false && column.Edit) {
44
59
  return <>{column.Edit?.({ cell, tableInstance })}</>;
45
60
  }
46
61
 
47
62
  return (
48
63
  <TextField
49
64
  margin="dense"
65
+ onBlur={handleBlur}
50
66
  onChange={handleChange}
51
67
  onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
52
68
  placeholder={column.header}
53
- value={cell.value}
69
+ value={value}
54
70
  variant="standard"
55
71
  {...textFieldProps}
56
72
  />
@@ -33,6 +33,7 @@ export interface MRT_Localization {
33
33
  pinToLeft: string;
34
34
  pinToRight: string;
35
35
  rowActions: string;
36
+ rowNumber: string;
36
37
  rowNumbers: string;
37
38
  save: string;
38
39
  search: string;
@@ -89,6 +90,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
89
90
  pinToLeft: 'Pin to left',
90
91
  pinToRight: 'Pin to right',
91
92
  rowActions: 'Row Actions',
93
+ rowNumber: '#',
92
94
  rowNumbers: 'Row Numbers',
93
95
  save: 'Save',
94
96
  search: 'Search',
@@ -25,7 +25,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
25
25
  getState,
26
26
  options: {
27
27
  icons: { EditIcon },
28
- enableRowEditing,
28
+ enableEditing,
29
29
  localization,
30
30
  renderRowActionMenuItems,
31
31
  },
@@ -42,7 +42,7 @@ export const MRT_RowActionMenu: FC<Props> = ({
42
42
  dense: isDensePadding,
43
43
  }}
44
44
  >
45
- {enableRowEditing && (
45
+ {enableEditing && (
46
46
  <MenuItem onClick={handleEdit} sx={commonMenuItemStyles}>
47
47
  <Box sx={commonListItemStyles}>
48
48
  <ListItemIcon>
@@ -92,7 +92,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
92
92
  const displayColumns = useMemo(
93
93
  () =>
94
94
  [
95
- (props.enableRowActions || props.enableRowEditing) &&
95
+ (props.enableRowActions || props.enableEditing) &&
96
96
  createDisplayColumn(table, {
97
97
  Cell: ({ cell }) => (
98
98
  <MRT_ToggleRowActionMenuButton
@@ -142,7 +142,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
142
142
  props.enableRowNumbers &&
143
143
  createDisplayColumn(table, {
144
144
  Cell: ({ cell }) => cell.row.index + 1,
145
- Header: () => '#',
145
+ Header: () => props.localization?.rowNumber,
146
146
  header: props.localization?.rowNumbers,
147
147
  id: 'mrt-row-numbers',
148
148
  maxWidth: 40,
@@ -151,10 +151,12 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
151
151
  }),
152
152
  ].filter(Boolean),
153
153
  [
154
+ table,
154
155
  props.enableExpandAll,
155
156
  props.enableExpanded,
156
157
  props.enableRowActions,
157
- props.enableRowEditing,
158
+ props.enableGrouping,
159
+ props.enableEditing,
158
160
  props.enableRowNumbers,
159
161
  props.enableRowSelection,
160
162
  props.enableSelectAll,
@@ -195,16 +197,16 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
195
197
  //@ts-ignore
196
198
  const tableInstance: MRT_TableInstance<{}> = useTable(table, {
197
199
  ...props,
198
- //@ts-ignore
199
- filterTypes: defaultFilterFNs,
200
- debugAll: false,
201
- globalFilterType: currentGlobalFilterType,
202
200
  columnFilterRowsFn: columnFilterRowsFn,
203
201
  columns,
204
202
  data,
203
+ debugAll: false,
205
204
  expandRowsFn: expandRowsFn,
205
+ //@ts-ignore
206
+ filterTypes: defaultFilterFNs,
206
207
  getSubRows: props.getSubRows ?? ((originalRow: D) => originalRow.subRows),
207
208
  globalFilterRowsFn: globalFilterRowsFn,
209
+ globalFilterType: currentGlobalFilterType,
208
210
  groupRowsFn: groupRowsFn,
209
211
  idPrefix,
210
212
  onPaginationChange: (updater: any) =>