material-react-table 0.7.0 → 0.7.3

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.
@@ -1,7 +1,7 @@
1
1
  import { FC } from 'react';
2
- import type { MRT_ColumnInstance, MRT_TableInstance } from '..';
2
+ import type { MRT_Column, MRT_TableInstance } from '..';
3
3
  interface Props {
4
- column: MRT_ColumnInstance;
4
+ column: MRT_Column;
5
5
  isSubMenu?: boolean;
6
6
  tableInstance: MRT_TableInstance;
7
7
  }
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ColumnDef, Table } from '@tanstack/react-table';
2
- import { MRT_ColumnInterface, MRT_FilterType } from '.';
3
- export declare const getAllLeafColumnDefs: (columns: MRT_ColumnInterface[]) => MRT_ColumnInterface[];
4
- export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnInterface<D>, currentFilterTypes: {
2
+ import { MRT_ColumnDef, MRT_FilterType } from '.';
3
+ export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
4
+ export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
5
5
  [key: string]: MRT_FilterType;
6
6
  }) => ColumnDef<D>;
7
- export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnInterface<D>, currentFilterTypes: {
7
+ export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
8
8
  [key: string]: MRT_FilterType;
9
9
  }) => ColumnDef<D>;
10
- export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnInterface<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "filterType" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortType" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationType" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledFilterTypes" | "filter" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
10
+ export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "filterFn" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterTypes" | "filter" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
11
11
  header?: string | undefined;
12
12
  }) => ColumnDef<D>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.0",
2
+ "version": "0.7.3",
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.",
@@ -97,7 +97,7 @@
97
97
  "react": ">=16.8"
98
98
  },
99
99
  "dependencies": {
100
- "@tanstack/react-table": "^8.0.0-alpha.43",
100
+ "@tanstack/react-table": "^8.0.0-alpha.45",
101
101
  "match-sorter": "^6.3.1"
102
102
  }
103
103
  }
@@ -53,7 +53,7 @@ export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
53
53
  'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
54
54
  >
55
55
  > & {
56
- columns: MRT_ColumnInterface<D>[];
56
+ columns: MRT_ColumnDef<D>[];
57
57
  data: D[];
58
58
  initialState?: Partial<MRT_TableState<D>>;
59
59
  state?: Partial<MRT_TableState<D>>;
@@ -85,8 +85,8 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
85
85
  | 'getState'
86
86
  | 'options'
87
87
  > & {
88
- getAllColumns: () => MRT_ColumnInstance<D>[];
89
- getAllLeafColumns: () => MRT_ColumnInstance<D>[];
88
+ getAllColumns: () => MRT_Column<D>[];
89
+ getAllLeafColumns: () => MRT_Column<D>[];
90
90
  getExpandedRowModel: () => MRT_RowModel<D>;
91
91
  getPaginationRowModel: () => MRT_RowModel<D>;
92
92
  getPrePaginationRowModel: () => MRT_RowModel<D>;
@@ -99,6 +99,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
99
99
  filterTypes: { [key in MRT_FILTER_TYPE]: any };
100
100
  localization: MRT_Localization;
101
101
  };
102
+ setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell<D> | null>>;
102
103
  setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row<D> | null>>;
103
104
  setCurrentFilterTypes: Dispatch<
104
105
  SetStateAction<{
@@ -116,6 +117,7 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
116
117
  TableState,
117
118
  'pagination'
118
119
  > & {
120
+ currentEditingCell: MRT_Cell<D> | null;
119
121
  currentEditingRow: MRT_Row<D> | null;
120
122
  currentFilterTypes: Record<string, string | Function>;
121
123
  currentGlobalFilterType: Record<string, string | Function>;
@@ -126,7 +128,7 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
126
128
  pagination: Partial<PaginationState>;
127
129
  };
128
130
 
129
- export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
131
+ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
130
132
  ColumnDef<D>,
131
133
  'header' | 'footer' | 'columns'
132
134
  > & {
@@ -170,11 +172,11 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
170
172
  tableInstance: MRT_TableInstance<D>;
171
173
  }) => ReactNode;
172
174
  id: keyof D | string;
173
- columns?: MRT_ColumnInterface<D>[];
175
+ columns?: MRT_ColumnDef<D>[];
174
176
  enableClickToCopy?: boolean;
175
177
  enableColumnActions?: boolean;
176
178
  enableEditing?: boolean;
177
- enabledFilterTypes?: (MRT_FILTER_TYPE | string)[];
179
+ enabledColumnFilterTypes?: (MRT_FILTER_TYPE | string)[];
178
180
  filter?: MRT_FilterType | string | FilterType<D>;
179
181
  filterSelectOptions?: (string | { text: string; value: string })[];
180
182
  footer?: string;
@@ -213,7 +215,7 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
213
215
  column,
214
216
  }: {
215
217
  tableInstance: MRT_TableInstance;
216
- column: MRT_ColumnInstance<D>;
218
+ column: MRT_Column<D>;
217
219
  }) => TableCellProps);
