material-react-table 0.18.0 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. package/dist/MaterialReactTable.d.ts +169 -133
  2. package/dist/body/MRT_TableBody.d.ts +1 -1
  3. package/dist/body/MRT_TableBodyCell.d.ts +1 -1
  4. package/dist/body/MRT_TableBodyRow.d.ts +1 -1
  5. package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
  6. package/dist/buttons/MRT_ColumnPinningButtons.d.ts +1 -1
  7. package/dist/buttons/MRT_CopyButton.d.ts +1 -1
  8. package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
  9. package/dist/buttons/MRT_ExpandAllButton.d.ts +1 -1
  10. package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
  11. package/dist/buttons/MRT_FullScreenToggleButton.d.ts +1 -1
  12. package/dist/buttons/MRT_GrabHandleButton.d.ts +1 -1
  13. package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +1 -1
  14. package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -1
  15. package/dist/buttons/MRT_ToggleFiltersButton.d.ts +1 -1
  16. package/dist/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -1
  17. package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
  18. package/dist/filtersFns.d.ts +31 -23
  19. package/dist/footer/MRT_TableFooter.d.ts +1 -1
  20. package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
  21. package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
  22. package/dist/head/MRT_DraggableTableHeadCell.d.ts +1 -1
  23. package/dist/head/MRT_TableHead.d.ts +1 -1
  24. package/dist/head/MRT_TableHeadCell.d.ts +1 -1
  25. package/dist/head/MRT_TableHeadCellColumnActionsButton.d.ts +1 -1
  26. package/dist/head/MRT_TableHeadCellFilterContainer.d.ts +1 -1
  27. package/dist/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
  28. package/dist/head/MRT_TableHeadCellResizeHandle.d.ts +1 -1
  29. package/dist/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
  30. package/dist/head/MRT_TableHeadRow.d.ts +1 -1
  31. package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
  32. package/dist/inputs/MRT_FilterRangeFields.d.ts +1 -1
  33. package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
  34. package/dist/inputs/MRT_GlobalFilterTextField.d.ts +1 -1
  35. package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
  36. package/dist/material-react-table.cjs.development.js +760 -759
  37. package/dist/material-react-table.cjs.development.js.map +1 -1
  38. package/dist/material-react-table.cjs.production.min.js +1 -1
  39. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  40. package/dist/material-react-table.esm.js +762 -761
  41. package/dist/material-react-table.esm.js.map +1 -1
  42. package/dist/menus/MRT_ColumnActionMenu.d.ts +1 -1
  43. package/dist/menus/MRT_FilterOptionMenu.d.ts +1 -1
  44. package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
  45. package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
  46. package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
  47. package/dist/sortingFns.d.ts +10 -3
  48. package/dist/table/MRT_Table.d.ts +1 -1
  49. package/dist/table/MRT_TableContainer.d.ts +1 -1
  50. package/dist/table/MRT_TablePaper.d.ts +1 -1
  51. package/dist/toolbar/MRT_LinearProgressBar.d.ts +1 -1
  52. package/dist/toolbar/MRT_TablePagination.d.ts +1 -1
  53. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
  54. package/dist/toolbar/MRT_ToolbarBottom.d.ts +1 -1
  55. package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +1 -1
  56. package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -1
  57. package/dist/utils.d.ts +10 -16
  58. package/package.json +4 -4
  59. package/src/MaterialReactTable.tsx +167 -156
  60. package/src/body/MRT_TableBody.tsx +5 -6
  61. package/src/body/MRT_TableBodyCell.tsx +18 -27
  62. package/src/body/MRT_TableBodyRow.tsx +7 -7
  63. package/src/body/MRT_TableDetailPanel.tsx +7 -7
  64. package/src/buttons/MRT_ColumnPinningButtons.tsx +3 -3
  65. package/src/buttons/MRT_CopyButton.tsx +5 -7
  66. package/src/buttons/MRT_EditActionButtons.tsx +4 -5
  67. package/src/buttons/MRT_ExpandAllButton.tsx +4 -5
  68. package/src/buttons/MRT_ExpandButton.tsx +4 -5
  69. package/src/buttons/MRT_FullScreenToggleButton.tsx +3 -7
  70. package/src/buttons/MRT_GrabHandleButton.tsx +39 -41
  71. package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -4
  72. package/src/buttons/MRT_ToggleDensePaddingButton.tsx +3 -7
  73. package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -4
  74. package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +4 -8
  75. package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +6 -6
  76. package/src/filtersFns.ts +24 -23
  77. package/src/footer/MRT_TableFooter.tsx +5 -6
  78. package/src/footer/MRT_TableFooterCell.tsx +8 -11
  79. package/src/footer/MRT_TableFooterRow.tsx +5 -9
  80. package/src/head/MRT_DraggableTableHeadCell.tsx +4 -6
  81. package/src/head/MRT_TableHead.tsx +5 -5
  82. package/src/head/MRT_TableHeadCell.tsx +18 -29
  83. package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +6 -8
  84. package/src/head/MRT_TableHeadCellFilterContainer.tsx +5 -7
  85. package/src/head/MRT_TableHeadCellFilterLabel.tsx +13 -19
  86. package/src/head/MRT_TableHeadCellResizeHandle.tsx +12 -11
  87. package/src/head/MRT_TableHeadCellSortLabel.tsx +3 -5
  88. package/src/head/MRT_TableHeadRow.tsx +6 -6
  89. package/src/inputs/MRT_EditCellTextField.tsx +12 -14
  90. package/src/inputs/MRT_FilterRangeFields.tsx +4 -4
  91. package/src/inputs/MRT_FilterTextField.tsx +27 -38
  92. package/src/inputs/MRT_GlobalFilterTextField.tsx +5 -6
  93. package/src/inputs/MRT_SelectCheckbox.tsx +9 -12
  94. package/src/menus/MRT_ColumnActionMenu.tsx +5 -9
  95. package/src/menus/MRT_FilterOptionMenu.tsx +16 -48
  96. package/src/menus/MRT_RowActionMenu.tsx +4 -5
  97. package/src/menus/MRT_ShowHideColumnsMenu.tsx +8 -9
  98. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +11 -10
  99. package/src/sortingFns.ts +11 -3
  100. package/src/table/MRT_Table.tsx +7 -11
  101. package/src/table/MRT_TableContainer.tsx +5 -6
  102. package/src/table/MRT_TablePaper.tsx +7 -8
  103. package/src/table/MRT_TableRoot.tsx +118 -132
  104. package/src/toolbar/MRT_LinearProgressBar.tsx +4 -5
  105. package/src/toolbar/MRT_TablePagination.tsx +7 -9
  106. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +13 -9
  107. package/src/toolbar/MRT_ToolbarBottom.tsx +8 -9
  108. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +10 -10
  109. package/src/toolbar/MRT_ToolbarTop.tsx +11 -11
  110. package/src/utils.ts +56 -50
