material-react-table 0.14.6 → 0.16.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/MaterialReactTable.d.ts +5 -3
- package/dist/material-react-table.cjs.development.js +62 -26
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +62 -26
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/sortingFns.d.ts +1 -0
- package/dist/table/MRT_TableRoot.d.ts +1 -0
- package/dist/utils.d.ts +3 -3
- package/package.json +7 -7
- package/src/MaterialReactTable.tsx +8 -1
- package/src/body/MRT_TableBody.tsx +35 -7
- package/src/buttons/MRT_ExpandAllButton.tsx +25 -19
- package/src/buttons/MRT_ExpandButton.tsx +25 -23
- package/src/sortingFns.ts +4 -0
package/dist/sortingFns.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { ColumnDef, ColumnOrderState, Table, Updater } from '@tanstack/react-tab
|
|
|
2
2
|
import { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
3
3
|
export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
|
|
4
4
|
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
5
|
-
[key: string]: import("@tanstack/
|
|
5
|
+
[key: string]: import("@tanstack/table-core").FilterFnOption<import("@tanstack/table-core").TableGenerics>;
|
|
6
6
|
}) => ColumnDef<D>;
|
|
7
7
|
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
8
|
-
[key: string]: import("@tanstack/
|
|
8
|
+
[key: string]: import("@tanstack/table-core").FilterFnOption<import("@tanstack/table-core").TableGenerics>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnFilterChangeMode" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
|
13
13
|
export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.16.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
}
|
|
57
57
|
],
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@babel/core": "^7.18.
|
|
59
|
+
"@babel/core": "^7.18.6",
|
|
60
60
|
"@emotion/react": "^11.9.3",
|
|
61
61
|
"@emotion/styled": "^11.9.3",
|
|
62
62
|
"@faker-js/faker": "^7.3.0",
|
|
63
63
|
"@mui/icons-material": "^5.8.4",
|
|
64
|
-
"@mui/material": "^5.8.
|
|
64
|
+
"@mui/material": "^5.8.6",
|
|
65
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
66
66
|
"@storybook/addon-a11y": "^6.5.9",
|
|
67
67
|
"@storybook/addon-actions": "^6.5.9",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
78
78
|
"husky": "^8.0.1",
|
|
79
79
|
"prettier": "^2.7.1",
|
|
80
|
-
"react": "^
|
|
81
|
-
"react-dom": "^
|
|
80
|
+
"react": "^18.2.0",
|
|
81
|
+
"react-dom": "^18.2.0",
|
|
82
82
|
"react-is": "^18.2.0",
|
|
83
83
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
84
84
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
"react": ">=16.8"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@tanstack/match-sorter-utils": "
|
|
101
|
-
"@tanstack/react-table": "
|
|
100
|
+
"@tanstack/match-sorter-utils": "8.0.13",
|
|
101
|
+
"@tanstack/react-table": "8.0.13",
|
|
102
102
|
"react-dnd": "^16.0.1",
|
|
103
103
|
"react-dnd-html5-backend": "^16.0.1",
|
|
104
104
|
"react-virtual": "^2.10.4"
|
|
@@ -88,6 +88,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
88
88
|
| 'getFlatHeaders'
|
|
89
89
|
| 'getLeftLeafColumns'
|
|
90
90
|
| 'getPaginationRowModel'
|
|
91
|
+
| 'getPreFilteredRowModel'
|
|
91
92
|
| 'getPrePaginationRowModel'
|
|
92
93
|
| 'getRightLeafColumns'
|
|
93
94
|
| 'getRowModel'
|
|
@@ -104,6 +105,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
104
105
|
getFlatHeaders: () => MRT_Header<D>[];
|
|
105
106
|
getLeftLeafColumns: () => MRT_Column<D>[];
|
|
106
107
|
getPaginationRowModel: () => MRT_RowModel<D>;
|
|
108
|
+
getPreFilteredRowModel: () => MRT_RowModel<D>;
|
|
107
109
|
getPrePaginationRowModel: () => MRT_RowModel<D>;
|
|
108
110
|
getRightLeafColumns: () => MRT_Column<D>[];
|
|
109
111
|
getRowModel: () => MRT_RowModel<D>;
|
|
@@ -203,9 +205,9 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
203
205
|
columns?: MRT_ColumnDef<D>[];
|
|
204
206
|
enableClickToCopy?: boolean;
|
|
205
207
|
enableColumnActions?: boolean;
|
|
208
|
+
enableColumnFilterChangeMode?: boolean;
|
|
206
209
|
enableColumnOrdering?: boolean;
|
|
207
210
|
enableEditing?: boolean;
|
|
208
|
-
enableColumnFilterChangeMode?: boolean;
|
|
209
211
|
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[] | null;
|
|
210
212
|
filterFn?: MRT_FilterFn;
|
|
211
213
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
@@ -395,6 +397,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
395
397
|
enableExpandAll?: boolean;
|
|
396
398
|
enableFullScreenToggle?: boolean;
|
|
397
399
|
enableGlobalFilterChangeMode?: boolean;
|
|
400
|
+
enableGlobalFilterRankedResults?: boolean;
|
|
398
401
|
enablePagination?: boolean;
|
|
399
402
|
enablePersistentState?: boolean;
|
|
400
403
|
enableRowActions?: boolean;
|
|
@@ -848,9 +851,11 @@ export default <D extends Record<string, any> = {}>({
|
|
|
848
851
|
enableFullScreenToggle = true,
|
|
849
852
|
enableGlobalFilter = true,
|
|
850
853
|
enableGlobalFilterChangeMode = true,
|
|
854
|
+
enableGlobalFilterRankedResults = true,
|
|
851
855
|
enableGrouping = false,
|
|
852
856
|
enableHiding = true,
|
|
853
857
|
enableMultiRowSelection = true,
|
|
858
|
+
enableMultiSort = true,
|
|
854
859
|
enablePagination = true,
|
|
855
860
|
enablePinning = false,
|
|
856
861
|
enableRowSelection = false,
|
|
@@ -889,9 +894,11 @@ export default <D extends Record<string, any> = {}>({
|
|
|
889
894
|
enableFullScreenToggle={enableFullScreenToggle}
|
|
890
895
|
enableGlobalFilter={enableGlobalFilter}
|
|
891
896
|
enableGlobalFilterChangeMode={enableGlobalFilterChangeMode}
|
|
897
|
+
enableGlobalFilterRankedResults={enableGlobalFilterRankedResults}
|
|
892
898
|
enableGrouping={enableGrouping}
|
|
893
899
|
enableHiding={enableHiding}
|
|
894
900
|
enableMultiRowSelection={enableMultiRowSelection}
|
|
901
|
+
enableMultiSort={enableMultiSort}
|
|
895
902
|
enablePagination={enablePagination}
|
|
896
903
|
enablePinning={enablePinning}
|
|
897
904
|
enableRowSelection={enableRowSelection}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { FC, RefObject } from 'react';
|
|
1
|
+
import React, { FC, RefObject, useMemo } from 'react';
|
|
2
2
|
import { useVirtual } from 'react-virtual';
|
|
3
3
|
import { TableBody } from '@mui/material';
|
|
4
4
|
import { MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
5
5
|
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
6
|
+
import { rankGlobalFuzzy } from '../sortingFns';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
instance: MRT_TableInstance;
|
|
@@ -11,10 +12,11 @@ interface Props {
|
|
|
11
12
|
|
|
12
13
|
export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
|
|
13
14
|
const {
|
|
14
|
-
|
|
15
|
+
getRowModel,
|
|
15
16
|
getPrePaginationRowModel,
|
|
16
17
|
getState,
|
|
17
18
|
options: {
|
|
19
|
+
enableGlobalFilterRankedResults,
|
|
18
20
|
enablePagination,
|
|
19
21
|
enableRowVirtualization,
|
|
20
22
|
muiTableBodyProps,
|
|
@@ -22,20 +24,46 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
|
|
|
22
24
|
},
|
|
23
25
|
} = instance;
|
|
24
26
|
|
|
25
|
-
const { density } = getState();
|
|
27
|
+
const { density, globalFilter, pagination, sorting } = getState();
|
|
26
28
|
|
|
27
29
|
const tableBodyProps =
|
|
28
30
|
muiTableBodyProps instanceof Function
|
|
29
31
|
? muiTableBodyProps({ instance })
|
|
30
32
|
: muiTableBodyProps;
|
|
31
33
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const getIsSomeColumnsSorted = () => {
|
|
35
|
+
return Object.values(sorting).some(Boolean);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const rows = useMemo(() => {
|
|
39
|
+
if (
|
|
40
|
+
enableGlobalFilterRankedResults &&
|
|
41
|
+
globalFilter &&
|
|
42
|
+
!getIsSomeColumnsSorted()
|
|
43
|
+
) {
|
|
44
|
+
const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
|
|
45
|
+
rankGlobalFuzzy(a, b),
|
|
46
|
+
);
|
|
47
|
+
if (enablePagination) {
|
|
48
|
+
return rankedRows.slice(0, pagination.pageSize);
|
|
49
|
+
}
|
|
50
|
+
return rankedRows;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return enablePagination
|
|
54
|
+
? getRowModel().rows
|
|
55
|
+
: getPrePaginationRowModel().rows;
|
|
56
|
+
}, [
|
|
57
|
+
enableGlobalFilterRankedResults,
|
|
58
|
+
(enableGlobalFilterRankedResults && globalFilter) || !enablePagination
|
|
59
|
+
? getPrePaginationRowModel().rows
|
|
60
|
+
: getRowModel().rows,
|
|
61
|
+
globalFilter,
|
|
62
|
+
]);
|
|
35
63
|
|
|
36
64
|
const rowVirtualizer = enableRowVirtualization
|
|
37
65
|
? useVirtual({
|
|
38
|
-
overscan: density === 'compact' ?
|
|
66
|
+
overscan: density === 'compact' ? 20 : 10,
|
|
39
67
|
size: rows.length,
|
|
40
68
|
parentRef: tableContainerRef,
|
|
41
69
|
...virtualizerProps,
|
|
@@ -35,26 +35,32 @@ export const MRT_ExpandAllButton: FC<Props> = ({ instance }) => {
|
|
|
35
35
|
enterNextDelay={1000}
|
|
36
36
|
title={localization.expandAll}
|
|
37
37
|
>
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
>
|
|
49
|
-
<KeyboardDoubleArrowDownIcon
|
|
50
|
-
style={{
|
|
51
|
-
transform: `rotate(${
|
|
52
|
-
getIsAllRowsExpanded() ? -180 : getIsSomeRowsExpanded() ? -90 : 0
|
|
53
|
-
}deg)`,
|
|
54
|
-
transition: 'transform 0.2s',
|
|
38
|
+
<span>
|
|
39
|
+
<IconButton
|
|
40
|
+
aria-label={localization.expandAll}
|
|
41
|
+
disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
|
|
42
|
+
onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
|
|
43
|
+
{...iconButtonProps}
|
|
44
|
+
sx={{
|
|
45
|
+
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
46
|
+
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
47
|
+
...iconButtonProps?.sx,
|
|
55
48
|
}}
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
>
|
|
50
|
+
<KeyboardDoubleArrowDownIcon
|
|
51
|
+
style={{
|
|
52
|
+
transform: `rotate(${
|
|
53
|
+
getIsAllRowsExpanded()
|
|
54
|
+
? -180
|
|
55
|
+
: getIsSomeRowsExpanded()
|
|
56
|
+
? -90
|
|
57
|
+
: 0
|
|
58
|
+
}deg)`,
|
|
59
|
+
transition: 'transform 0.2s',
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
</IconButton>
|
|
63
|
+
</span>
|
|
58
64
|
</Tooltip>
|
|
59
65
|
);
|
|
60
66
|
};
|
|
@@ -38,30 +38,32 @@ export const MRT_ExpandButton: FC<Props> = ({ row, instance }) => {
|
|
|
38
38
|
enterNextDelay={1000}
|
|
39
39
|
title={localization.expand}
|
|
40
40
|
>
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
<ExpandMoreIcon
|
|
53
|
-
style={{
|
|
54
|
-
transform: `rotate(${
|
|
55
|
-
!row.getCanExpand() && !renderDetailPanel
|
|
56
|
-
? -90
|
|
57
|
-
: row.getIsExpanded()
|
|
58
|
-
? -180
|
|
59
|
-
: 0
|
|
60
|
-
}deg)`,
|
|
61
|
-
transition: 'transform 0.2s',
|
|
41
|
+
<span>
|
|
42
|
+
<IconButton
|
|
43
|
+
aria-label={localization.expand}
|
|
44
|
+
disabled={!row.getCanExpand() && !renderDetailPanel}
|
|
45
|
+
onClick={handleToggleExpand}
|
|
46
|
+
{...iconButtonProps}
|
|
47
|
+
sx={{
|
|
48
|
+
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
49
|
+
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
50
|
+
...iconButtonProps?.sx,
|
|
62
51
|
}}
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
>
|
|
53
|
+
<ExpandMoreIcon
|
|
54
|
+
style={{
|
|
55
|
+
transform: `rotate(${
|
|
56
|
+
!row.getCanExpand() && !renderDetailPanel
|
|
57
|
+
? -90
|
|
58
|
+
: row.getIsExpanded()
|
|
59
|
+
? -180
|
|
60
|
+
: 0
|
|
61
|
+
}deg)`,
|
|
62
|
+
transition: 'transform 0.2s',
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
</IconButton>
|
|
66
|
+
</span>
|
|
65
67
|
</Tooltip>
|
|
66
68
|
);
|
|
67
69
|
};
|
package/src/sortingFns.ts
CHANGED
|
@@ -19,3 +19,7 @@ const fuzzy = (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => {
|
|
|
19
19
|
export const MRT_SortingFns = {
|
|
20
20
|
fuzzy,
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
export const rankGlobalFuzzy = (rowA: MRT_Row, rowB: MRT_Row) =>
|
|
24
|
+
Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
|
|
25
|
+
Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
|