material-react-table 0.37.0 → 0.38.0

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
2
- import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, ToolbarProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, AlertProps } from '@mui/material';
2
+ import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, 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';
5
5
  import * as _tanstack_table_core from '@tanstack/table-core';
@@ -304,6 +304,12 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
304
304
  footer: MRT_Header<TData>;
305
305
  table: MRT_TableInstance<TData>;
306
306
  }) => ReactNode);
307
+ GroupedCell?: ({ cell, column, row, table, }: {
308
+ cell: MRT_Cell<TData>;
309
+ column: MRT_Column<TData>;
310
+ row: MRT_Row<TData>;
311
+ table: MRT_TableInstance<TData>;
312
+ }) => ReactNode;
307
313
  Header?: ReactNode | (({ column, header, table, }: {
308
314
  column: MRT_Column<TData>;
309
315
  header: MRT_Header<TData>;
@@ -483,6 +489,9 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
483
489
  icons?: Partial<MRT_Icons>;
484
490
  initialState?: Partial<MRT_TableState<TData>>;
485
491
  localization?: Partial<MRT_Localization>;
492
+ muiBottomToolbarProps?: ToolbarProps | (({ table }: {
493
+ table: MRT_TableInstance<TData>;
494
+ }) => ToolbarProps);
486
495
  muiExpandAllButtonProps?: IconButtonProps | (({ table }: {
487
496
  table: MRT_TableInstance<TData>;
488
497
  }) => IconButtonProps);
@@ -537,9 +546,6 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
537
546
  table: MRT_TableInstance<TData>;
538
547
  row: MRT_Row<TData>;
539
548
  }) => TableRowProps);
540
- muiTableBottomToolbarProps?: ToolbarProps | (({ table }: {
541
- table: MRT_TableInstance<TData>;
542
- }) => ToolbarProps);
543
549
  muiTableContainerProps?: TableContainerProps | (({ table, }: {
544
550
  table: MRT_TableInstance<TData>;
545
551
  }) => TableContainerProps);
@@ -591,10 +597,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
591
597
  muiTableProps?: TableProps | (({ table }: {
592
598
  table: MRT_TableInstance<TData>;
593
599
  }) => TableProps);
