material-react-table 0.26.6 → 0.29.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/README.md +7 -8
- package/dist/MaterialReactTable.d.ts +11 -7
- package/dist/column.utils.d.ts +1 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/localization.d.ts +9 -0
- package/dist/material-react-table.cjs.development.js +214 -146
- 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 +215 -147
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_FilterOptionMenu.d.ts +7 -0
- package/package.json +5 -5
- package/src/MaterialReactTable.tsx +15 -7
- package/src/body/MRT_TableBody.tsx +12 -12
- package/src/body/MRT_TableBodyCell.tsx +7 -1
- package/src/buttons/MRT_ExpandAllButton.tsx +1 -0
- package/src/column.utils.ts +13 -0
- package/src/head/MRT_TableHeadCell.tsx +2 -4
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +3 -1
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +8 -3
- package/src/inputs/MRT_FilterRangeFields.tsx +2 -2
- package/src/inputs/MRT_FilterTextField.tsx +124 -84
- package/src/inputs/MRT_SelectCheckbox.tsx +3 -3
- package/src/localization.ts +18 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
- package/src/menus/MRT_FilterOptionMenu.tsx +103 -101
- package/src/table/MRT_TableRoot.tsx +2 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
3
|
+
import { MRT_Localization } from '../localization';
|
|
4
|
+
export declare const internalFilterOptions: (localization: MRT_Localization) => {
|
|
5
|
+
option: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
label: string;
|
|
8
|
+
divider: boolean;
|
|
9
|
+
}[];
|
|
3
10
|
interface Props {
|
|
4
11
|
anchorEl: HTMLElement | null;
|
|
5
12
|
header?: MRT_Header;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.29.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
|
-
"description": "A fully featured Material UI implementation of TanStack React Table
|
|
5
|
+
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
|
|
6
6
|
"author": "Kevin Vandy",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"react-table",
|
|
@@ -57,12 +57,12 @@
|
|
|
57
57
|
}
|
|
58
58
|
],
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@babel/core": "^7.18.
|
|
60
|
+
"@babel/core": "^7.18.9",
|
|
61
61
|
"@emotion/react": "^11.9.3",
|
|
62
62
|
"@emotion/styled": "^11.9.3",
|
|
63
63
|
"@faker-js/faker": "^7.3.0",
|
|
64
64
|
"@mui/icons-material": "^5.8.4",
|
|
65
|
-
"@mui/material": "^5.9.
|
|
65
|
+
"@mui/material": "^5.9.2",
|
|
66
66
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
67
67
|
"@storybook/addon-a11y": "^6.5.9",
|
|
68
68
|
"@storybook/addon-actions": "^6.5.9",
|
|
@@ -101,6 +101,6 @@
|
|
|
101
101
|
"dependencies": {
|
|
102
102
|
"@tanstack/match-sorter-utils": "8.1.1",
|
|
103
103
|
"@tanstack/react-table": "8.2.6",
|
|
104
|
-
"react-virtual": "^
|
|
104
|
+
"@tanstack/react-virtual": "^3.0.0-beta.13"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -40,7 +40,7 @@ import type {
|
|
|
40
40
|
TableOptions,
|
|
41
41
|
TableState,
|
|
42
42
|
} from '@tanstack/react-table';
|
|
43
|
-
import type {
|
|
43
|
+
import type { VirtualizerOptions } from '@tanstack/react-virtual';
|
|
44
44
|
import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
|
|
45
45
|
import { MRT_Default_Icons, MRT_Icons } from './icons';
|
|
46
46
|
import { MRT_TableRoot } from './table/MRT_TableRoot';
|
|
@@ -134,7 +134,7 @@ export type MRT_TableState<TData extends Record<string, any> = {}> =
|
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
137
|
-
ColumnDef<TData>,
|
|
137
|
+
ColumnDef<TData, unknown>,
|
|
138
138
|
| 'accessorFn'
|
|
139
139
|
| 'accessorKey'
|
|
140
140
|
| 'aggregatedCell'
|
|
@@ -215,6 +215,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
215
215
|
* @example columnDefType: 'display'
|
|
216
216
|
*/
|
|
217
217
|
columnDefType?: 'data' | 'display' | 'group';
|
|
218
|
+
columnFilterModeOptions?: MRT_FilterOption[] | null;
|
|
218
219
|
columns?: MRT_ColumnDef<TData>[];
|
|
219
220
|
enableClickToCopy?: boolean;
|
|
220
221
|
enableColumnActions?: boolean;
|
|
@@ -222,9 +223,9 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
222
223
|
enableColumnFilterChangeMode?: boolean;
|
|
223
224
|
enableColumnOrdering?: boolean;
|
|
224
225
|
enableEditing?: boolean;
|
|
225
|
-
enabledColumnFilterOptions?: MRT_FilterOption[] | null;
|
|
226
226
|
filterFn?: MRT_FilterFn<TData>;
|
|
227
227
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
228
|
+
filterVariant?: 'text' | 'select' | 'multiSelect' | 'range';
|
|
228
229
|
/**
|
|
229
230
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
|
230
231
|
*/
|
|
@@ -302,9 +303,11 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
302
303
|
| (({
|
|
303
304
|
table,
|
|
304
305
|
column,
|
|
306
|
+
rangeFilterIndex,
|
|
305
307
|
}: {
|
|
306
308
|
table: MRT_TableInstance<TData>;
|
|
307
309
|
column: MRT_Column<TData>;
|
|
310
|
+
rangeFilterIndex?: number;
|
|
308
311
|
}) => TextFieldProps);
|
|
309
312
|
muiTableHeadCellProps?:
|
|
310
313
|
| TableCellProps
|
|
@@ -341,6 +344,7 @@ export type MRT_DefinedColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
|
341
344
|
'id'
|
|
342
345
|
> & {
|
|
343
346
|
id: string;
|
|
347
|
+
_filterFn: MRT_FilterOption;
|
|
344
348
|
};
|
|
345
349
|
|
|
346
350
|
export type MRT_Column<TData extends Record<string, any> = {}> = Omit<
|
|
@@ -422,6 +426,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
422
426
|
displayColumnDefOptions?: Partial<{
|
|
423
427
|
[key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
|
|
424
428
|
}>;
|
|
429
|
+
columnFilterModeOptions?: (MRT_FilterOption | string)[] | null;
|
|
425
430
|
columns: MRT_ColumnDef<TData>[];
|
|
426
431
|
data: TData[];
|
|
427
432
|
editingMode?: 'table' | 'row' | 'cell';
|
|
@@ -449,7 +454,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
449
454
|
enableToolbarBottom?: boolean;
|
|
450
455
|
enableToolbarInternalActions?: boolean;
|
|
451
456
|
enableToolbarTop?: boolean;
|
|
452
|
-
enabledColumnFilterOptions?: (MRT_FilterOption | string)[] | null;
|
|
453
457
|
enabledGlobalFilterOptions?: (MRT_FilterOption | string)[] | null;
|
|
454
458
|
expandRowsFn?: (dataRow: TData) => TData[];
|
|
455
459
|
icons?: Partial<MRT_Icons>;
|
|
@@ -607,9 +611,11 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
607
611
|
| (({
|
|
608
612
|
table,
|
|
609
613
|
column,
|
|
614
|
+
rangeFilterIndex,
|
|
610
615
|
}: {
|
|
611
616
|
table: MRT_TableInstance<TData>;
|
|
612
617
|
column: MRT_Column<TData>;
|
|
618
|
+
rangeFilterIndex?: number;
|
|
613
619
|
}) => TextFieldProps);
|
|
614
620
|
muiTableHeadCellProps?:
|
|
615
621
|
| TableCellProps
|
|
@@ -779,7 +785,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
779
785
|
selectAllMode?: 'all' | 'page';
|
|
780
786
|
state?: Partial<MRT_TableState<TData>>;
|
|
781
787
|
tableId?: string;
|
|
782
|
-
virtualizerProps?: Partial<
|
|
788
|
+
virtualizerProps?: Partial<
|
|
789
|
+
VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>
|
|
790
|
+
>;
|
|
783
791
|
};
|
|
784
792
|
|
|
785
793
|
export default <TData extends Record<string, any> = {}>({
|
|
@@ -788,7 +796,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
788
796
|
defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
|
|
789
797
|
editingMode = 'row',
|
|
790
798
|
enableColumnActions = true,
|
|
791
|
-
enableColumnFilterChangeMode =
|
|
799
|
+
enableColumnFilterChangeMode = false,
|
|
792
800
|
enableColumnFilters = true,
|
|
793
801
|
enableColumnOrdering = false,
|
|
794
802
|
enableColumnResizing = false,
|
|
@@ -797,7 +805,7 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
797
805
|
enableFilters = true,
|
|
798
806
|
enableFullScreenToggle = true,
|
|
799
807
|
enableGlobalFilter = true,
|
|
800
|
-
enableGlobalFilterChangeMode =
|
|
808
|
+
enableGlobalFilterChangeMode = false,
|
|
801
809
|
enableGlobalFilterRankedResults = true,
|
|
802
810
|
enableGrouping = false,
|
|
803
811
|
enableHiding = true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC, RefObject, useMemo } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
|
|
3
3
|
import { TableBody } from '@mui/material';
|
|
4
4
|
import { MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
5
5
|
import { rankGlobalFuzzy } from '../sortingFns';
|
|
@@ -60,28 +60,27 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
60
60
|
globalFilter,
|
|
61
61
|
]);
|
|
62
62
|
|
|
63
|
-
const rowVirtualizer = enableRowVirtualization
|
|
64
|
-
?
|
|
65
|
-
|
|
63
|
+
const rowVirtualizer: Virtualizer = enableRowVirtualization
|
|
64
|
+
? useVirtualizer({
|
|
65
|
+
estimateSize: () => (density === 'compact' ? 25 : 50),
|
|
66
66
|
overscan: density === 'compact' ? 30 : 10,
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
getScrollElement: () => tableContainerRef.current as HTMLDivElement,
|
|
68
|
+
count: rows.length,
|
|
69
69
|
...virtualizerProps,
|
|
70
70
|
})
|
|
71
71
|
: ({} as any);
|
|
72
72
|
|
|
73
73
|
const virtualRows = enableRowVirtualization
|
|
74
|
-
? rowVirtualizer.
|
|
74
|
+
? rowVirtualizer.getVirtualItems()
|
|
75
75
|
: [];
|
|
76
76
|
|
|
77
77
|
let paddingTop = 0;
|
|
78
78
|
let paddingBottom = 0;
|
|
79
79
|
if (enableRowVirtualization) {
|
|
80
|
-
paddingTop = virtualRows.length
|
|
81
|
-
paddingBottom =
|
|
82
|
-
virtualRows.length
|
|
83
|
-
|
|
84
|
-
: 0;
|
|
80
|
+
paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
|
|
81
|
+
paddingBottom = !!virtualRows.length
|
|
82
|
+
? rowVirtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
|
|
83
|
+
: 0;
|
|
85
84
|
}
|
|
86
85
|
|
|
87
86
|
return (
|
|
@@ -91,6 +90,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
91
90
|
<td style={{ height: `${paddingTop}px` }} />
|
|
92
91
|
</tr>
|
|
93
92
|
)}
|
|
93
|
+
{/* @ts-ignore */}
|
|
94
94
|
{(enableRowVirtualization ? virtualRows : rows).map(
|
|
95
95
|
(rowOrVirtualRow: any, rowIndex: number) => {
|
|
96
96
|
const row = enableRowVirtualization
|
|
@@ -35,6 +35,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
35
35
|
enableClickToCopy,
|
|
36
36
|
enableColumnOrdering,
|
|
37
37
|
enableEditing,
|
|
38
|
+
enablePagination,
|
|
38
39
|
enableRowNumbers,
|
|
39
40
|
muiTableBodyCellProps,
|
|
40
41
|
muiTableBodyCellSkeletonProps,
|
|
@@ -147,7 +148,12 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
147
148
|
borderLeft: draggingBorder,
|
|
148
149
|
borderRight: draggingBorder,
|
|
149
150
|
borderBottom:
|
|
150
|
-
row.index ===
|
|
151
|
+
row.index ===
|
|
152
|
+
(enablePagination
|
|
153
|
+
? table.getRowModel()
|
|
154
|
+
: table.getPrePaginationRowModel()
|
|
155
|
+
).rows.length -
|
|
156
|
+
1
|
|
151
157
|
? draggingBorder
|
|
152
158
|
: undefined,
|
|
153
159
|
}
|
|
@@ -43,6 +43,7 @@ export const MRT_ExpandAllButton: FC<Props> = ({ table }) => {
|
|
|
43
43
|
sx={{
|
|
44
44
|
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
45
45
|
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
46
|
+
mt: density !== 'compact' ? '-0.25rem' : undefined,
|
|
46
47
|
...iconButtonProps?.sx,
|
|
47
48
|
}}
|
|
48
49
|
>
|
package/src/column.utils.ts
CHANGED
|
@@ -52,6 +52,8 @@ export const prepareColumns = <TData extends Record<string, any> = {}>(
|
|
|
52
52
|
if (Object.keys(MRT_FilterFns).includes(currentFilterFns[columnDef.id])) {
|
|
53
53
|
columnDef.filterFn =
|
|
54
54
|
MRT_FilterFns[currentFilterFns[columnDef.id]] ?? MRT_FilterFns.fuzzy;
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
columnDef._filterFn = currentFilterFns[columnDef.id];
|
|
55
57
|
}
|
|
56
58
|
if (Object.keys(MRT_SortingFns).includes(columnDef.sortingFn as string)) {
|
|
57
59
|
// @ts-ignore
|
|
@@ -123,3 +125,14 @@ export const getDefaultColumnOrderIds = <
|
|
|
123
125
|
),
|
|
124
126
|
...getTrailingDisplayColumnIds(props),
|
|
125
127
|
].filter(Boolean) as string[];
|
|
128
|
+
|
|
129
|
+
export const getDefaultColumnFilterFn = <
|
|
130
|
+
TData extends Record<string, any> = {},
|
|
131
|
+
>(
|
|
132
|
+
columnDef: MRT_ColumnDef<TData>,
|
|
133
|
+
): MRT_FilterOption => {
|
|
134
|
+
if (columnDef.filterVariant === 'multiSelect') return 'arrIncludesSome';
|
|
135
|
+
if (columnDef.filterVariant === 'select') return 'equals';
|
|
136
|
+
if (columnDef.filterVariant === 'range') return 'betweenInclusive';
|
|
137
|
+
return 'fuzzy';
|
|
138
|
+
};
|
|
@@ -128,12 +128,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
128
128
|
: 1,
|
|
129
129
|
p:
|
|
130
130
|
density === 'compact'
|
|
131
|
-
?
|
|
132
|
-
? '0 0.5rem'
|
|
133
|
-
: '0.5rem'
|
|
131
|
+
? '0.5rem'
|
|
134
132
|
: density === 'comfortable'
|
|
135
133
|
? columnDefType === 'display'
|
|
136
|
-
? '0.
|
|
134
|
+
? '0.75rem'
|
|
137
135
|
: '1rem'
|
|
138
136
|
: columnDefType === 'display'
|
|
139
137
|
? '1rem 1.25rem'
|
|
@@ -19,7 +19,9 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
|
|
22
|
-
{
|
|
22
|
+
{['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
23
|
+
currentFilterFns[column.id],
|
|
24
|
+
) ? (
|
|
23
25
|
<MRT_FilterRangeFields header={header} table={table} />
|
|
24
26
|
) : (
|
|
25
27
|
<MRT_FilterTextField header={header} table={table} />
|
|
@@ -19,6 +19,11 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
19
19
|
const { column } = header;
|
|
20
20
|
const { columnDef } = column;
|
|
21
21
|
|
|
22
|
+
const isRangeFilter = [
|
|
23
|
+
'between',
|
|
24
|
+
'betweenInclusive',
|
|
25
|
+
'inNumberRange',
|
|
26
|
+
].includes(columnDef._filterFn);
|
|
22
27
|
const currentFilterOption = currentFilterFns?.[header.id];
|
|
23
28
|
const filterTooltip = localization.filteringByColumn
|
|
24
29
|
.replace('{column}', String(columnDef.header))
|
|
@@ -37,7 +42,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
37
42
|
`"${
|
|
38
43
|
Array.isArray(column.getFilterValue())
|
|
39
44
|
? (column.getFilterValue() as [string, string]).join(
|
|
40
|
-
`" ${localization.and} "`,
|
|
45
|
+
`" ${isRangeFilter ? localization.and : localization.or} "`,
|
|
41
46
|
)
|
|
42
47
|
: (column.getFilterValue() as string)
|
|
43
48
|
}"`,
|
|
@@ -48,8 +53,8 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
48
53
|
<Grow
|
|
49
54
|
unmountOnExit
|
|
50
55
|
in={
|
|
51
|
-
(!!column.getFilterValue() &&
|
|
52
|
-
(
|
|
56
|
+
(!!column.getFilterValue() && isRangeFilter) ||
|
|
57
|
+
(!isRangeFilter && // @ts-ignore
|
|
53
58
|
(!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
|
|
54
59
|
}
|
|
55
60
|
>
|
|
@@ -11,8 +11,8 @@ interface Props {
|
|
|
11
11
|
export const MRT_FilterRangeFields: FC<Props> = ({ header, table }) => {
|
|
12
12
|
return (
|
|
13
13
|
<Box sx={{ display: 'grid', gridTemplateColumns: '6fr 6fr', gap: '1rem' }}>
|
|
14
|
-
<MRT_FilterTextField header={header}
|
|
15
|
-
<MRT_FilterTextField header={header}
|
|
14
|
+
<MRT_FilterTextField header={header} rangeFilterIndex={0} table={table} />
|
|
15
|
+
<MRT_FilterTextField header={header} rangeFilterIndex={1} table={table} />
|
|
16
16
|
</Box>
|
|
17
17
|
);
|
|
18
18
|
};
|