218
220
  muiTableHeadCellColumnActionsButtonProps?:
219
221
  | IconButtonProps
@@ -222,7 +224,7 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
222
224
  column,
223
225
  }: {
224
226
  tableInstance: MRT_TableInstance;
225
- column: MRT_ColumnInstance<D>;
227
+ column: MRT_Column<D>;
226
228
  }) => IconButtonProps);
227
229
  muiTableHeadCellFilterTextFieldProps?:
228
230
  | TextFieldProps
@@ -231,7 +233,7 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
231
233
  column,
232
234
  }: {
233
235
  tableInstance: MRT_TableInstance;
234
- column: MRT_ColumnInstance<D>;
236
+ column: MRT_Column<D>;
235
237
  }) => TextFieldProps);
236
238
  muiTableHeadCellProps?:
237
239
  | TableCellProps
@@ -240,7 +242,7 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
240
242
  column,
241
243
  }: {
242
244
  tableInstance: MRT_TableInstance;
243
- column: MRT_ColumnInstance<D>;
245
+ column: MRT_Column<D>;
244
246
  }) => TableCellProps);
245
247
  onCellEditBlur?: ({
246
248
  cell,
@@ -261,27 +263,29 @@ export type MRT_ColumnInterface<D extends Record<string, any> = {}> = Omit<
261
263
  tableInstance: MRT_TableInstance<D>;
262
264
  }) => void;
263
265
  onColumnFilterValueChange?: ({
266
+ column,
264
267
  event,
265
268
  filterValue,
266
269
  }: {
270
+ column: MRT_Column<D>;
267
271
  event: ChangeEvent<HTMLInputElement>;
268
272
  filterValue: any;
269
273
  }) => void;
270
274
  };
271
275
 
272
- export type MRT_ColumnInstance<D extends Record<string, any> = {}> = Omit<
276
+ export type MRT_Column<D extends Record<string, any> = {}> = Omit<
273
277
  Column<D>,
274
278
  'header' | 'footer' | 'columns'
275
279
  > &
276
- MRT_ColumnInterface<D> & {
277
- columns?: MRT_ColumnInstance<D>[];
280
+ MRT_ColumnDef<D> & {
281
+ columns?: MRT_Column<D>[];
278
282
  };
279
283
 
280
284
  export type MRT_Header<D extends Record<string, any> = {}> = Omit<
281
285
  Header<D>,
282
286
  'column'
283
287
  > & {
284
- column: MRT_ColumnInstance<D>;
288
+ column: MRT_Column<D>;
285
289
  };
286
290
 
287
291
  export type MRT_HeaderGroup<D extends Record<string, any> = {}> = Omit<
@@ -314,7 +318,7 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
314
318
  Cell<D>,
315
319
  'column' | 'row'
316
320
  > & {
317
- column: MRT_ColumnInstance<D>;
321
+ column: MRT_Column<D>;
318
322
  row: MRT_Row<D>;
319
323
  };
320
324
 
@@ -322,6 +326,7 @@ export type MRT_FilterType = MRT_FILTER_TYPE | Function;
322
326
 
323
327
  export type MaterialReactTableProps<D extends Record<string, any> = {}> =
324
328
  MRT_TableOptions<D> & {
329
+ editingMode?: 'table' | 'row' | 'cell';
325
330
  enableClickToCopy?: boolean;
326
331
  enableColumnActions?: boolean;
327
332
  enableDensePaddingToggle?: boolean;
@@ -333,13 +338,13 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
333
338
  enableRowNumbers?: boolean;
334
339
  enableSelectAll?: boolean;
335
340
  enableStickyHeader?: boolean;
341
+ enableTableFooter?: boolean;
342
+ enableTableHead?: boolean;
343
+ enableToolbarBottom?: boolean;
344
+ enableToolbarInternalActions?: boolean;
345
+ enableToolbarTop?: boolean;
336
346
  enabledGlobalFilterTypes?: (MRT_FILTER_TYPE | string)[];
337
347
  filterTypes?: { [key in MRT_FILTER_TYPE]: any };
338
- hideTableFooter?: boolean;
339
- hideTableHead?: boolean;
340
- hideToolbarBottom?: boolean;
341
- hideToolbarInternalActions?: boolean;
342
- hideToolbarTop?: boolean;
343
348
  icons?: Partial<MRT_Icons>;
344
349
  idPrefix?: string;
345
350
  isLoading?: boolean;
@@ -445,7 +450,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
445
450
  column,
446
451
  }: {
447
452
  tableInstance: MRT_TableInstance;
448
- column: MRT_ColumnInstance<D>;
453
+ column: MRT_Column<D>;
449
454
  }) => TableCellProps);