594
- muiTableToolbarAlertBannerProps?: AlertProps | (({ table }: {
600
+ muiToolbarAlertBannerChipProps?: ChipProps | (({ table }: {
601
+ table: MRT_TableInstance<TData>;
602
+ }) => ChipProps);
603
+ muiToolbarAlertBannerProps?: AlertProps | (({ table }: {
595
604
  table: MRT_TableInstance<TData>;
596
605
  }) => AlertProps);
597
- muiTableTopToolbarProps?: ToolbarProps | (({ table }: {
606
+ muiTopToolbarProps?: ToolbarProps | (({ table }: {
598
607
  table: MRT_TableInstance<TData>;
599
608
  }) => ToolbarProps);
600
609
  onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
@@ -607,13 +616,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
607
616
  onDensityChange?: OnChangeFn<boolean>;
608
617
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
609
618
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
619
+ onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
610
620
  onEditingRowSave?: ({ exitEditingMode, row, table, values, }: {
611
621
  exitEditingMode: () => void;
612
622
  row: MRT_Row<TData>;
613
623
  table: MRT_TableInstance<TData>;
614
624
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
615
625
  }) => Promise<void> | void;
616
- onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
617
626
  onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
618
627
  onFilterFnsChange?: OnChangeFn<{
619
628
  [key: string]: MRT_FilterOption;
@@ -650,7 +659,8 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
650
659
  row: MRT_Row<TData>;
651
660
  table: MRT_TableInstance<TData>;
652
661
  }) => ReactNode[];
653
- renderRowActions?: ({ row, table, }: {
662
+ renderRowActions?: ({ cell, row, table, }: {
663
+ cell: MRT_Cell<TData>;
654
664
  row: MRT_Row<TData>;
655
665
  table: MRT_TableInstance<TData>;
656
666
  }) => ReactNode;
@@ -670,6 +680,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
670
680
  };
671
681
  declare const _default: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, editingMode, enableBottomToolbar, enableColumnActions, enableColumnFilterChangeMode, enableColumnFilters, enableColumnOrdering, enableColumnResizing, enableDensityToggle, enableExpandAll, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableGlobalFilterChangeMode, enableGlobalFilterRankedResults, enableGrouping, enableHiding, enableMultiRowSelection, enableMultiSort, enablePagination, enablePinning, enableRowSelection, enableSelectAll, enableSorting, enableStickyHeader, enableTableFooter, enableTableHead, enableToolbarInternalActions, enableTopToolbar, filterFns, icons, localization, positionActionsColumn, positionExpandColumn, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, rowNumberMode, selectAllMode, sortingFns, ...rest }: MaterialReactTableProps<TData>) => JSX.Element;
672
682
 
683
+ interface Props$6<TData extends Record<string, any> = {}> {
684
+ cell: MRT_Cell<TData>;
685
+ children: ReactNode;
686
+ table: MRT_TableInstance<TData>;
687
+ }
688
+ declare const MRT_CopyButton: <TData extends Record<string, any> = {}>({ cell, children, table, }: Props$6<TData>) => JSX.Element;
689
+
673
690
  interface Props$5<TData extends Record<string, any> = {}> extends IconButtonProps {
674
691
  table: MRT_TableInstance<TData>;
675
692
  }
@@ -700,4 +717,4 @@ interface Props<TData extends Record<string, any> = {}> extends IconButtonProps
700
717
  }
701
718
  declare const MRT_ToggleGlobalFilterButton: <TData extends Record<string, any> = {}>({ table, ...rest }: Props<TData>) => JSX.Element;
702
719
 
703
- export { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MaterialReactTableProps, _default as default };
720
+ export { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MaterialReactTableProps, _default as default };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.37.0",
2
+ "version": "0.38.0",
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.0",
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.21.0",
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.77.3",
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",
@@ -9,6 +9,7 @@ import type {
9
9
  AlertProps,
10
10
  ButtonProps,
11
11
  CheckboxProps,
12
+ ChipProps,
12
13
  IconButtonProps,
13
14
  LinearProgressProps,
14
15
  PaperProps,
@@ -207,6 +208,17 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
207
208
  footer: MRT_Header<TData>;
208
209
  table: MRT_TableInstance<TData>;
209
210
  }) => ReactNode);
211
+ GroupedCell?: ({
212
+ cell,
213
+ column,
214
+ row,
215
+ table,
216
+ }: {
217
+ cell: MRT_Cell<TData>;
218
+ column: MRT_Column<TData>;
219
+ row: MRT_Row<TData>;
220
+ table: MRT_TableInstance<TData>;
221
+ }) => ReactNode;
210
222
  Header?:
211
223
  | ReactNode
212
224
  | (({
@@ -486,6 +498,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
486
498
  icons?: Partial<MRT_Icons>;
487
499
  initialState?: Partial<MRT_TableState<TData>>;
488
500
  localization?: Partial<MRT_Localization>;
501
+ muiBottomToolbarProps?:
502
+ | ToolbarProps
503
+ | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
489
504
  muiExpandAllButtonProps?:
490
505
  | IconButtonProps
491
506
  | (({ table }: { table: MRT_TableInstance<TData> }) => IconButtonProps);
@@ -590,9 +605,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
590
605
  table: MRT_TableInstance<TData>;
591
606
  row: MRT_Row<TData>;
592
607
  }) => TableRowProps);
593
- muiTableBottomToolbarProps?:
594
- | ToolbarProps
595
- | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
596
608
  muiTableContainerProps?:
597
609
  | TableContainerProps
598
610
  | (({
@@ -693,10 +705,13 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
693
705
  muiTableProps?:
694
706
  | TableProps
695
707
  | (({ table }: { table: MRT_TableInstance<TData> }) => TableProps);
696
- muiTableToolbarAlertBannerProps?:
708
+ muiToolbarAlertBannerChipProps?:
709
+ | ChipProps
710
+ | (({ table }: { table: MRT_TableInstance<TData> }) => ChipProps);
711
+ muiToolbarAlertBannerProps?:
697
712
  | AlertProps
698
713
  | (({ table }: { table: MRT_TableInstance<TData> }) => AlertProps);
699
- muiTableTopToolbarProps?:
714
+ muiTopToolbarProps?:
700
715
  | ToolbarProps
701
716
  | (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
702
717
  onColumnDrop?: ({
@@ -711,6 +726,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
711
726
  onDensityChange?: OnChangeFn<boolean>;
712
727
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
713
728
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
729
+ onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
714
730
  onEditingRowSave?: ({
715
731
  exitEditingMode,
716
732
  row,
@@ -722,7 +738,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
722
738
  table: MRT_TableInstance<TData>;
723
739
  values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
724
740
  }) => Promise<void> | void;
725
- onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
726
741
  onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
727
742
  onFilterFnsChange?: OnChangeFn<{ [key: string]: MRT_FilterOption }>;
728
743
  onGlobalFilterFnChange?: OnChangeFn<MRT_FilterOption>;
@@ -769,9 +784,11 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
769
784
  table: MRT_TableInstance<TData>;
770
785
  }) => ReactNode[];
771
786
  renderRowActions?: ({
787
+ cell,
772
788
  row,
773
789
  table,
774
790
  }: {
791
+ cell: MRT_Cell<TData>;
775
792
  row: MRT_Row<TData>;
776
793
  table: MRT_TableInstance<TData>;
777
794
  }) => ReactNode;
@@ -18,6 +18,7 @@ import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
18
18
  import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
19
19
  import type { MRT_Cell, MRT_TableInstance } from '..';
20
20
  import { MRT_TableBodyRowGrabHandle } from './MRT_TableBodyRowGrabHandle';
21
+ import { MRT_TableBodyCellValue } from './MRT_TableBodyCellValue';
21
22
 
22
23
  interface Props {
23
24
  cell: MRT_Cell;
@@ -282,27 +283,16 @@ export const MRT_TableBodyCell: FC<Props> = ({
282
283
  <MRT_EditCellTextField cell={cell} table={table} />
283
284
  ) : (enableClickToCopy || columnDef.enableClickToCopy) &&
284
285
  columnDef.enableClickToCopy !== false ? (
285
- <>
286
- <MRT_CopyButton cell={cell} table={table}>
287
- <>
288
- {row.getIsGrouped() && !cell.getIsGrouped()
289
- ? null
290
- : columnDef?.Cell?.({ cell, column, row, table }) ??
291
- cell.renderValue()}
292
- </>
293
- </MRT_CopyButton>
294
- {cell.getIsGrouped() && <> ({row.subRows?.length})</>}
295
- </>
286
+ <MRT_CopyButton cell={cell} table={table}>
287
+ <MRT_TableBodyCellValue cell={cell} table={table} />
288
+ </MRT_CopyButton>
296
289
  ) : (
297
- <>
298
- {row.getIsGrouped() && !cell.getIsGrouped()
299
- ? null
300
- : columnDef?.Cell?.({ cell, column, row, table }) ??
301
- cell.renderValue()}
302
- {cell.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
303
- </>
290
+ <MRT_TableBodyCellValue cell={cell} table={table} />
304
291
  )}
305
292
  </>
293
+ {cell.getIsGrouped() && !columnDef.GroupedCell && (
294
+ <> ({row.subRows?.length})</>
295
+ )}
306
296
  </TableCell>
307
297
  );
308
298
  };
@@ -0,0 +1,35 @@
1
+ import React, { FC } from 'react';
2
+ import { MRT_Cell, MRT_TableInstance } from '..';
3
+
4
+ interface Props {
5
+ cell: MRT_Cell;
6
+ table: MRT_TableInstance;
7
+ }
8
+
9
+ export const MRT_TableBodyCellValue: FC<Props> = ({ cell, table }) => {
10
+ const { column, row } = cell;
11
+ const { columnDef } = column;
12
+
13
+ return (
14
+ <>
15
+ {cell.getIsAggregated() && column.columnDef.aggregationFn
16
+ ? columnDef.AggregatedCell?.({
17
+ cell,
18
+ column,
19
+ row,
20
+ table,
21
+ })
22
+ : row.getIsGrouped() && !cell.getIsGrouped()
23
+ ? null
24
+ : (cell.getIsGrouped() &&
25
+ columnDef.GroupedCell?.({
26
+ cell,
27
+ column,
28
+ row,
29
+ table,
30
+ })) ||
31
+ (columnDef?.Cell?.({ cell, column, row, table }) ??
32
+ cell.renderValue())}
33
+ </>
34
+ );
35
+ };
@@ -1,14 +1,18 @@
1
- import React, { FC, ReactNode, useState } from 'react';
1
+ import React, { ReactNode, useState } from 'react';
2
2
  import { Button, Tooltip } from '@mui/material';
3
3
  import { MRT_Cell, MRT_TableInstance } from '..';
4
4
 
5
- interface Props {
6
- cell: MRT_Cell;
5
+ interface Props<TData extends Record<string, any> = {}> {
6
+ cell: MRT_Cell<TData>;
7
7
  children: ReactNode;
8
- table: MRT_TableInstance;
8
+ table: MRT_TableInstance<TData>;
9
9
  }
10
10
 
11
- export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
11
+ export const MRT_CopyButton = <TData extends Record<string, any> = {}>({
12
+ cell,
13
+ children,
14
+ table,
15
+ }: Props<TData>) => {
12
16
  const {
13
17
  options: { localization, muiTableBodyCellCopyButtonProps },
14
18
  } = table;
@@ -2,7 +2,7 @@ import React, { FC, MouseEvent, useState } from 'react';
2
2
  import { IconButton, Tooltip } from '@mui/material';
3
3
  import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
4
4
  import { MRT_EditActionButtons } from './MRT_EditActionButtons';
5
- import type { MRT_Row, MRT_TableInstance } from '..';
5
+ import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
6
6
 
7
7
  const commonIconButtonStyles = {
8
8
  height: '2rem',
@@ -16,11 +16,12 @@ const commonIconButtonStyles = {
16
16
  };
17
17
 
18
18
  interface Props {
19
+ cell: MRT_Cell
19
20
  row: MRT_Row;
20
21
  table: MRT_TableInstance;
21
22
  }
22
23
 
23
- export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
24
+ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ cell, row, table }) => {
24
25
  const {
25
26
  getState,
26
27
  options: {
@@ -52,12 +53,16 @@ export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row, table }) => {
52
53
  return (
53
54
  <>
54
55
  {renderRowActions ? (
55
- <>{renderRowActions({ row, table })}</>
56
+ <>{renderRowActions({ cell, row, table })}</>
56
57
  ) : row.id === editingRow?.id && editingMode === 'row' ? (
57
58
  <MRT_EditActionButtons row={row} table={table} />
58
59
  ) : !renderRowActionMenuItems && enableEditing ? (
59
60
  <Tooltip placement="right" arrow title={localization.edit}>
60
- <IconButton sx={commonIconButtonStyles} onClick={handleStartEditMode}>
61
+ <IconButton
62
+ aria-label={localization.edit}
63
+ sx={commonIconButtonStyles}
64
+ onClick={handleStartEditMode}
65
+ >
61
66
  <EditIcon />
62
67
  </IconButton>
63
68
  </Tooltip>
@@ -1,4 +1,4 @@
1
- import { ColumnOrderState } from '@tanstack/react-table';
1
+ import { ColumnOrderState, GroupingState } from '@tanstack/react-table';
2
2
  import {
3
3
  MaterialReactTableProps,
4
4
  MRT_Column,
@@ -107,6 +107,16 @@ export const reorderColumn = <TData extends Record<string, any> = {}>(
107
107
  return [...columnOrder];
108
108
  };
109
109
 
110
+ export const showExpandColumn = <TData extends Record<string, any> = {}>(
111
+ props: MaterialReactTableProps<TData>,
112
+ grouping?: GroupingState,
113
+ ) =>
114
+ !!(
115
+ props.enableExpanding ||
116
+ (props.enableGrouping && (grouping === undefined || grouping?.length)) ||
117
+ props.renderDetailPanel
118
+ );
119
+
110
120
  export const getLeadingDisplayColumnIds = <
111
121
  TData extends Record<string, any> = {},
112
122
  >(
@@ -119,9 +129,7 @@ export const getLeadingDisplayColumnIds = <
119
129
  ['row', 'modal'].includes(props.editingMode ?? ''))) &&
120
130
  'mrt-row-actions',
121
131
  props.positionExpandColumn === 'first' &&
122
- (props.enableExpanding ||
123
- props.enableGrouping ||
124
- props.renderDetailPanel) &&
132
+ showExpandColumn(props) &&
125
133
  'mrt-row-expand',
126
134
  props.enableRowSelection && 'mrt-row-select',
127
135
  props.enableRowNumbers && 'mrt-row-numbers',
@@ -137,9 +145,7 @@ export const getTrailingDisplayColumnIds = <
137
145
  ['row', 'modal'].includes(props.editingMode ?? ''))) &&
138
146
  'mrt-row-actions',
139
147
  props.positionExpandColumn === 'last' &&
140
- (props.enableExpanding ||
141
- props.enableGrouping ||
142
- props.renderDetailPanel) &&
148
+ showExpandColumn(props) &&
143
149
  'mrt-row-expand',
144
150
  ];
145
151
 
@@ -70,7 +70,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
70
70
  if (enableGrouping && hoveredColumn?.id === 'drop-zone') {
71
71
  setHoveredColumn(null);
72
72
  }
73
- if (enableColumnOrdering && draggingColumn) {
73
+ if (enableColumnOrdering && draggingColumn && columnDefType !== 'group') {
74
74
  setHoveredColumn(
75
75
  columnDef.enableColumnOrdering !== false ? column : null,
76
76
  );
@@ -151,10 +151,8 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
151
151
  ? 'sticky'
152
152
  : undefined,
153
153
  pt:
154
- columnDefType === 'group'
155
- ? 0
156
- : density === 'compact'
157
- ? '0.25'
154
+ columnDefType === 'group' || density === 'compact'
155
+ ? '0.25rem'
158
156
  : density === 'comfortable'
159
157
  ? '.75rem'
160
158
  : '1.25rem',
package/src/index.tsx CHANGED
@@ -6,6 +6,7 @@ import type { MRT_Icons } from './icons';
6
6
  import type { MRT_Localization } from './localization';
7
7
  export type { MRT_Localization, MRT_Icons };
8
8
 
9
+ import { MRT_CopyButton } from './buttons/MRT_CopyButton';
9
10
  import { MRT_FullScreenToggleButton } from './buttons/MRT_FullScreenToggleButton';
10
11
  import { MRT_GlobalFilterTextField } from './inputs/MRT_GlobalFilterTextField';
11
12
  import { MRT_ShowHideColumnsButton } from './buttons/MRT_ShowHideColumnsButton';
@@ -20,4 +21,5 @@ export {
20
21
  MRT_ToggleDensePaddingButton,
21
22
  MRT_ToggleFiltersButton,
22
23
  MRT_ToggleGlobalFilterButton,
24
+ MRT_CopyButton,
23
25
  };
@@ -9,6 +9,7 @@ import {
9
9
  getPaginationRowModel,
10
10
  getSortedRowModel,
11
11
  useReactTable,
12
+ GroupingState,
12
13
  } from '@tanstack/react-table';
13
14
  import { Box, Dialog, Grow } from '@mui/material';
14
15
  import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
@@ -22,6 +23,7 @@ import {
22
23
  getDefaultColumnOrderIds,
23
24
  getDefaultColumnFilterFn,
24
25
  defaultDisplayColumnDefOptions,
26
+ showExpandColumn,
25
27
  } from '../column.utils';
26
28
  import type {
27
29
  MRT_Cell,
@@ -95,6 +97,9 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
95
97
  const [globalFilterFn, setGlobalFilterFn] = useState<MRT_FilterOption>(
96
98
  initialState.globalFilterFn ?? 'fuzzy',
97
99
  );
100
+ const [grouping, setGrouping] = useState<GroupingState>(
101
+ initialState.grouping ?? [],
102
+ );
98
103
  const [hoveredColumn, setHoveredColumn] = useState<
99
104
  MRT_Column<TData> | { id: string } | null
100
105
  >(initialState.hoveredColumn ?? null);
@@ -126,8 +131,12 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
126
131
  id: 'mrt-row-drag',
127
132
  },
128
133
  columnOrder.includes('mrt-row-actions') && {
129
- Cell: ({ row }) => (
130
- <MRT_ToggleRowActionMenuButton row={row as any} table={table} />
134
+ Cell: ({ cell, row }) => (
135
+ <MRT_ToggleRowActionMenuButton
136
+ cell={cell as any}
137
+ row={row as any}
138
+ table={table}
139
+ />
131
140
  ),
132
141
  header: props.localization?.actions,
133
142
  size: 70,
@@ -135,20 +144,21 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
135
144
  ...props.displayColumnDefOptions?.['mrt-row-actions'],
136
145
  id: 'mrt-row-actions',
137
146
  },
138
- columnOrder.includes('mrt-row-expand') && {
139
- Cell: ({ row }) => (
140
- <MRT_ExpandButton row={row as any} table={table} />
141
- ),
142
- Header: () =>
143
- props.enableExpandAll ? (
144
- <MRT_ExpandAllButton table={table} />
145
- ) : null,
146
- header: props.localization?.expand,
147
- size: 60,
148
- ...defaultDisplayColumnDefOptions,
149
- ...props.displayColumnDefOptions?.['mrt-row-expand'],
150
- id: 'mrt-row-expand',
151
- },
147
+ columnOrder.includes('mrt-row-expand') &&
148
+ showExpandColumn(props, grouping) && {
149
+ Cell: ({ row }) => (
150
+ <MRT_ExpandButton row={row as any} table={table} />
151
+ ),
152
+ Header: () =>
153
+ props.enableExpandAll ? (
154
+ <MRT_ExpandAllButton table={table} />
155
+ ) : null,
156
+ header: props.localization?.expand,
157
+ size: 60,
158
+ ...defaultDisplayColumnDefOptions,
159
+ ...props.displayColumnDefOptions?.['mrt-row-expand'],
160
+ id: 'mrt-row-expand',
161
+ },
152
162
  columnOrder.includes('mrt-row-select') && {
153
163
  Cell: ({ row }) => (
154
164
  <MRT_SelectCheckbox row={row as any} table={table} />
@@ -176,6 +186,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
176
186
  ).filter(Boolean),
177
187
  [
178
188
  columnOrder,
189
+ grouping,
179
190
  props.displayColumnDefOptions,
180
191
  props.editingMode,
181
192
  props.enableColumnDragging,
@@ -192,6 +203,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
192
203
  props.enableSelectAll,
193
204
  props.localization,
194
205
  props.positionActionsColumn,
206
+ props.renderDetailPanel,
195
207
  ],
196
208
  );
197
209
 
@@ -241,6 +253,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
241
253
  getPaginationRowModel: getPaginationRowModel(),
242
254
  getSortedRowModel: getSortedRowModel(),
243
255
  onColumnOrderChange: setColumnOrder,
256
+ onGroupingChange: setGrouping,
244
257
  getSubRows: (row) => row?.subRows,
245
258
  ...props,
246
259
  //@ts-ignore
@@ -258,6 +271,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
258
271
  editingCell,
259
272
  editingRow,
260
273
  globalFilterFn,
274
+ grouping,
261
275
  hoveredColumn,
262
276
  hoveredRow,
263
277
  isFullScreen,
@@ -16,7 +16,7 @@ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
16
16
  getState,
17
17
  options: {
18
18
  enablePagination,
19
- muiTableBottomToolbarProps,
19
+ muiBottomToolbarProps,
20
20
  positionPagination,
21
21
  positionToolbarAlertBanner,
22
22
  positionToolbarDropZone,
@@ -29,9 +29,9 @@ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
29
29
  const isMobile = useMediaQuery('(max-width:720px)');
30
30
 
31
31
  const toolbarProps =
32
- muiTableBottomToolbarProps instanceof Function
33
- ? muiTableBottomToolbarProps({ table })
34
- : muiTableBottomToolbarProps;
32
+ muiBottomToolbarProps instanceof Function
33
+ ? muiBottomToolbarProps({ table })
34
+ : muiBottomToolbarProps;
35
35
 
36
36
  const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
37
37
 
@@ -75,9 +75,7 @@ export const MRT_BottomToolbar: FC<Props> = ({ table }) => {
75
75
  }}
76
76
  >
77
77
  {renderBottomToolbarCustomActions ? (
78
- <Box sx={{ p: '0.5rem' }}>
79
- {renderBottomToolbarCustomActions({ table })}
80
- </Box>
78
+ renderBottomToolbarCustomActions({ table })
81
79
  ) : (
82
80
  <span />
83
81
  )}
@@ -15,14 +15,23 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
15
15
  getPrePaginationRowModel,
16
16
  getSelectedRowModel,
17
17
  getState,
18
- options: { localization, muiTableToolbarAlertBannerProps },
18
+ options: {
19
+ localization,
20
+ muiToolbarAlertBannerProps,
21
+ muiToolbarAlertBannerChipProps,
22
+ },
19
23
  } = table;
20
24
  const { grouping, showAlertBanner } = getState();
21
25
 
22
26
  const alertProps =
23
- muiTableToolbarAlertBannerProps instanceof Function
24
- ? muiTableToolbarAlertBannerProps({ table })
25
- : muiTableToolbarAlertBannerProps;
27
+ muiToolbarAlertBannerProps instanceof Function
28
+ ? muiToolbarAlertBannerProps({ table })
29
+ : muiToolbarAlertBannerProps;
30
+
31
+ const chipProps =
32
+ muiToolbarAlertBannerChipProps instanceof Function
33
+ ? muiToolbarAlertBannerChipProps({ table })
34
+ : muiToolbarAlertBannerChipProps;
26
35
 
27
36
  const selectMessage =
28
37
  getSelectedRowModel().rows.length > 0
@@ -45,9 +54,9 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
45
54
  <Fragment key={`${index}-${columnId}`}>
46
55
  {index > 0 ? localization.thenBy : ''}
47
56
  <Chip
48
- color="secondary"
49
57
  label={table.getColumn(columnId).columnDef.header}
50
58
  onDelete={() => table.getColumn(columnId).toggleGrouping()}
59
+ {...chipProps}
51
60
  />
52
61
  </Fragment>
53
62
  ))}
@@ -31,7 +31,7 @@ export const MRT_TopToolbar: FC<Props> = ({ table }) => {
31
31
  enableGlobalFilter,
32
32
  enablePagination,
33
33
  enableToolbarInternalActions,
34
- muiTableTopToolbarProps,
34
+ muiTopToolbarProps,
35
35
  positionGlobalFilter,
36
36
  positionPagination,
37
37
  positionToolbarAlertBanner,
@@ -46,9 +46,9 @@ export const MRT_TopToolbar: FC<Props> = ({ table }) => {
46
46
  const isMobile = useMediaQuery('(max-width:720px)');
47
47
 
48
48
  const toolbarProps =
49
- muiTableTopToolbarProps instanceof Function
50
- ? muiTableTopToolbarProps({ table })
51
- : muiTableTopToolbarProps;
49
+ muiTopToolbarProps instanceof Function
50
+ ? muiTopToolbarProps({ table })
51
+ : muiTopToolbarProps;
52
52
 
53
53
  const stackAlertBanner =
54
54
  isMobile || !!renderTopToolbarCustomActions || showGlobalFilter;