material-react-table 1.2.10 → 1.3.0-beta.2
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/cjs/MaterialReactTable.d.ts +7 -3
- package/dist/cjs/column.utils.d.ts +29 -17
- package/dist/cjs/index.js +17 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/table/MRT_TableRoot.d.ts +1 -1
- package/dist/esm/MaterialReactTable.d.ts +7 -3
- package/dist/esm/column.utils.d.ts +29 -17
- package/dist/esm/material-react-table.esm.js +17 -4
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +1 -1
- package/dist/index.d.ts +19 -4
- package/package.json +10 -9
- package/src/MaterialReactTable.tsx +11 -1
- package/src/body/MRT_TableBodyCell.tsx +2 -1
- package/src/column.utils.ts +30 -1
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +1 -1
- package/src/table/MRT_TableRoot.tsx +2 -1
|
@@ -181,7 +181,7 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
181
181
|
values: Record<(string & Record<never, never>) | (string & import("@tanstack/table-core").DeepKeys<TData>), any>;
|
|
182
182
|
}) => void | Promise<void>) | undefined;
|
|
183
183
|
onEditingRowChange?: import("@tanstack/table-core").OnChangeFn<MRT_Row<TData> | null> | undefined;
|
|
184
|
-
|
|
184
|
+
onColumnFilterFnsChange?: import("@tanstack/table-core").OnChangeFn<{
|
|
185
185
|
[key: string]: MRT_FilterOption;
|
|
186
186
|
}> | undefined;
|
|
187
187
|
onGlobalFilterFnChange?: import("@tanstack/table-core").OnChangeFn<MRT_FilterOption> | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -19,11 +19,23 @@ import { TableProps } from '@mui/material/Table';
|
|
|
19
19
|
import { TableRowProps } from '@mui/material/TableRow';
|
|
20
20
|
import { TextFieldProps } from '@mui/material/TextField';
|
|
21
21
|
import { ToolbarProps } from '@mui/material/Toolbar';
|
|
22
|
-
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
22
|
+
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, AggregationFn, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
23
23
|
import { Options, VirtualItem } from 'react-virtual';
|
|
24
24
|
import * as _tanstack_table_core from '@tanstack/table-core';
|
|
25
25
|
import { RankingInfo } from '@tanstack/match-sorter-utils';
|
|
26
26
|
|
|
27
|
+
declare const MRT_AggregationFns: {
|
|
28
|
+
sum: _tanstack_table_core.AggregationFn<any>;
|
|
29
|
+
min: _tanstack_table_core.AggregationFn<any>;
|
|
30
|
+
max: _tanstack_table_core.AggregationFn<any>;
|
|
31
|
+
extent: _tanstack_table_core.AggregationFn<any>;
|
|
32
|
+
mean: _tanstack_table_core.AggregationFn<any>;
|
|
33
|
+
median: _tanstack_table_core.AggregationFn<any>;
|
|
34
|
+
unique: _tanstack_table_core.AggregationFn<any>;
|
|
35
|
+
uniqueCount: _tanstack_table_core.AggregationFn<any>;
|
|
36
|
+
count: _tanstack_table_core.AggregationFn<any>;
|
|
37
|
+
};
|
|
38
|
+
|
|
27
39
|
declare const MRT_FilterFns: {
|
|
28
40
|
between: {
|
|
29
41
|
<TData extends Record<string, any> = {}>(row: Row<TData>, id: string, filterValues: [string | number, string | number]): boolean;
|
|
@@ -308,7 +320,7 @@ declare type MRT_TableState<TData extends Record<string, any> = {}> = TableState
|
|
|
308
320
|
showProgressBars: boolean;
|
|
309
321
|
showSkeletons: boolean;
|
|
310
322
|
};
|
|
311
|
-
declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnDef<TData, unknown>, 'aggregatedCell' | 'cell' | 'columns' | 'filterFn' | 'footer' | 'header' | 'id' | 'sortingFn'> & {
|
|
323
|
+
declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<ColumnDef<TData, unknown>, 'accessorKey' | 'aggregatedCell' | 'aggregationFn' | 'cell' | 'columns' | 'filterFn' | 'footer' | 'header' | 'id' | 'sortingFn'> & {
|
|
312
324
|
AggregatedCell?: ({ cell, column, row, table, }: {
|
|
313
325
|
cell: MRT_Cell<TData>;
|
|
314
326
|
column: MRT_Column<TData>;
|
|
@@ -365,6 +377,7 @@ declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<Column
|
|
|
365
377
|
* @example accessorKey: 'name.firstName' //deep key dot notation
|
|
366
378
|
*/
|
|
367
379
|
accessorKey?: DeepKeys<TData>;
|
|
380
|
+
aggregationFn?: MRT_AggregationFn<TData> | Array<MRT_AggregationFn<TData>>;
|
|
368
381
|
/**
|
|
369
382
|
* Specify what type of column this is. Either `data`, `display`, or `group`. Defaults to `data`.
|
|
370
383
|
* Leave this blank if you are just creating a normal data column.
|
|
@@ -490,6 +503,8 @@ declare type MRT_Cell<TData extends Record<string, any> = {}> = Omit<Cell<TData,
|
|
|
490
503
|
column: MRT_Column<TData>;
|
|
491
504
|
row: MRT_Row<TData>;
|
|
492
505
|
};
|
|
506
|
+
declare type MRT_AggregationOption = string & keyof typeof MRT_AggregationFns;
|
|
507
|
+
declare type MRT_AggregationFn<TData extends Record<string, any> = {}> = AggregationFn<TData> | MRT_AggregationOption;
|
|
493
508
|
declare type MRT_SortingOption = LiteralUnion<string & keyof typeof MRT_SortingFns>;
|
|
494
509
|
declare type MRT_SortingFn<TData extends Record<string, any> = {}> = SortingFn<TData> | MRT_SortingOption;
|
|
495
510
|
declare type MRT_FilterOption = LiteralUnion<string & keyof typeof MRT_FilterFns>;
|
|
@@ -721,7 +736,7 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
721
736
|
values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
|
|
722
737
|
}) => Promise<void> | void;
|
|
723
738
|
onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
724
|
-
|
|
739
|
+
onColumnFilterFnsChange?: OnChangeFn<{
|
|
725
740
|
[key: string]: MRT_FilterOption;
|
|
726
741
|
}>;
|
|
727
742
|
onGlobalFilterFnChange?: OnChangeFn<MRT_FilterOption>;
|
|
@@ -859,4 +874,4 @@ interface Props<TData extends Record<string, any> = {}> {
|
|
|
859
874
|
}
|
|
860
875
|
declare const MRT_ToolbarInternalButtons: <TData extends Record<string, any> = {}>({ table, }: Props<TData>) => JSX.Element;
|
|
861
876
|
|
|
862
|
-
export { DensityState, MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FilterOptionMenu, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_InternalFilterOption, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TablePagination, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToolbarInternalButtons, MaterialReactTableProps, Virtualizer, MaterialReactTable as default };
|
|
877
|
+
export { DensityState, MRT_AggregationFn, MRT_AggregationOption, MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, MRT_FilterOptionMenu, MRT_FullScreenToggleButton, MRT_GlobalFilterTextField, MRT_Header, MRT_HeaderGroup, MRT_Icons, MRT_InternalFilterOption, MRT_Localization, MRT_Row, MRT_RowModel, MRT_ShowHideColumnsButton, MRT_SortingFn, MRT_SortingOption, MRT_TableInstance, MRT_TablePagination, MRT_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MRT_ToolbarInternalButtons, MaterialReactTableProps, Virtualizer, MaterialReactTable as default };
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2
|
|
2
|
+
"version": "1.3.0-beta.2",
|
|
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.",
|
|
@@ -47,17 +47,18 @@
|
|
|
47
47
|
"format": "prettier -w .",
|
|
48
48
|
"lint": "eslint .",
|
|
49
49
|
"size": "size-limit",
|
|
50
|
+
"dev": "start-storybook -p 6006",
|
|
50
51
|
"start": "start-storybook -p 6006",
|
|
51
52
|
"storybook": "start-storybook -p 6006"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@babel/core": "^7.19.
|
|
55
|
+
"@babel/core": "^7.19.6",
|
|
55
56
|
"@babel/preset-react": "^7.18.6",
|
|
56
57
|
"@emotion/react": "^11.10.4",
|
|
57
58
|
"@emotion/styled": "^11.10.4",
|
|
58
59
|
"@faker-js/faker": "^7.5.0",
|
|
59
60
|
"@mui/icons-material": "^5.10.6",
|
|
60
|
-
"@mui/material": "^5.10.
|
|
61
|
+
"@mui/material": "^5.10.10",
|
|
61
62
|
"@rollup/plugin-babel": "^5.3.1",
|
|
62
63
|
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
63
64
|
"@rollup/plugin-typescript": "^8.5.0",
|
|
@@ -74,10 +75,10 @@
|
|
|
74
75
|
"@storybook/react": "^6.5.12",
|
|
75
76
|
"@types/react": "^18.0.21",
|
|
76
77
|
"@types/react-dom": "^18.0.6",
|
|
77
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
78
|
-
"@typescript-eslint/parser": "^5.
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "^5.40.1",
|
|
79
|
+
"@typescript-eslint/parser": "^5.40.1",
|
|
79
80
|
"babel-loader": "^8.2.5",
|
|
80
|
-
"eslint": "^8.
|
|
81
|
+
"eslint": "^8.26.0",
|
|
81
82
|
"eslint-plugin-mui-path-imports": "^0.0.3",
|
|
82
83
|
"prettier": "^2.7.1",
|
|
83
84
|
"react": "^18.2.0",
|
|
@@ -101,8 +102,8 @@
|
|
|
101
102
|
"react": ">=17.0"
|
|
102
103
|
},
|
|
103
104
|
"dependencies": {
|
|
104
|
-
"@tanstack/match-sorter-utils": "8.
|
|
105
|
-
"@tanstack/react-table": "8.5.
|
|
105
|
+
"@tanstack/match-sorter-utils": "8.5.14",
|
|
106
|
+
"@tanstack/react-table": "8.5.17",
|
|
106
107
|
"react-virtual": "^2.10.4"
|
|
107
108
|
}
|
|
108
|
-
}
|
|
109
|
+
}
|
|
@@ -25,6 +25,7 @@ import type { TableRowProps } from '@mui/material/TableRow';
|
|
|
25
25
|
import type { TextFieldProps } from '@mui/material/TextField';
|
|
26
26
|
import type { ToolbarProps } from '@mui/material/Toolbar';
|
|
27
27
|
import type {
|
|
28
|
+
AggregationFn,
|
|
28
29
|
Cell,
|
|
29
30
|
Column,
|
|
30
31
|
ColumnDef,
|
|
@@ -244,7 +245,9 @@ export type MRT_TableState<TData extends Record<string, any> = {}> =
|
|
|
244
245
|
|
|
245
246
|
export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
246
247
|
ColumnDef<TData, unknown>,
|
|
248
|
+
| 'accessorKey'
|
|
247
249
|
| 'aggregatedCell'
|
|
250
|
+
| 'aggregationFn'
|
|
248
251
|
| 'cell'
|
|
249
252
|
| 'columns'
|
|
250
253
|
| 'filterFn'
|
|
@@ -346,6 +349,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
346
349
|
* @example accessorKey: 'name.firstName' //deep key dot notation
|
|
347
350
|
*/
|
|
348
351
|
accessorKey?: DeepKeys<TData>;
|
|
352
|
+
aggregationFn?: MRT_AggregationFn<TData> | Array<MRT_AggregationFn<TData>>;
|
|
349
353
|
/**
|
|
350
354
|
* Specify what type of column this is. Either `data`, `display`, or `group`. Defaults to `data`.
|
|
351
355
|
* Leave this blank if you are just creating a normal data column.
|
|
@@ -554,6 +558,12 @@ export type MRT_Cell<TData extends Record<string, any> = {}> = Omit<
|
|
|
554
558
|
row: MRT_Row<TData>;
|
|
555
559
|
};
|
|
556
560
|
|
|
561
|
+
export type MRT_AggregationOption = string & keyof typeof MRT_AggregationFns;
|
|
562
|
+
|
|
563
|
+
export type MRT_AggregationFn<TData extends Record<string, any> = {}> =
|
|
564
|
+
| AggregationFn<TData>
|
|
565
|
+
| MRT_AggregationOption;
|
|
566
|
+
|
|
557
567
|
export type MRT_SortingOption = LiteralUnion<
|
|
558
568
|
string & keyof typeof MRT_SortingFns
|
|
559
569
|
>;
|
|
@@ -928,7 +938,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
928
938
|
values: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
|
|
929
939
|
}) => Promise<void> | void;
|
|
930
940
|
onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
931
|
-
|
|
941
|
+
onColumnFilterFnsChange?: OnChangeFn<{ [key: string]: MRT_FilterOption }>;
|
|
932
942
|
onGlobalFilterFnChange?: OnChangeFn<MRT_FilterOption>;
|
|
933
943
|
onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
|
934
944
|
onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
@@ -133,7 +133,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
133
133
|
editingMode !== 'modal' &&
|
|
134
134
|
(editingMode === 'table' ||
|
|
135
135
|
editingRow?.id === row.id ||
|
|
136
|
-
editingCell?.id === cell.id)
|
|
136
|
+
editingCell?.id === cell.id) &&
|
|
137
|
+
!row.getIsGrouped();
|
|
137
138
|
|
|
138
139
|
const handleDoubleClick = (event: MouseEvent<HTMLTableCellElement>) => {
|
|
139
140
|
tableCellProps?.onDoubleClick?.(event);
|
package/src/column.utils.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ColumnOrderState,
|
|
3
|
+
GroupingState,
|
|
4
|
+
Row,
|
|
5
|
+
} from '@tanstack/react-table';
|
|
6
|
+
import { MRT_AggregationFns } from './aggregationFns';
|
|
2
7
|
import { MRT_FilterFns } from './filterFns';
|
|
3
8
|
import { MRT_SortingFns } from './sortingFns';
|
|
4
9
|
import { alpha, lighten } from '@mui/material/styles';
|
|
@@ -38,12 +43,15 @@ export const getAllLeafColumnDefs = <TData extends Record<string, any> = {}>(
|
|
|
38
43
|
};
|
|
39
44
|
|
|
40
45
|
export const prepareColumns = <TData extends Record<string, any> = {}>({
|
|
46
|
+
aggregationFns,
|
|
41
47
|
columnDefs,
|
|
42
48
|
columnFilterFns,
|
|
43
49
|
defaultDisplayColumn,
|
|
44
50
|
filterFns,
|
|
45
51
|
sortingFns,
|
|
46
52
|
}: {
|
|
53
|
+
aggregationFns: typeof MRT_AggregationFns &
|
|
54
|
+
MaterialReactTableProps<TData>['aggregationFns'];
|
|
47
55
|
columnDefs: MRT_ColumnDef<TData>[];
|
|
48
56
|
columnFilterFns: { [key: string]: MRT_FilterOption };
|
|
49
57
|
defaultDisplayColumn: Partial<MRT_ColumnDef<TData>>;
|
|
@@ -52,16 +60,21 @@ export const prepareColumns = <TData extends Record<string, any> = {}>({
|
|
|
52
60
|
MaterialReactTableProps<TData>['sortingFns'];
|
|
53
61
|
}): MRT_DefinedColumnDef<TData>[] =>
|
|
54
62
|
columnDefs.map((columnDef) => {
|
|
63
|
+
//assign columnId
|
|
55
64
|
if (!columnDef.id) columnDef.id = getColumnId(columnDef);
|
|
56
65
|
if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
|
|
57
66
|
console.error(
|
|
58
67
|
'Column definitions must have a valid `accessorKey` or `id` property',
|
|
59
68
|
);
|
|
60
69
|
}
|
|
70
|
+
|
|
71
|
+
//assign columnDefType
|
|
61
72
|
if (!columnDef.columnDefType) columnDef.columnDefType = 'data';
|
|
62
73
|
if (columnDef.columns?.length) {
|
|
63
74
|
columnDef.columnDefType = 'group';
|
|
75
|
+
//recursively prepare columns if this is a group column
|
|
64
76
|
columnDef.columns = prepareColumns({
|
|
77
|
+
aggregationFns,
|
|
65
78
|
columnDefs: columnDef.columns,
|
|
66
79
|
columnFilterFns,
|
|
67
80
|
defaultDisplayColumn,
|
|
@@ -69,12 +82,28 @@ export const prepareColumns = <TData extends Record<string, any> = {}>({
|
|
|
69
82
|
sortingFns,
|
|
70
83
|
});
|
|
71
84
|
} else if (columnDef.columnDefType === 'data') {
|
|
85
|
+
//assign aggregationFns if multiple aggregationFns are provided
|
|
86
|
+
if (Array.isArray(columnDef.aggregationFn)) {
|
|
87
|
+
const aggFns = columnDef.aggregationFn as string[];
|
|
88
|
+
columnDef.aggregationFn = (
|
|
89
|
+
columnId: string,
|
|
90
|
+
leafRows: Row<TData>[],
|
|
91
|
+
childRows: Row<TData>[],
|
|
92
|
+
) =>
|
|
93
|
+
aggFns.map((fn) =>
|
|
94
|
+
aggregationFns[fn]?.(columnId, leafRows, childRows),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//assign filterFns
|
|
72
99
|
if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
|
|
73
100
|
columnDef.filterFn =
|
|
74
101
|
filterFns[columnFilterFns[columnDef.id]] ?? filterFns.fuzzy;
|
|
75
102
|
(columnDef as MRT_DefinedColumnDef)._filterFn =
|
|
76
103
|
columnFilterFns[columnDef.id];
|
|
77
104
|
}
|
|
105
|
+
|
|
106
|
+
//assign sortingFns
|
|
78
107
|
if (Object.keys(sortingFns).includes(columnDef.sortingFn as string)) {
|
|
79
108
|
// @ts-ignore
|
|
80
109
|
columnDef.sortingFn = sortingFns[columnDef.sortingFn];
|
|
@@ -209,6 +209,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
209
209
|
const columnDefs = useMemo(
|
|
210
210
|
() =>
|
|
211
211
|
prepareColumns({
|
|
212
|
+
aggregationFns: props.aggregationFns as any,
|
|
212
213
|
columnDefs: [...displayColumns, ...props.columns],
|
|
213
214
|
columnFilterFns: props.state?.columnFilterFns ?? columnFilterFns,
|
|
214
215
|
defaultDisplayColumn: props.defaultDisplayColumn ?? {},
|
|
@@ -296,7 +297,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
296
297
|
tablePaperRef,
|
|
297
298
|
topToolbarRef,
|
|
298
299
|
},
|
|
299
|
-
setColumnFilterFns: props.
|
|
300
|
+
setColumnFilterFns: props.onColumnFilterFnsChange ?? setColumnFilterFns,
|
|
300
301
|
setDensity: props.onDensityChange ?? setDensity,
|
|
301
302
|
setDraggingColumn: props.onDraggingColumnChange ?? setDraggingColumn,
|
|
302
303
|
setDraggingRow: props.onDraggingRowChange ?? setDraggingRow,
|