450
455
  muiTableFooterProps?:
451
456
  | TableFooterProps
@@ -470,7 +475,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
470
475
  column,
471
476
  }: {
472
477
  tableInstance: MRT_TableInstance;
473
- column: MRT_ColumnInstance<D>;
478
+ column: MRT_Column<D>;
474
479
  }) => IconButtonProps);
475
480
  muiTableHeadCellFilterTextFieldProps?:
476
481
  | TextFieldProps
@@ -479,7 +484,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
479
484
  column,
480
485
  }: {
481
486
  tableInstance: MRT_TableInstance;
482
- column: MRT_ColumnInstance<D>;
487
+ column: MRT_Column<D>;
483
488
  }) => TextFieldProps);
484
489
  muiTableHeadCellProps?:
485
490
  | TableCellProps
@@ -488,7 +493,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
488
493
  column,
489
494
  }: {
490
495
  tableInstance: MRT_TableInstance;
491
- column: MRT_ColumnInstance<D>;
496
+ column: MRT_Column<D>;
492
497
  }) => TableCellProps);
493
498
  muiTableHeadProps?:
494
499
  | TableHeadProps
@@ -557,6 +562,33 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
557
562
  tableInstance: MRT_TableInstance<D>;
558
563
  event: MouseEvent<HTMLTableCellElement>;
559
564
  }) => void;
565
+ onCellEditBlur?: ({
566
+ cell,
567
+ event,
568
+ tableInstance,
569
+ }: {
570
+ event: FocusEvent<HTMLInputElement>;
571
+ cell: MRT_Cell<D>;
572
+ tableInstance: MRT_TableInstance<D>;
573
+ }) => void;
574
+ onCellEditChange?: ({
575
+ cell,
576
+ event,
577
+ tableInstance,
578
+ }: {
579
+ event: ChangeEvent<HTMLInputElement>;
580
+ cell: MRT_Cell<D>;
581
+ tableInstance: MRT_TableInstance<D>;
582
+ }) => void;
583
+ onColumnFilterValueChange?: ({
584
+ column,
585
+ event,
586
+ filterValue,
587
+ }: {
588
+ column: MRT_Column<D>;
589
+ event: ChangeEvent<HTMLInputElement>;
590
+ filterValue: any;
591
+ }) => void;
560
592
  onDetailPanelClick?: ({
561
593
  event,
562
594
  row,
@@ -622,7 +654,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
622
654
  columnVisibility,
623
655
  tableInstance,
624
656
  }: {
625
- column: MRT_ColumnInstance<D>;
657
+ column: MRT_Column<D>;
626
658
  columnVisibility: VisibilityState;
627
659
  tableInstance: MRT_TableInstance<D>;
628
660
  }) => void;
@@ -723,8 +755,11 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
723
755
 
