material-react-table 1.8.1 → 1.8.3
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/index.js +37 -30
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +38 -23
- package/dist/cjs/types/body/MRT_TableBody.d.ts +4 -3
- package/dist/cjs/types/body/MRT_TableBodyCell.d.ts +3 -2
- package/dist/cjs/types/body/MRT_TableBodyRow.d.ts +5 -4
- package/dist/cjs/types/body/MRT_TableDetailPanel.d.ts +3 -2
- package/dist/cjs/types/column.utils.d.ts +17 -1
- package/dist/cjs/types/footer/MRT_TableFooter.d.ts +3 -2
- package/dist/cjs/types/footer/MRT_TableFooterRow.d.ts +3 -2
- package/dist/cjs/types/head/MRT_TableHead.d.ts +3 -2
- package/dist/cjs/types/head/MRT_TableHeadRow.d.ts +3 -2
- package/dist/cjs/types/sortingFns.d.ts +117 -1
- package/dist/esm/material-react-table.esm.js +37 -30
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +38 -23
- package/dist/esm/types/body/MRT_TableBody.d.ts +4 -3
- package/dist/esm/types/body/MRT_TableBodyCell.d.ts +3 -2
- package/dist/esm/types/body/MRT_TableBodyRow.d.ts +5 -4
- package/dist/esm/types/body/MRT_TableDetailPanel.d.ts +3 -2
- package/dist/esm/types/column.utils.d.ts +17 -1
- package/dist/esm/types/footer/MRT_TableFooter.d.ts +3 -2
- package/dist/esm/types/footer/MRT_TableFooterRow.d.ts +3 -2
- package/dist/esm/types/head/MRT_TableHead.d.ts +3 -2
- package/dist/esm/types/head/MRT_TableHeadRow.d.ts +3 -2
- package/dist/esm/types/sortingFns.d.ts +117 -1
- package/dist/index.d.ts +39 -24
- package/package.json +15 -15
- package/src/MaterialReactTable.tsx +655 -624
- package/src/body/MRT_TableBody.tsx +10 -11
- package/src/body/MRT_TableBodyCell.tsx +3 -2
- package/src/body/MRT_TableBodyRow.tsx +7 -14
- package/src/body/MRT_TableDetailPanel.tsx +3 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +1 -1
- package/src/footer/MRT_TableFooter.tsx +3 -2
- package/src/footer/MRT_TableFooterRow.tsx +3 -7
- package/src/head/MRT_TableHead.tsx +3 -2
- package/src/head/MRT_TableHeadRow.tsx +3 -7
- package/src/inputs/MRT_EditCellTextField.tsx +28 -27
- package/src/inputs/MRT_FilterTextField.tsx +36 -35
- package/src/menus/MRT_FilterOptionMenu.tsx +8 -3
- package/src/table/MRT_Table.tsx +4 -3
- package/src/table/MRT_TableRoot.tsx +6 -0
@@ -1,20 +1,19 @@
|
|
1
1
|
import React, { memo, useMemo } from 'react';
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
useVirtualizer,
|
4
|
+
VirtualItem,
|
5
|
+
Virtualizer,
|
6
|
+
} from '@tanstack/react-virtual';
|
3
7
|
import TableBody from '@mui/material/TableBody';
|
4
8
|
import Typography from '@mui/material/Typography';
|
5
9
|
import { Memo_MRT_TableBodyRow, MRT_TableBodyRow } from './MRT_TableBodyRow';
|
6
10
|
import { rankGlobalFuzzy } from '../sortingFns';
|
7
|
-
import type {
|
8
|
-
MRT_Row,
|
9
|
-
MRT_TableInstance,
|
10
|
-
MRT_VirtualItem,
|
11
|
-
MRT_Virtualizer,
|
12
|
-
} from '..';
|
11
|
+
import type { MRT_Row, MRT_TableInstance } from '..';
|
13
12
|
|
14
13
|
interface Props {
|
15
|
-
columnVirtualizer?:
|
14
|
+
columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
16
15
|
table: MRT_TableInstance;
|
17
|
-
virtualColumns?:
|
16
|
+
virtualColumns?: VirtualItem[];
|
18
17
|
virtualPaddingLeft?: number;
|
19
18
|
virtualPaddingRight?: number;
|
20
19
|
}
|
@@ -117,7 +116,7 @@ export const MRT_TableBody = ({
|
|
117
116
|
]);
|
118
117
|
|
119
118
|
const rowVirtualizer:
|
120
|
-
|
|
119
|
+
| Virtualizer<HTMLDivElement, HTMLTableRowElement>
|
121
120
|
| undefined = enableRowVirtualization
|
122
121
|
? useVirtualizer({
|
123
122
|
count: rows.length,
|
@@ -202,7 +201,7 @@ export const MRT_TableBody = ({
|
|
202
201
|
virtualPaddingLeft,
|
203
202
|
virtualPaddingRight,
|
204
203
|
virtualRow: rowVirtualizer
|
205
|
-
? (rowOrVirtualRow as
|
204
|
+
? (rowOrVirtualRow as VirtualItem)
|
206
205
|
: undefined,
|
207
206
|
};
|
208
207
|
return memoMode === 'rows' ? (
|
@@ -19,7 +19,8 @@ import {
|
|
19
19
|
getIsFirstColumn,
|
20
20
|
getIsLastColumn,
|
21
21
|
} from '../column.utils';
|
22
|
-
import type {
|
22
|
+
import type { VirtualItem } from '@tanstack/react-virtual';
|
23
|
+
import type { MRT_Cell, MRT_TableInstance } from '..';
|
23
24
|
|
24
25
|
interface Props {
|
25
26
|
cell: MRT_Cell;
|
@@ -29,7 +30,7 @@ interface Props {
|
|
29
30
|
rowIndex: number;
|
30
31
|
rowRef: RefObject<HTMLTableRowElement>;
|
31
32
|
table: MRT_TableInstance;
|
32
|
-
virtualCell?:
|
33
|
+
virtualCell?: VirtualItem;
|
33
34
|
}
|
34
35
|
|
35
36
|
export const MRT_TableBodyCell = ({
|
@@ -3,25 +3,20 @@ import TableRow from '@mui/material/TableRow';
|
|
3
3
|
import { darken, lighten } from '@mui/material/styles';
|
4
4
|
import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
|
5
5
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
6
|
-
import type {
|
7
|
-
|
8
|
-
MRT_Row,
|
9
|
-
MRT_TableInstance,
|
10
|
-
MRT_VirtualItem,
|
11
|
-
MRT_Virtualizer,
|
12
|
-
} from '..';
|
6
|
+
import type { VirtualItem, Virtualizer } from '@tanstack/react-virtual';
|
7
|
+
import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
|
13
8
|
|
14
9
|
interface Props {
|
15
|
-
columnVirtualizer?:
|
10
|
+
columnVirtualizer?: Virtualizer<HTMLDivElement, HTMLTableCellElement>;
|
16
11
|
measureElement?: (element: HTMLTableRowElement) => void;
|
17
12
|
numRows: number;
|
18
13
|
row: MRT_Row;
|
19
14
|
rowIndex: number;
|
20
15
|
table: MRT_TableInstance;
|
21
|
-
virtualColumns?:
|
16
|
+
virtualColumns?: VirtualItem[];
|
22
17
|
virtualPaddingLeft?: number;
|
23
18
|
virtualPaddingRight?: number;
|
24
|
-
virtualRow?:
|
19
|
+
virtualRow?: VirtualItem;
|
25
20
|
}
|
26
21
|
|
27
22
|
export const MRT_TableBodyRow = ({
|
@@ -108,9 +103,7 @@ export const MRT_TableBodyRow = ({
|
|
108
103
|
) : null}
|
109
104
|
{(virtualColumns ?? row.getVisibleCells()).map((cellOrVirtualCell) => {
|
110
105
|
const cell = columnVirtualizer
|
111
|
-
? row.getVisibleCells()[
|
112
|
-
(cellOrVirtualCell as MRT_VirtualItem).index
|
113
|
-
]
|
106
|
+
? row.getVisibleCells()[(cellOrVirtualCell as VirtualItem).index]
|
114
107
|
: (cellOrVirtualCell as MRT_Cell);
|
115
108
|
const props = {
|
116
109
|
cell,
|
@@ -122,7 +115,7 @@ export const MRT_TableBodyRow = ({
|
|
122
115
|
rowRef,
|
123
116
|
table,
|
124
117
|
virtualCell: columnVirtualizer
|
125
|
-
? (cellOrVirtualCell as
|
118
|
+
? (cellOrVirtualCell as VirtualItem)
|
126
119
|
: undefined,
|
127
120
|
};
|
128
121
|
return memoMode === 'cells' &&
|
@@ -3,13 +3,14 @@ import Collapse from '@mui/material/Collapse';
|
|
3
3
|
import TableCell from '@mui/material/TableCell';
|
4
4
|
import TableRow from '@mui/material/TableRow';
|
5
5
|
import { lighten } from '@mui/material/styles';
|
6
|
-
import type {
|
6
|
+
import type { VirtualItem } from '@tanstack/react-virtual';
|
7
|
+
import type { MRT_Row, MRT_TableInstance } from '..';
|
7
8
|
|
8
9
|
interface Props {
|
9
10
|
parentRowRef: React.RefObject<HTMLTableRowElement>;
|
10
11
|
row: MRT_Row;
|
11
12
|
table: MRT_TableInstance;
|
12
|
-
virtualRow?:
|
13
|
+
virtualRow?: VirtualItem;
|
13
14
|
}
|
14
15
|
|
15
16
|
export const MRT_TableDetailPanel = ({
|
@@ -61,7 +61,7 @@ export const MRT_ToggleRowActionMenuButton = <
|
|
61
61
|
return (
|
62
62
|
<>
|
63
63
|
{renderRowActions ? (
|
64
|
-
|
64
|
+
renderRowActions({ cell, row, table })
|
65
65
|
) : row.id === editingRow?.id && editingMode === 'row' ? (
|
66
66
|
<MRT_EditActionButtons row={row} table={table} />
|
67
67
|
) : !renderRowActionMenuItems &&
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import TableFooter from '@mui/material/TableFooter';
|
3
3
|
import { MRT_TableFooterRow } from './MRT_TableFooterRow';
|
4
|
-
import type {
|
4
|
+
import type { VirtualItem } from '@tanstack/react-virtual';
|
5
|
+
import type { MRT_TableInstance } from '..';
|
5
6
|
|
6
7
|
interface Props {
|
7
8
|
table: MRT_TableInstance;
|
8
|
-
virtualColumns?:
|
9
|
+
virtualColumns?: VirtualItem[];
|
9
10
|
virtualPaddingLeft?: number;
|
10
11
|
virtualPaddingRight?: number;
|
11
12
|
}
|
@@ -2,17 +2,13 @@ import React from 'react';
|
|
2
2
|
import TableRow from '@mui/material/TableRow';
|
3
3
|
import { lighten } from '@mui/material/styles';
|
4
4
|
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
|
5
|
-
import
|
6
|
-
|
7
|
-
MRT_HeaderGroup,
|
8
|
-
MRT_TableInstance,
|
9
|
-
MRT_VirtualItem,
|
10
|
-
} from '..';
|
5
|
+
import { VirtualItem } from '@tanstack/react-virtual';
|
6
|
+
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
11
7
|
|
12
8
|
interface Props {
|
13
9
|
footerGroup: MRT_HeaderGroup;
|
14
10
|
table: MRT_TableInstance;
|
15
|
-
virtualColumns?:
|
11
|
+
virtualColumns?: VirtualItem[];
|
16
12
|
virtualPaddingLeft?: number;
|
17
13
|
virtualPaddingRight?: number;
|
18
14
|
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import TableHead from '@mui/material/TableHead';
|
3
3
|
import { MRT_TableHeadRow } from './MRT_TableHeadRow';
|
4
|
-
import type {
|
4
|
+
import type { VirtualItem } from '@tanstack/react-virtual';
|
5
|
+
import type { MRT_TableInstance } from '..';
|
5
6
|
|
6
7
|
interface Props {
|
7
8
|
table: MRT_TableInstance;
|
8
|
-
virtualColumns?:
|
9
|
+
virtualColumns?: VirtualItem[];
|
9
10
|
virtualPaddingLeft?: number;
|
10
11
|
virtualPaddingRight?: number;
|
11
12
|
}
|
@@ -2,17 +2,13 @@ import React from 'react';
|
|
2
2
|
import TableRow from '@mui/material/TableRow';
|
3
3
|
import { alpha, lighten } from '@mui/material/styles';
|
4
4
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
5
|
-
import type {
|
6
|
-
|
7
|
-
MRT_HeaderGroup,
|
8
|
-
MRT_TableInstance,
|
9
|
-
MRT_VirtualItem,
|
10
|
-
} from '..';
|
5
|
+
import type { VirtualItem } from '@tanstack/react-virtual';
|
6
|
+
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
11
7
|
|
12
8
|
interface Props {
|
13
9
|
headerGroup: MRT_HeaderGroup;
|
14
10
|
table: MRT_TableInstance;
|
15
|
-
virtualColumns?:
|
11
|
+
virtualColumns?: VirtualItem[];
|
16
12
|
virtualPaddingLeft?: number;
|
17
13
|
virtualPaddingRight?: number;
|
18
14
|
}
|
@@ -116,33 +116,34 @@ export const MRT_EditCellTextField = <TData extends Record<string, any> = {}>({
|
|
116
116
|
onChange={handleChange}
|
117
117
|
onKeyDown={handleEnterKeyDown}
|
118
118
|
>
|
119
|
-
{
|
120
|
-
(
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
119
|
+
{textFieldProps.children ??
|
120
|
+
columnDef?.editSelectOptions?.map(
|
121
|
+
(option: string | { text: string; value: string }) => {
|
122
|
+
let value: string;
|
123
|
+
let text: string;
|
124
|
+
if (typeof option !== 'object') {
|
125
|
+
value = option;
|
126
|
+
text = option;
|
127
|
+
} else {
|
128
|
+
value = option.value;
|
129
|
+
text = option.text;
|
130
|
+
}
|
131
|
+
return (
|
132
|
+
<MenuItem
|
133
|
+
key={value}
|
134
|
+
sx={{
|
135
|
+
display: 'flex',
|
136
|
+
m: 0,
|
137
|
+
alignItems: 'center',
|
138
|
+
gap: '0.5rem',
|
139
|
+
}}
|
140
|
+
value={value}
|
141
|
+
>
|
142
|
+
{text}
|
143
|
+
</MenuItem>
|
144
|
+
);
|
145
|
+
},
|
146
|
+
)}
|
146
147
|
</TextField>
|
147
148
|
);
|
148
149
|
};
|
@@ -349,41 +349,42 @@ export const MRT_FilterTextField = ({
|
|
349
349
|
<Box sx={{ opacity: 0.5 }}>{filterPlaceholder}</Box>
|
350
350
|
</MenuItem>
|
351
351
|
)}
|
352
|
-
{
|
353
|
-
(
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
(
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
352
|
+
{textFieldProps.children ??
|
353
|
+
columnDef?.filterSelectOptions?.map(
|
354
|
+
(option: string | { text: string; value: string }) => {
|
355
|
+
let value: string;
|
356
|
+
let text: string;
|
357
|
+
if (typeof option !== 'object') {
|
358
|
+
value = option;
|
359
|
+
text = option;
|
360
|
+
} else {
|
361
|
+
value = option.value;
|
362
|
+
text = option.text;
|
363
|
+
}
|
364
|
+
return (
|
365
|
+
<MenuItem
|
366
|
+
key={value}
|
367
|
+
sx={{
|
368
|
+
display: 'flex',
|
369
|
+
m: 0,
|
370
|
+
alignItems: 'center',
|
371
|
+
gap: '0.5rem',
|
372
|
+
}}
|
373
|
+
value={value}
|
374
|
+
>
|
375
|
+
{isMultiSelectFilter && (
|
376
|
+
<Checkbox
|
377
|
+
checked={(
|
378
|
+
(column.getFilterValue() ?? []) as string[]
|
379
|
+
).includes(value)}
|
380
|
+
sx={{ mr: '0.5rem' }}
|
381
|
+
/>
|
382
|
+
)}
|
383
|
+
{text}
|
384
|
+
</MenuItem>
|
385
|
+
);
|
386
|
+
},
|
387
|
+
)}
|
387
388
|
</TextField>
|
388
389
|
<MRT_FilterOptionMenu
|
389
390
|
anchorEl={anchorEl}
|
@@ -165,7 +165,10 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
165
165
|
option as string,
|
166
166
|
)
|
167
167
|
) {
|
168
|
-
if (
|
168
|
+
if (
|
169
|
+
currentFilterValue instanceof String ||
|
170
|
+
(currentFilterValue as Array<any>)?.length
|
171
|
+
) {
|
169
172
|
column.setFilterValue([]);
|
170
173
|
setFilterValue?.([]);
|
171
174
|
}
|
@@ -175,8 +178,10 @@ export const MRT_FilterOptionMenu = <TData extends Record<string, any> = {}>({
|
|
175
178
|
option as MRT_FilterOption,
|
176
179
|
)
|
177
180
|
) {
|
178
|
-
|
179
|
-
|
181
|
+
if (!(currentFilterValue as Array<any>)?.every((v) => v === '')) {
|
182
|
+
column.setFilterValue(['', '']);
|
183
|
+
setFilterValue?.('');
|
184
|
+
}
|
180
185
|
} else {
|
181
186
|
if (
|
182
187
|
!['', undefined].includes(currentFilterValue as string | undefined)
|
package/src/table/MRT_Table.tsx
CHANGED
@@ -3,13 +3,14 @@ import {
|
|
3
3
|
defaultRangeExtractor,
|
4
4
|
Range,
|
5
5
|
useVirtualizer,
|
6
|
+
Virtualizer,
|
6
7
|
} from '@tanstack/react-virtual';
|
7
8
|
import Table from '@mui/material/Table';
|
8
9
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|
9
10
|
import { Memo_MRT_TableBody, MRT_TableBody } from '../body/MRT_TableBody';
|
10
11
|
import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
11
12
|
import { parseCSSVarId } from '../column.utils';
|
12
|
-
import type { MRT_TableInstance
|
13
|
+
import type { MRT_TableInstance } from '..';
|
13
14
|
|
14
15
|
interface Props {
|
15
16
|
table: MRT_TableInstance;
|
@@ -63,7 +64,7 @@ export const MRT_Table = ({ table }: Props) => {
|
|
63
64
|
colSizes[`--col-${parseCSSVarId(header.column.id)}-size`] = colSize;
|
64
65
|
}
|
65
66
|
return colSizes;
|
66
|
-
}, [columns, columnSizing, columnSizingInfo]);
|
67
|
+
}, [columns, columnSizing, columnSizingInfo, columnVisibility]);
|
67
68
|
|
68
69
|
//get first 16 column widths and average them
|
69
70
|
const averageColumnWidth = useMemo(() => {
|
@@ -94,7 +95,7 @@ export const MRT_Table = ({ table }: Props) => {
|
|
94
95
|
);
|
95
96
|
|
96
97
|
const columnVirtualizer:
|
97
|
-
|
|
98
|
+
| Virtualizer<HTMLDivElement, HTMLTableCellElement>
|
98
99
|
| undefined = enableColumnVirtualization
|
99
100
|
? useVirtualizer({
|
100
101
|
count: table.getVisibleLeafColumns().length,
|
@@ -332,6 +332,12 @@ export const MRT_TableRoot: any = <TData extends Record<string, any> = {}>(
|
|
332
332
|
props.onShowToolbarDropZoneChange ?? setShowToolbarDropZone,
|
333
333
|
} as MRT_TableInstance<TData>;
|
334
334
|
|
335
|
+
if (props.tableFeatures) {
|
336
|
+
props.tableFeatures.forEach((feature) => {
|
337
|
+
Object.assign(table, feature(table));
|
338
|
+
});
|
339
|
+
}
|
340
|
+
|
335
341
|
if (props.tableInstanceRef) {
|
336
342
|
props.tableInstanceRef.current = table;
|
337
343
|
}
|