@@ -17,14 +17,14 @@ interface Props {
17
17
  allColumns: MRT_Column[];
18
18
  column: MRT_Column;
19
19
  isSubMenu?: boolean;
20
- instance: MRT_TableInstance;
20
+ table: MRT_TableInstance;
21
21
  }
22
22
 
23
23
  export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
24
24
  allColumns,
25
25
  column,
26
26
  isSubMenu,
27
- instance,
27
+ table,
28
28
  }) => {
29
29
  const {
30
30
  getState,
@@ -35,11 +35,10 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
35
35
  localization,
36
36
  },
37
37
  setColumnOrder,
38
- } = instance;
39
-
38
+ } = table;
40
39
  const { columnOrder } = getState();
41
-
42
- const { columnDef, columnDefType } = column;
40
+ const { columnDef } = column;
41
+ const { columnDefType } = columnDef;
43
42
 
44
43
  const [, dropRef] = useDrop({
45
44
  accept: 'column',
@@ -94,11 +93,13 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
94
93
  >
95
94
  {columnDefType !== 'group' &&
96
95
  enableColumnOrdering &&
97
- !allColumns.some((col) => col.columnDefType === 'group') &&
96
+ !allColumns.some(
97
+ (col) => col.columnDef.columnDefType === 'group',
98
+ ) &&
98
99
  (columnDef.enableColumnOrdering !== false ? (
99
100
  <MRT_GrabHandleButton
100
101
  ref={dragRef as Ref<HTMLButtonElement>}
101
- instance={instance}
102
+ table={table}
102
103
  />
103
104
  ) : (
104
105
  <Box sx={{ width: '28px' }} />
@@ -106,7 +107,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
106
107
  {enablePinning &&
107
108
  !isSubMenu &&
108
109
  (column.getCanPin() ? (
109
- <MRT_ColumnPinningButtons column={column} instance={instance} />
110
+ <MRT_ColumnPinningButtons column={column} table={table} />
110
111
  ) : (
111
112
  <Box sx={{ width: '70px' }} />
112
113
  ))}
@@ -152,7 +153,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
152
153
  key={`${i}-${c.id}`}
153
154
  column={c}
154
155
  isSubMenu={isSubMenu}
155
- instance={instance}
156
+ table={table}
156
157
  />
157
158
  ))}
158
159
  </>
package/src/sortingFns.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
2
2
  import { Row, sortingFns } from '@tanstack/react-table';
3
- import type { MRT_Row } from '.';
3
+ import { MRT_Row } from '.';
4
4
 
5
- const fuzzy = (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => {
5
+ const fuzzy = <D extends Record<string, any> = {}>(
6
+ rowA: Row<D>,
7
+ rowB: Row<D>,
8
+ columnId: string,
9
+ ) => {
6
10
  let dir = 0;
7
11
  if (rowA.columnFiltersMeta[columnId]) {
8
12
  dir = compareItems(
@@ -17,9 +21,13 @@ const fuzzy = (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => {
17
21
  };
18
22
 
19
23
  export const MRT_SortingFns = {
24
+ ...sortingFns,
20
25
  fuzzy,
21
26
  };
22
27
 
23
- export const rankGlobalFuzzy = (rowA: MRT_Row, rowB: MRT_Row) =>
28
+ export const rankGlobalFuzzy = <D extends Record<string, any> = {}>(
29
+ rowA: MRT_Row<D>,
30
+ rowB: MRT_Row<D>,
31
+ ) =>
24
32
  Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
25
33
  Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
@@ -7,10 +7,10 @@ import { MRT_TableInstance } from '..';
7
7
 
8
8
  interface Props {
9
9
  tableContainerRef: RefObject<HTMLDivElement>;
10
- instance: MRT_TableInstance;
10
+ table: MRT_TableInstance;
11
11
  }
12
12
 
13
- export const MRT_Table: FC<Props> = ({ tableContainerRef, instance }) => {
13
+ export const MRT_Table: FC<Props> = ({ tableContainerRef, table }) => {
14
14
  const {
15
15
  getState,
16
16
  options: {
@@ -21,13 +21,12 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, instance }) => {
21
21
  enableTableHead,
22
22
  muiTableProps,
23
23
  },
24
- } = instance;
25
-
24
+ } = table;
26
25
  const { isFullScreen } = getState();
27
26
 
28
27
  const tableProps =
29
28
  muiTableProps instanceof Function
30
- ? muiTableProps({ instance })
29
+ ? muiTableProps({ table })
31
30
  : muiTableProps;
32
31
 
33
32
  return (
@@ -42,12 +41,9 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, instance }) => {
42
41
  ...tableProps?.sx,
43
42
  }}
44
43
  >
45
- {enableTableHead && <MRT_TableHead instance={instance} />}
46
- <MRT_TableBody
47
- tableContainerRef={tableContainerRef}
48
- instance={instance}
49
- />
50
- {enableTableFooter && <MRT_TableFooter instance={instance} />}
44
+ {enableTableHead && <MRT_TableHead table={table} />}
45
+ <MRT_TableBody tableContainerRef={tableContainerRef} table={table} />
46
+ {enableTableFooter && <MRT_TableFooter table={table} />}
51
47
  </Table>
52
48
  );
53
49
  };
@@ -7,10 +7,10 @@ const useIsomorphicLayoutEffect =
7
7
  typeof window !== 'undefined' ? useLayoutEffect : useEffect;
8
8
 
9
9
  interface Props {
10
- instance: MRT_TableInstance;
10
+ table: MRT_TableInstance;
11
11
  }
12
12
 
13
- export const MRT_TableContainer: FC<Props> = ({ instance }) => {
13
+ export const MRT_TableContainer: FC<Props> = ({ table }) => {
14
14
  const {
15
15
  getState,
16
16
  options: {
@@ -19,15 +19,14 @@ export const MRT_TableContainer: FC<Props> = ({ instance }) => {
19
19
  muiTableContainerProps,
20
20
  tableId,
21
21
  },
22
- } = instance;
23
-
22
+ } = table;
24
23
  const { isFullScreen } = getState();
25
24
 
26
25
  const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
27
26
 
28
27
  const tableContainerProps =
29
28
  muiTableContainerProps instanceof Function
30
- ? muiTableContainerProps({ instance })
29
+ ? muiTableContainerProps({ table })
31
30
  : muiTableContainerProps;
32
31
 
33
32
  useIsomorphicLayoutEffect(() => {
@@ -68,7 +67,7 @@ export const MRT_TableContainer: FC<Props> = ({ instance }) => {
68
67
  ...tableContainerProps?.style,
69
68
  }}
70
69
  >
71
- <MRT_Table tableContainerRef={tableContainerRef} instance={instance} />
70
+ <MRT_Table tableContainerRef={tableContainerRef} table={table} />
72
71
  </TableContainer>
73
72
  );
74
73
  };
@@ -8,15 +8,14 @@ import { MRT_TableContainer } from './MRT_TableContainer';
8
8
  import type { MRT_TableInstance } from '..';
9
9
 
10
10
  interface Props {
11
- instance: MRT_TableInstance;
11
+ table: MRT_TableInstance;
12
12
  }
13
13
 
14
- export const MRT_TablePaper: FC<Props> = ({ instance }) => {
14
+ export const MRT_TablePaper: FC<Props> = ({ table }) => {
15
15
  const {
16
16
  getState,
17
17
  options: { enableToolbarBottom, enableToolbarTop, muiTablePaperProps },
18
- } = instance;
19
-
18
+ } = table;
20
19
  const { isFullScreen } = getState();
21
20
 
22
21
  useEffect(() => {
@@ -31,7 +30,7 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
31
30
 
32
31
  const tablePaperProps =
33
32
  muiTablePaperProps instanceof Function
34
- ? muiTablePaperProps({ instance })
33
+ ? muiTablePaperProps({ table })
35
34
  : muiTablePaperProps;
36
35
 
37
36
  return (
@@ -53,9 +52,9 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
53
52
  width: isFullScreen ? '100vw' : undefined,
54
53
  }}
55
54
  >
56
- {enableToolbarTop && <MRT_ToolbarTop instance={instance} />}
57
- <MRT_TableContainer instance={instance} />
58
- {enableToolbarBottom && <MRT_ToolbarBottom instance={instance} />}
55
+ {enableToolbarTop && <MRT_ToolbarTop table={table} />}
56
+ <MRT_TableContainer table={table} />
57
+ {enableToolbarBottom && <MRT_ToolbarBottom table={table} />}
59
58
  </Paper>
60
59
  </DndProvider>
61
60
  );
@@ -1,11 +1,6 @@
1
1
  import React, { useEffect, useMemo, useState } from 'react';
2
2
  import {
3
- FilterFn,
4
- ReactTableGenerics,
5
- Table,
6
3
  TableState,
7
- createTable,
8
- filterFns,
9
4
  getCoreRowModel,
10
5
  getExpandedRowModel,
11
6
  getFacetedRowModel,
@@ -13,14 +8,12 @@ import {
13
8
  getGroupedRowModel,
14
9
  getPaginationRowModel,
15
10
  getSortedRowModel,
16
- useTableInstance,
17
- sortingFns,
11
+ useReactTable,
18
12
  } from '@tanstack/react-table';
19
13
  import {
20
14
  MRT_Cell,
21
15
  MRT_ColumnDef,
22
- MRT_FilterFn,
23
- MRT_FILTER_OPTION,
16
+ MRT_FilterOption,
24
17
  MRT_Row,
25
18
  MRT_TableInstance,
26
19
  MRT_TableState,
@@ -33,14 +26,11 @@ import { MaterialReactTableProps } from '../MaterialReactTable';
33
26
  import { MRT_TablePaper } from './MRT_TablePaper';
34
27
  import { Box, Dialog, Grow } from '@mui/material';
35
28
  import {
36
- createDataColumn,
37
- createDisplayColumn,
38
- createGroup,
29
+ prepareColumns,
39
30
  getAllLeafColumnDefs,
40
31
  getDefaultColumnOrderIds,
41
32
  } from '../utils';
42
33
  import { MRT_FilterFns } from '../filtersFns';
43
- import { MRT_SortingFns } from '../sortingFns';
44
34
 
45
35
  export const MRT_TableRoot = <D extends Record<string, any> = {}>(
46
36
  props: MaterialReactTableProps<D>,
@@ -84,125 +74,114 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
84
74
  );
85
75
 
86
76
  const [currentFilterFns, setCurrentFilterFns] = useState<{
87
- [key: string]: MRT_FilterFn;
77
+ [key: string]: MRT_FilterOption;
88
78
  }>(() =>
89
79
  Object.assign(
90
80
  {},
91
- ...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => ({
92
- [c.id as string]:
93
- c.filterFn ??
94
- initialState?.currentFilterFns?.[c.id] ??
95
- (!!c.filterSelectOptions?.length ? 'equals' : 'fuzzy'),
96
- })),
81
+ ...getAllLeafColumnDefs(props.columns as MRT_ColumnDef<D>[]).map(
82
+ (col) => ({
83
+ [col.id?.toString() ?? col.accessorKey?.toString() ?? '']:
84
+ col.filterFn instanceof Function
85
+ ? col.filterFn.name ?? 'custom'
86
+ : col.filterFn ??
87
+ initialState?.currentFilterFns?.[
88
+ col.id?.toString() ?? col.accessorKey?.toString() ?? ''
89
+ ] ??
90
+ (!!col.filterSelectOptions?.length ? 'equals' : 'fuzzy'),
91
+ }),
92
+ ),
97
93
  ),
98
94
  );
99
95
 
100
- const [currentGlobalFilterFn, setCurrentGlobalFilterFn] = useState<
101
- MRT_FILTER_OPTION | FilterFn<ReactTableGenerics> | string | number | symbol
102
- >(props.globalFilterFn ?? 'fuzzy');
96
+ const [currentGlobalFilterFn, setCurrentGlobalFilterFn] =
97
+ useState<MRT_FilterOption>(
98
+ props.globalFilterFn instanceof String
99
+ ? (props.globalFilterFn as MRT_FilterOption)
100
+ : 'fuzzy',
101
+ );
103
102
 
104
- const table = useMemo(
103
+ const displayColumns = useMemo(
105
104
  () =>
106
- // @ts-ignore
107
- createTable().setOptions({
108
- filterFns: { ...filterFns, ...MRT_FilterFns, ...props.filterFns },
109
- getCoreRowModel: getCoreRowModel(),
110
- getExpandedRowModel: getExpandedRowModel(),
111
- getFacetedRowModel: getFacetedRowModel(),
112
- getFilteredRowModel: getFilteredRowModel(),
113
- getGroupedRowModel: getGroupedRowModel(),
114
- getPaginationRowModel: getPaginationRowModel(),
115
- getSortedRowModel: getSortedRowModel(),
116
- sortingFns: { ...sortingFns, ...MRT_SortingFns, ...props.sortingFns },
117
- }) as Table<D>,
118
- [],
105
+ (
106
+ [
107
+ columnOrder.includes('mrt-row-actions') && {
108
+ Cell: ({ cell }) => (
109
+ <MRT_ToggleRowActionMenuButton
110
+ row={cell.row as any}
111
+ table={table}
112
+ />
113
+ ),
114
+ columnDefType: 'display',
115
+ header: props.localization?.actions,
116
+ id: 'mrt-row-actions',
117
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
118
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
119
+ size: 70,
120
+ },
121
+ columnOrder.includes('mrt-expand') && {
122
+ Cell: ({ cell }) => (
123
+ <MRT_ExpandButton row={cell.row as any} table={table} />
124
+ ),
125
+ Header: () =>
126
+ props.enableExpandAll ? (
127
+ <MRT_ExpandAllButton table={table} />
128
+ ) : null,
129
+ columnDefType: 'display',
130
+ header: props.localization?.expand,
131
+ id: 'mrt-expand',
132
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
133
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
134
+ size: 60,
135
+ },
136
+ columnOrder.includes('mrt-select') && {
137
+ Cell: ({ cell }) => (
138
+ <MRT_SelectCheckbox row={cell.row as any} table={table} />
139
+ ),
140
+ Header: () =>
141
+ props.enableSelectAll ? (
142
+ <MRT_SelectCheckbox selectAll table={table} />
143
+ ) : null,
144
+ columnDefType: 'display',
145
+ header: props.localization?.select,
146
+ id: 'mrt-select',
147
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
148
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
149
+ size: 60,
150
+ },
151
+ columnOrder.includes('mrt-row-numbers') && {
152
+ Cell: ({ cell }) => cell.row.index + 1,
153
+ Header: () => props.localization?.rowNumber,
154
+ columnDefType: 'display',
155
+ header: props.localization?.rowNumbers,
156
+ id: 'mrt-row-numbers',
157
+ muiTableBodyCellProps: props.muiTableBodyCellProps,
158
+ muiTableHeadCellProps: props.muiTableHeadCellProps,
159
+ size: 60,
160
+ },
161
+ ] as MRT_ColumnDef<D>[]
162
+ ).filter(Boolean),
163
+ [
164
+ columnOrder,
165
+ props.editingMode,
166
+ props.enableEditing,
167
+ props.enableExpandAll,
168
+ props.enableExpanding,
169
+ props.enableGrouping,
170
+ props.enableRowActions,
171
+ props.enableRowNumbers,
172
+ props.enableRowSelection,
173
+ props.enableSelectAll,
174
+ props.localization,
175
+ props.muiTableBodyCellProps,
176
+ props.muiTableHeadCellProps,
177
+ props.positionActionsColumn,
178
+ ],
119
179
  );
120
180
 
121
- const displayColumns = useMemo(() => {
122
- return [
123
- columnOrder.includes('mrt-row-actions') &&
124
- createDisplayColumn(table, {
125
- Cell: ({ cell }) => (
126
- <MRT_ToggleRowActionMenuButton
127
- row={cell.row as any}
128
- instance={instance}
129
- />
130
- ),
131
- header: props.localization?.actions,
132
- id: 'mrt-row-actions',
133
- muiTableBodyCellProps: props.muiTableBodyCellProps,
134
- muiTableHeadCellProps: props.muiTableHeadCellProps,
135
- size: 70,
136
- }),
137
- columnOrder.includes('mrt-expand') &&
138
- createDisplayColumn(table, {
139
- Cell: ({ cell }) => (
140
- <MRT_ExpandButton row={cell.row as any} instance={instance} />
141
- ),
142
- Header: () =>
143
- props.enableExpandAll ? (
144
- <MRT_ExpandAllButton instance={instance} />
145
- ) : null,
146
- header: props.localization?.expand,
147
- id: 'mrt-expand',
148
- muiTableBodyCellProps: props.muiTableBodyCellProps,
149
- muiTableHeadCellProps: props.muiTableHeadCellProps,
150
- size: 60,
151
- }),
152
- columnOrder.includes('mrt-select') &&
153
- createDisplayColumn(table, {
154
- Cell: ({ cell }) => (
155
- <MRT_SelectCheckbox row={cell.row as any} instance={instance} />
156
- ),
157
- Header: () =>
158
- props.enableSelectAll ? (
159
- <MRT_SelectCheckbox selectAll instance={instance} />
160
- ) : null,
161
- header: props.localization?.select,
162
- id: 'mrt-select',
163
- muiTableBodyCellProps: props.muiTableBodyCellProps,
164
- muiTableHeadCellProps: props.muiTableHeadCellProps,
165
- size: 60,
166
- }),
167
- columnOrder.includes('mrt-row-numbers') &&
168
- createDisplayColumn(table, {
169
- Cell: ({ cell }) => cell.row.index + 1,
170
- Header: () => props.localization?.rowNumber,
171
- header: props.localization?.rowNumbers,
172
- id: 'mrt-row-numbers',
173
- muiTableBodyCellProps: props.muiTableBodyCellProps,
174
- muiTableHeadCellProps: props.muiTableHeadCellProps,
175
- size: 60,
176
- }),
177
- ].filter(Boolean) as MRT_ColumnDef<D>[];
178
- }, [
179
- columnOrder,
180
- props.editingMode,
181
- props.enableEditing,
182
- props.enableExpandAll,
183
- props.enableExpanding,
184
- props.enableGrouping,
185
- props.enableRowActions,
186
- props.enableRowNumbers,
187
- props.enableRowSelection,
188
- props.enableSelectAll,
189
- props.localization,
190
- props.muiTableBodyCellProps,
191
- props.muiTableHeadCellProps,
192
- props.positionActionsColumn,
193
- table,
194
- ]);
195
-
196
- const columns = useMemo(
197
- () => [
198
- ...displayColumns,
199
- ...props.columns.map((column) =>
200
- column.columns
201
- ? createGroup(table, column as any, currentFilterFns)
202
- : createDataColumn(table, column as any, currentFilterFns),
203
- ),
204
- ],
205
- [table, props.columns, currentFilterFns],
181
+ const columnDefs = useMemo(
182
+ () =>
183
+ prepareColumns([...displayColumns, ...props.columns], currentFilterFns),
184
+ [currentFilterFns, displayColumns, props.columns],
206
185
  );
207
186
 
208
187
  const data: D[] = useMemo(
@@ -213,8 +192,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
213
192
  Object.assign(
214
193
  {},
215
194
  ...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
216
- (c) => ({
217
- [c.id]: null,
195
+ (col) => ({
196
+ [col.id ?? col.accessorKey ?? '']: null,
218
197
  }),
219
198
  ),
220
199
  ),
@@ -224,17 +203,24 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
224
203
  );
225
204
 
226
205
  //@ts-ignore
227
- const instance = {
228
- //@ts-ignore
229
- ...useTableInstance(table, {
206
+ const table = {
207
+ ...useReactTable({
208
+ getCoreRowModel: getCoreRowModel(),
209
+ getExpandedRowModel: getExpandedRowModel(),
210
+ getFacetedRowModel: getFacetedRowModel(),
211
+ getFilteredRowModel: getFilteredRowModel(),
212
+ getGroupedRowModel: getGroupedRowModel(),
213
+ getPaginationRowModel: getPaginationRowModel(),
214
+ getSortedRowModel: getSortedRowModel(),
230
215
  onColumnOrderChange: setColumnOrder,
231
216
  ...props,
232
217
  //@ts-ignore
233
- columns,
218
+ columns: columnDefs,
234
219
  data,
235
- getSubRows: (row) => (row as MRT_Row)?.subRows,
220
+ getSubRows: (row) => row?.subRows,
236
221
  //@ts-ignore
237
- globalFilterFn: currentGlobalFilterFn,
222
+ globalFilterFn:
223
+ MRT_FilterFns[currentGlobalFilterFn] ?? MRT_FilterFns.fuzzy,
238
224
  initialState,
239
225
  state: {
240
226
  columnOrder,
@@ -277,9 +263,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
277
263
  open={isFullScreen}
278
264
  transitionDuration={400}
279
265
  >
280
- <MRT_TablePaper instance={instance} />
266
+ <MRT_TablePaper table={table} />
281
267
  </Dialog>
282
- {!isFullScreen && <MRT_TablePaper instance={instance} />}
268
+ {!isFullScreen && <MRT_TablePaper table={table} />}
283
269
  </>
284
270
  );
285
271
  };
@@ -4,20 +4,19 @@ import { MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
6
6
  alignTo: 'bottom' | 'top';
7
- instance: MRT_TableInstance;
7
+ table: MRT_TableInstance;
8
8
  }
9
9
 
10
- export const MRT_LinearProgressBar: FC<Props> = ({ alignTo, instance }) => {
10
+ export const MRT_LinearProgressBar: FC<Props> = ({ alignTo, table }) => {
11
11
  const {
12
12
  options: { muiLinearProgressProps },
13
13
  getState,
14
- } = instance;
15
-
14
+ } = table;
16
15
  const { isLoading, showProgressBars } = getState();
17
16
 
18
17
  const linearProgressProps =
19
18
  muiLinearProgressProps instanceof Function
20
- ? muiLinearProgressProps({ instance })
19
+ ? muiLinearProgressProps({ table })
21
20
  : muiLinearProgressProps;
22
21
 
23
22
  return (
@@ -3,11 +3,11 @@ import { TablePagination } from '@mui/material';
3
3
  import { MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
6
- instance: MRT_TableInstance;
6
+ table: MRT_TableInstance;
7
7
  position: 'top' | 'bottom';
8
8
  }
9
9
 
10
- export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
10
+ export const MRT_TablePagination: FC<Props> = ({ table, position }) => {
11
11
  const {
12
12
  getPrePaginationRowModel,
13
13
  getState,
@@ -18,26 +18,24 @@ export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
18
18
  enableToolbarInternalActions,
19
19
  rowCount,
20
20
  },
21
- } = instance;
22
-
21
+ } = table;
23
22
  const {
24
23
  pagination: { pageSize = 10, pageIndex = 0 },
25
24
  showGlobalFilter,
26
25
  } = getState();
27
26
 
27
+ const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
28
+ const showFirstLastPageButtons = totalRowCount / pageSize > 2;
29
+
28
30
  const tablePaginationProps =
29
31
  muiTablePaginationProps instanceof Function
30
- ? muiTablePaginationProps({ instance })
32
+ ? muiTablePaginationProps({ table })
31
33
  : muiTablePaginationProps;
32
34
 
33
35
  const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
34
36
  setPageSize(+event.target.value);
35
37
  };
36
38
 
37
- const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
38
-
39
- const showFirstLastPageButtons = totalRowCount / pageSize > 2;
40
-
41
39
  return (
42
40
  <TablePagination
43
41
  SelectProps={{
@@ -1,28 +1,27 @@
1
1
  import React, { FC, Fragment } from 'react';
2
- import { Alert, Box, Chip, Collapse } from '@mui/material';
2
+ import { Alert, AlertTitle, Box, Chip, Collapse } from '@mui/material';
3
3
  import { MRT_TableInstance } from '..';
4
4
 
5
5
  interface Props {
6
6
  stackAlertBanner?: boolean;
7
- instance: MRT_TableInstance;
7
+ table: MRT_TableInstance;
8
8
  }
9
9
 
10
10
  export const MRT_ToolbarAlertBanner: FC<Props> = ({
11
11
  stackAlertBanner,
12
- instance,
12
+ table,
13
13
  }) => {
14
14
  const {
15
15
  getPrePaginationRowModel,
16
16
  getSelectedRowModel,
17
17
  getState,
18
18
  options: { localization, muiTableToolbarAlertBannerProps },
19
- } = instance;
20
-
19
+ } = table;
21
20
  const { grouping, showAlertBanner } = getState();
22
21
 
23
22
  const alertProps =
24
23
  muiTableToolbarAlertBannerProps instanceof Function
25
- ? muiTableToolbarAlertBannerProps({ instance })
24
+ ? muiTableToolbarAlertBannerProps({ table })
26
25
  : muiTableToolbarAlertBannerProps;
27
26
 
28
27
  const selectMessage =
@@ -47,8 +46,8 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
47
46
  {index > 0 ? localization.thenBy : ''}
48
47
  <Chip
49
48
  color="secondary"
50
- label={instance.getColumn(columnId).columnDef.header}
51
- onDelete={() => instance.getColumn(columnId).toggleGrouping()}
49
+ label={table.getColumn(columnId).columnDef.header}
50
+ onDelete={() => table.getColumn(columnId).toggleGrouping()}
52
51
  />
53
52
  </Fragment>
54
53
  ))}
@@ -63,6 +62,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
63
62
  <Alert
64
63
  color="info"
65
64
  icon={false}
65
+ {...alertProps}
66
66
  sx={{
67
67
  borderRadius: 0,
68
68
  fontSize: '1rem',
@@ -75,9 +75,13 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
75
75
  zIndex: 2,
76
76
  ...alertProps?.sx,
77
77
  }}
78
- {...alertProps}
79
78
  >
79
+ {alertProps?.title && <AlertTitle>{alertProps.title}</AlertTitle>}
80
80
  <Box sx={{ p: '0.5rem 1rem' }}>
81
+ {alertProps?.children}
82
+ {alertProps?.children && (selectMessage || groupedByMessage) && (
83
+ <br />
84
+ )}
81
85
  {selectMessage}
82
86
  {selectMessage && groupedByMessage && <br />}
83
87
  {groupedByMessage}