724
756
  export default <D extends Record<string, any> = {}>({
725
757
  autoResetExpanded = false,
758
+ columnResizeMode = 'onEnd',
759
+ editingMode = 'row',
726
760
  enableColumnActions = true,
727
761
  enableColumnFilters = true,
762
+ enableColumnResizing = false,
728
763
  enableDensePaddingToggle = true,
729
764
  enableExpandAll = true,
730
765
  enableFilters = true,
@@ -736,6 +771,11 @@ export default <D extends Record<string, any> = {}>({
736
771
  enableSelectAll = true,
737
772
  enableSorting = true,
738
773
  enableStickyHeader = true,
774
+ enableTableFooter = true,
775
+ enableTableHead = true,
776
+ enableToolbarBottom = true,
777
+ enableToolbarInternalActions = true,
778
+ enableToolbarTop = true,
739
779
  icons,
740
780
  localization,
741
781
  positionActionsColumn = 'first',
@@ -746,7 +786,10 @@ export default <D extends Record<string, any> = {}>({
746
786
  }: MaterialReactTableProps<D>) => (
747
787
  <MRT_TableRoot
748
788
  autoResetExpanded={autoResetExpanded}
789
+ columnResizeMode={columnResizeMode}
790
+ editingMode={editingMode}
749
791
  enableColumnActions={enableColumnActions}
792
+ enableColumnResizing={enableColumnResizing}
750
793
  enableColumnFilters={enableColumnFilters}
751
794
  enableDensePaddingToggle={enableDensePaddingToggle}
752
795
  enableExpandAll={enableExpandAll}
@@ -759,6 +802,11 @@ export default <D extends Record<string, any> = {}>({
759
802
  enableSelectAll={enableSelectAll}
760
803
  enableSorting={enableSorting}
761
804
  enableStickyHeader={enableStickyHeader}
805
+ enableTableFooter={enableTableFooter}
806
+ enableTableHead={enableTableHead}
807
+ enableToolbarBottom={enableToolbarBottom}
808
+ enableToolbarInternalActions={enableToolbarInternalActions}
809
+ enableToolbarTop={enableToolbarTop}
762
810
  icons={{ ...MRT_Default_Icons, ...icons }}
763
811
  localization={{ ...MRT_DefaultLocalization_EN, ...localization }}
764
812
  positionActionsColumn={positionActionsColumn}
@@ -14,17 +14,20 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
14
14
  getIsSomeColumnsPinned,
15
15
  getState,
16
16
  options: {
17
+ editingMode,
17
18
  enableClickToCopy,
18
- enablePinning,
19
19
  enableEditing,
20
+ enablePinning,
21
+ idPrefix,
20
22
  isLoading,
21
23
  muiTableBodyCellProps,
22
24
  muiTableBodyCellSkeletonProps,
23
25
  onCellClick,
24
26
  },
27
+ setCurrentEditingCell,
25
28
  } = tableInstance;
26
29
 
27
- const { currentEditingRow, isDensePadding } = getState();
30
+ const { currentEditingCell, currentEditingRow, isDensePadding } = getState();
28
31
 
29
32
  const { column, row } = cell;
30
33
 
@@ -53,13 +56,45 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
53
56
  [column.columnDefType, column.getWidth()],
54
57
  );
55
58
 
59
+ const isEditable =
60
+ (enableEditing || column.enableEditing) && column.enableEditing !== false;
61
+
62
+ const isEditing =
63
+ isEditable &&
64
+ (editingMode === 'table' ||
65
+ currentEditingRow?.id === row.id ||
66
+ currentEditingCell?.id === cell.id);
67
+
68
+ const handleDoubleClick = (_event: MouseEvent<HTMLTableCellElement>) => {
69
+ if (
70
+ (enableEditing || column.enableEditing) &&
71
+ column.enableEditing !== false &&
72
+ editingMode === 'cell'
73
+ ) {
74
+ setCurrentEditingCell(cell);
75
+ setTimeout(() => {
76
+ const textField = document.getElementById(
77
+ `mrt-${idPrefix}-edit-cell-text-field-${cell.id}`,
78
+ ) as HTMLInputElement;
79
+ if (textField) {
80
+ textField.focus();
81
+ textField.select();
82
+ }
83
+ }, 200);
84
+ }
85
+ };
86
+
56
87
  return (
57
88
  <TableCell
58
89
  onClick={(event: MouseEvent<HTMLTableCellElement>) =>
59
90
  onCellClick?.({ event, cell, tableInstance })
60
91
  }
92
+ onDoubleClick={handleDoubleClick}
61
93
  {...tableCellProps}
62
94
  sx={{
95
+ cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
96
+ maxWidth: `min(${column.getWidth()}px, fit-content)`,
97
+ minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
63
98
  p: isDensePadding
64
99
  ? column.columnDefType === 'display'
65
100
  ? '0 0.5rem'
@@ -76,6 +111,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
76
111
  isDensePadding || (enablePinning && getIsSomeColumnsPinned())
77
112
  ? 'nowrap'
78
113
  : 'normal',
114
+ width: column.getWidth(),
79
115
  //@ts-ignore
80
116
  ...tableCellProps?.sx,
81
117
  }}
@@ -94,9 +130,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
94
130
  column.id !==
95
131
  row.groupingColumnId) ? null : cell.getIsAggregated() ? (
96
132
  cell.renderAggregatedCell()
97
- ) : enableEditing &&
98
- column.enableEditing !== false &&
99
- currentEditingRow?.id === row.id ? (
133
+ ) : isEditing ? (
100
134
  <MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
101
135
  ) : (enableClickToCopy || column.enableClickToCopy) &&
102
136
  column.enableClickToCopy !== false ? (
@@ -56,6 +56,7 @@ export const MRT_CopyButton: FC<Props> = ({
56
56
  backgroundColor: 'transparent',
57
57
  border: 'none',
58
58
  color: 'inherit',
59
+ cursor: 'copy',
59
60
  fontFamily: 'inherit',
60
61
  fontSize: 'inherit',
61
62
  letterSpacing: 'inherit',
@@ -46,8 +46,11 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
46
46
  0.05,
47
47
  )},${alpha(theme.palette.common.white, 0.05)})`,
48
48
  fontWeight: 'bold',
49
+ maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
50
+ minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
49
51
  p: isDensePadding ? '0.5rem' : '1rem',
50
52
  transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
53
+ width: column.getWidth(),
51
54
  verticalAlign: 'text-top',
52
55
  //@ts-ignore
53
56
  ...tableCellProps?.sx,
@@ -97,10 +97,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
97
97
  theme.palette.common.white,
98
98
  0.05,
99
99
  )},${alpha(theme.palette.common.white, 0.05)})`,
100
- boxShadow: `3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
101
100
  fontWeight: 'bold',
102
101
  height: '100%',
103
- minWidth: `max(${header.getWidth()}, 100px)`,
102
+ maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
103
+ minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
104
104
  p: isDensePadding
105
105
  ? column.columnDefType === 'display'
106
106
  ? '0 0.5rem'
@@ -115,9 +115,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
115
115
  ? '0.75rem'
116
116
  : '1.25rem',
117
117
  pb: column.columnDefType === 'display' ? 0 : undefined,
118
+ overflow: 'visible',
118
119
  transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
119
120
  verticalAlign: 'text-top',
120
121
  width: header.getWidth(),
122
+ zIndex: column.getIsResizing() ? 2 : 1,
121
123
  //@ts-ignore
122
124
  ...tableCellProps?.sx,
123
125
  })}
@@ -144,11 +146,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
144
146
  : undefined,
145
147
  display: 'flex',
146
148
  flexWrap: 'nowrap',
147
- whiteSpace: column.header.length < 15 ? 'nowrap' : 'normal',
149
+ whiteSpace: column.header.length < 24 ? 'nowrap' : 'normal',
148
150
  }}
149
151
  >
150
152
  {headerElement}
151
- {column.columnDefType !== 'group' && column.getCanSort() && (
153
+ {column.columnDefType === 'data' && column.getCanSort() && (
152
154
  <Tooltip arrow placement="top" title={sortTooltip}>
153
155
  <TableSortLabel
154
156
  aria-label={sortTooltip}
@@ -161,7 +163,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
161
163
  />
162
164
  </Tooltip>
163
165
  )}
164
- {column.columnDefType !== 'group' &&
166
+ {column.columnDefType === 'data' &&
165
167
  enableColumnFilters &&
166
168
  !!column.getCanColumnFilter() && (
167
169
  <Tooltip arrow placement="top" title={filterTooltip}>
@@ -192,59 +194,56 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
192
194
  </Tooltip>
193
195
  )}
194
196
  </Box>
195
- <Box
196
- sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}
197
- >
198
- {(enableColumnActions || column.enableColumnActions) &&
199
- column.enableColumnActions !== false &&
200
- column.columnDefType !== 'group' && (
201
- <MRT_ToggleColumnActionMenuButton
202
- header={header}
203
- tableInstance={tableInstance}
204
- />
205
- )}
206
- {enableColumnResizing && column.columnDefType !== 'group' && (
207
- <Divider
208
- flexItem
209
- orientation="vertical"
210
- onDoubleClick={() => header.resetSize()}
211
- sx={(theme: Theme) => ({
212
- borderRightWidth: '2px',
213
- borderRadius: '2px',
214
- maxHeight: '2rem',
215
- cursor: 'col-resize',
216
- userSelect: 'none',
217
- touchAction: 'none',
218
- '&:active': {
219
- backgroundColor: theme.palette.secondary.dark,
220
- opacity: 1,
221
- },
222
- })}
223
- {...(header.getResizerProps((props: ColumnResizerProps) => ({
224
- ...props,
225
- style: {
226
- transform: column.getIsResizing()
227
- ? `translateX(${
228
- getState().columnSizingInfo.deltaOffset
229
- }px)`
230
- : '',
231
- },
232
- })) as any)}
197
+ {(enableColumnActions || column.enableColumnActions) &&
198
+ column.enableColumnActions !== false &&
199
+ column.columnDefType !== 'group' && (
200
+ <MRT_ToggleColumnActionMenuButton
201
+ header={header}
202
+ tableInstance={tableInstance}
233
203
  />
234
204
  )}
235
- </Box>
205
+ {column.getCanResize() && (
206
+ <Divider
207
+ flexItem
208
+ orientation="vertical"
209
+ onDoubleClick={() => header.resetSize()}
210
+ sx={(theme: Theme) => ({
211
+ borderRadius: '2px',
212
+ borderRightWidth: '2px',
213
+ cursor: 'col-resize',
214
+ height:
215
+ showFilters && column.columnDefType === 'data'
216
+ ? '4rem'
217
+ : '2rem',
218
+ opacity: 0.8,
219
+ position: 'absolute',
220
+ right: '1px',
221
+ touchAction: 'none',
222
+ transition: 'all 0.2s ease-in-out',
223
+ userSelect: 'none',
224
+ zIndex: 2000,
225
+ '&:active': {
226
+ backgroundColor: theme.palette.info.main,
227
+ opacity: 1,
228
+ },
229
+ })}
230
+ {...(header.getResizerProps((props: ColumnResizerProps) => ({
231
+ ...props,
232
+ style: {
233
+ transform: column.getIsResizing()
234
+ ? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
235
+ : '',
236
+ },
237
+ })) as any)}
238
+ />
239
+ )}
236
240
  </Box>
237
241
  )}
238
- {column.columnDefType === 'data' &&
239
- enableColumnFilters &&
240
- column.getCanColumnFilter() && (
241
- <Collapse in={showFilters}>
242
- <MRT_FilterTextField
243
- header={header}
244
- tableInstance={tableInstance}
245
- />
246
- </Collapse>
247
- )}
242
+ {column.columnDefType === 'data' && column.getCanColumnFilter() && (
243
+ <Collapse in={showFilters}>
244
+ <MRT_FilterTextField header={header} tableInstance={tableInstance} />
245
+ </Collapse>
246
+ )}
248
247
  </TableCell>
249
248
  );
250
249
  };
@@ -1,5 +1,5 @@
1
- import React, { FC } from 'react';
2
- import { TableRow } from '@mui/material';
1
+ import React, { CSSProperties, FC } from 'react';
2
+ import { alpha, TableRow } from '@mui/material';
3
3
  import { MRT_TableHeadCell } from './MRT_TableHeadCell';
4
4
  import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
5
5
 
@@ -24,7 +24,16 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
24
24
  };
25
25
 
26
26
  return (
27
- <TableRow {...tableRowProps}>
27
+ <TableRow
28
+ {...tableRowProps}
29
+ sx={(theme) =>
30
+ ({
31
+ boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
32
+ //@ts-ignore
33
+ ...tableRowProps?.sx,
34
+ } as CSSProperties)
35
+ }
36
+ >
28
37
  {headerGroup.headers.map((header: MRT_Header, index) => (
29
38
  <MRT_TableHeadCell
30
39
  header={header}
package/src/icons.ts CHANGED
@@ -19,6 +19,7 @@ import FullscreenIcon from '@mui/icons-material/Fullscreen';
19
19
  import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
20
20
  import MoreVertIcon from '@mui/icons-material/MoreVert';
21
21
  import PushPinIcon from '@mui/icons-material/PushPin';
22
+ import RestartAltIcon from '@mui/icons-material/RestartAlt';
22
23
  import SaveIcon from '@mui/icons-material/Save';
23
24
  import SearchIcon from '@mui/icons-material/Search';
24
25
  import SearchOffIcon from '@mui/icons-material/SearchOff';
@@ -48,6 +49,7 @@ export interface MRT_Icons {
48
49
  MoreHorizIcon: any;
49
50
  MoreVertIcon: any;
50
51
  PushPinIcon: any;
52
+ RestartAltIcon: any;
51
53
  SaveIcon: any;
52
54
  SearchIcon: any;
53
55
  SearchOffIcon: any;
@@ -78,6 +80,7 @@ export const MRT_Default_Icons: MRT_Icons = {
78
80
  MoreHorizIcon,
79
81
  MoreVertIcon,
80
82
  PushPinIcon,
83
+ RestartAltIcon,
81
84
  SaveIcon,
82
85
  SearchIcon,
83
86
  SearchOffIcon,