material-react-table 0.9.4 → 0.9.7
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 +2 -0
- package/dist/MaterialReactTable.d.ts +13 -1
- package/dist/material-react-table.cjs.development.js +53 -48
- 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 +53 -48
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_TablePaper.d.ts +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +13 -2
- package/src/body/MRT_TableBody.tsx +7 -1
- package/src/body/MRT_TableBodyCell.tsx +2 -15
- package/src/body/MRT_TableBodyRow.tsx +5 -1
- package/src/body/MRT_TableDetailPanel.tsx +3 -2
- package/src/head/MRT_TableHeadCell.tsx +1 -3
- package/src/table/MRT_Table.tsx +7 -2
- package/src/table/MRT_TableContainer.tsx +11 -4
- package/src/table/MRT_TablePaper.tsx +1 -5
- package/src/table/MRT_TableRoot.tsx +12 -9
- package/src/toolbar/MRT_ToolbarTop.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.9.
|
|
2
|
+
"version": "0.9.7",
|
|
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.",
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
FilterFnOption,
|
|
35
35
|
Header,
|
|
36
36
|
HeaderGroup,
|
|
37
|
+
OnChangeFn,
|
|
37
38
|
Overwrite,
|
|
38
39
|
ReactTableGenerics,
|
|
39
40
|
Row,
|
|
@@ -43,6 +44,7 @@ import {
|
|
|
43
44
|
UseTableInstanceOptions,
|
|
44
45
|
VisibilityState,
|
|
45
46
|
} from '@tanstack/react-table';
|
|
47
|
+
import { Options as VirtualizerOptions } from 'react-virtual';
|
|
46
48
|
import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
|
|
47
49
|
import { MRT_Default_Icons, MRT_Icons } from './icons';
|
|
48
50
|
import { MRT_FILTER_OPTION } from './enums';
|
|
@@ -567,6 +569,12 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
567
569
|
}: {
|
|
568
570
|
tableInstance: MRT_TableInstance;
|
|
569
571
|
}) => ToolbarProps);
|
|
572
|
+
onCurrentEditingCellChange?: OnChangeFn<MRT_Cell>;
|
|
573
|
+
onCurrentEditingRowChange?: OnChangeFn<MRT_Row>;
|
|
574
|
+
onCurrentFilterFnsChange?: OnChangeFn<{ [key: string]: MRT_FilterFn<D> }>;
|
|
575
|
+
onCurrentGlobalFilterFnChange?: OnChangeFn<MRT_FilterFn<D>>;
|
|
576
|
+
onIsDensePaddingChange?: OnChangeFn<boolean>;
|
|
577
|
+
onIsFullScreenChange?: OnChangeFn<boolean>;
|
|
570
578
|
onMrtCellClick?: ({
|
|
571
579
|
cell,
|
|
572
580
|
event,
|
|
@@ -708,6 +716,8 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
708
716
|
showGlobalFilter: boolean;
|
|
709
717
|
tableInstance: MRT_TableInstance<D>;
|
|
710
718
|
}) => void;
|
|
719
|
+
onShowFiltersChange?: OnChangeFn<boolean>;
|
|
720
|
+
onShowGlobalFilterChange?: OnChangeFn<boolean>;
|
|
711
721
|
persistentStateMode?: 'localStorage' | 'sessionStorage';
|
|
712
722
|
positionActionsColumn?: 'first' | 'last';
|
|
713
723
|
positionPagination?: 'bottom' | 'top' | 'both';
|
|
@@ -770,12 +780,13 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
770
780
|
rowNumberMode?: 'original' | 'static';
|
|
771
781
|
selectAllMode?: 'all' | 'page';
|
|
772
782
|
tableId?: string;
|
|
783
|
+
virtualizerProps?: VirtualizerOptions<HTMLDivElement>;
|
|
773
784
|
};
|
|
774
785
|
|
|
775
786
|
export default <D extends Record<string, any> = {}>({
|
|
776
787
|
autoResetExpanded = false,
|
|
777
788
|
columnResizeMode = 'onEnd',
|
|
778
|
-
defaultColumn = { minSize:
|
|
789
|
+
defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
|
|
779
790
|
editingMode = 'row',
|
|
780
791
|
enableColumnActions = true,
|
|
781
792
|
enableColumnFilters = true,
|
|
@@ -793,7 +804,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
793
804
|
enablePinning = false,
|
|
794
805
|
enableSelectAll = true,
|
|
795
806
|
enableSorting = true,
|
|
796
|
-
enableStickyHeader =
|
|
807
|
+
enableStickyHeader = false,
|
|
797
808
|
enableTableFooter = true,
|
|
798
809
|
enableTableHead = true,
|
|
799
810
|
enableToolbarBottom = true,
|
|
@@ -17,7 +17,12 @@ export const MRT_TableBody: FC<Props> = ({
|
|
|
17
17
|
getPaginationRowModel,
|
|
18
18
|
getPrePaginationRowModel,
|
|
19
19
|
getState,
|
|
20
|
-
options: {
|
|
20
|
+
options: {
|
|
21
|
+
enablePagination,
|
|
22
|
+
enableRowVirtualization,
|
|
23
|
+
muiTableBodyProps,
|
|
24
|
+
virtualizerProps,
|
|
25
|
+
},
|
|
21
26
|
} = tableInstance;
|
|
22
27
|
|
|
23
28
|
const { isDensePadding } = getState();
|
|
@@ -36,6 +41,7 @@ export const MRT_TableBody: FC<Props> = ({
|
|
|
36
41
|
overscan: isDensePadding ? 15 : 5,
|
|
37
42
|
size: rows.length,
|
|
38
43
|
parentRef: tableContainerRef,
|
|
44
|
+
...virtualizerProps,
|
|
39
45
|
})
|
|
40
46
|
: ({} as any);
|
|
41
47
|
|
|
@@ -25,10 +25,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
25
25
|
editingMode,
|
|
26
26
|
enableClickToCopy,
|
|
27
27
|
enableColumnOrdering,
|
|
28
|
-
enableColumnResizing,
|
|
29
28
|
enableEditing,
|
|
30
29
|
enableRowNumbers,
|
|
31
|
-
enableRowVirtualization,
|
|
32
30
|
muiTableBodyCellProps,
|
|
33
31
|
muiTableBodyCellSkeletonProps,
|
|
34
32
|
onMrtCellClick,
|
|
@@ -137,15 +135,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
137
135
|
onMrtCellClick?.({ event, cell, tableInstance })
|
|
138
136
|
}
|
|
139
137
|
onDoubleClick={handleDoubleClick}
|
|
140
|
-
title={
|
|
141
|
-
(enableRowVirtualization || enableColumnResizing) &&
|
|
142
|
-
!columnDef?.Cell &&
|
|
143
|
-
!cell.getIsGrouped() &&
|
|
144
|
-
!columnDef.enableClickToCopy &&
|
|
145
|
-
typeof cell.getValue() === 'string'
|
|
146
|
-
? (cell.getValue() as string)
|
|
147
|
-
: ''
|
|
148
|
-
}
|
|
149
138
|
{...tableCellProps}
|
|
150
139
|
ref={
|
|
151
140
|
columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
|
|
@@ -179,7 +168,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
179
168
|
position: column.getIsPinned() ? 'sticky' : 'relative',
|
|
180
169
|
right:
|
|
181
170
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
182
|
-
textOverflow: 'ellipsis',
|
|
171
|
+
textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
|
|
183
172
|
transition: 'all 0.2s ease-in-out',
|
|
184
173
|
whiteSpace: isDensePadding ? 'nowrap' : 'normal',
|
|
185
174
|
zIndex: column.getIsPinned() ? 1 : undefined,
|
|
@@ -195,12 +184,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
195
184
|
: undefined,
|
|
196
185
|
},
|
|
197
186
|
...(tableCellProps?.sx as any),
|
|
198
|
-
})}
|
|
199
|
-
style={{
|
|
200
187
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
201
188
|
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
|
202
189
|
width: column.getSize(),
|
|
203
|
-
}}
|
|
190
|
+
})}
|
|
204
191
|
>
|
|
205
192
|
<>
|
|
206
193
|
{isLoading || showSkeletons ? (
|
|
@@ -10,7 +10,11 @@ interface Props {
|
|
|
10
10
|
tableInstance: MRT_TableInstance;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const MRT_TableBodyRow: FC<Props> = ({
|
|
13
|
+
export const MRT_TableBodyRow: FC<Props> = ({
|
|
14
|
+
row,
|
|
15
|
+
rowIndex,
|
|
16
|
+
tableInstance,
|
|
17
|
+
}) => {
|
|
14
18
|
const {
|
|
15
19
|
getIsSomeColumnsPinned,
|
|
16
20
|
options: { muiTableBodyRowProps, onMrtRowClick, renderDetailPanel },
|
|
@@ -9,7 +9,7 @@ interface Props {
|
|
|
9
9
|
|
|
10
10
|
export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
|
|
11
11
|
const {
|
|
12
|
-
|
|
12
|
+
getVisibleLeafColumns,
|
|
13
13
|
options: {
|
|
14
14
|
muiTableBodyRowProps,
|
|
15
15
|
muiTableDetailPanelProps,
|
|
@@ -31,7 +31,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
|
|
|
31
31
|
return (
|
|
32
32
|
<TableRow {...tableRowProps}>
|
|
33
33
|
<TableCell
|
|
34
|
-
colSpan={
|
|
34
|
+
colSpan={getVisibleLeafColumns().length}
|
|
35
35
|
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
36
36
|
onMrtDetailPanelClick?.({ event, row, tableInstance })
|
|
37
37
|
}
|
|
@@ -41,6 +41,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
|
|
|
41
41
|
pb: row.getIsExpanded() ? '1rem' : 0,
|
|
42
42
|
pt: row.getIsExpanded() ? '1rem' : 0,
|
|
43
43
|
transition: 'all 0.2s ease-in-out',
|
|
44
|
+
width: `${tableInstance.getTotalSize()}px`,
|
|
44
45
|
...tableCellProps?.sx,
|
|
45
46
|
}}
|
|
46
47
|
>
|
|
@@ -136,12 +136,10 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
136
136
|
? 2
|
|
137
137
|
: 1,
|
|
138
138
|
...(tableCellProps?.sx as any),
|
|
139
|
-
})}
|
|
140
|
-
style={{
|
|
141
139
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
142
140
|
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
|
143
141
|
width: header.getSize(),
|
|
144
|
-
}}
|
|
142
|
+
})}
|
|
145
143
|
>
|
|
146
144
|
{header.isPlaceholder ? null : columnDefType === 'display' ? (
|
|
147
145
|
headerElement
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -12,6 +12,7 @@ interface Props {
|
|
|
12
12
|
|
|
13
13
|
export const MRT_Table: FC<Props> = ({ tableContainerRef, tableInstance }) => {
|
|
14
14
|
const {
|
|
15
|
+
getState,
|
|
15
16
|
options: {
|
|
16
17
|
enableColumnResizing,
|
|
17
18
|
enableRowVirtualization,
|
|
@@ -22,6 +23,8 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, tableInstance }) => {
|
|
|
22
23
|
},
|
|
23
24
|
} = tableInstance;
|
|
24
25
|
|
|
26
|
+
const { isFullScreen } = getState();
|
|
27
|
+
|
|
25
28
|
const tableProps =
|
|
26
29
|
muiTableProps instanceof Function
|
|
27
30
|
? muiTableProps({ tableInstance })
|
|
@@ -29,11 +32,13 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, tableInstance }) => {
|
|
|
29
32
|
|
|
30
33
|
return (
|
|
31
34
|
<Table
|
|
32
|
-
stickyHeader={
|
|
35
|
+
stickyHeader={
|
|
36
|
+
enableStickyHeader || enableRowVirtualization || isFullScreen
|
|
37
|
+
}
|
|
33
38
|
{...tableProps}
|
|
34
39
|
sx={{
|
|
35
40
|
tableLayout:
|
|
36
|
-
enableColumnResizing || enableRowVirtualization ? 'fixed' :
|
|
41
|
+
enableColumnResizing || enableRowVirtualization ? 'fixed' : 'auto',
|
|
37
42
|
...tableProps?.sx,
|
|
38
43
|
}}
|
|
39
44
|
>
|
|
@@ -13,7 +13,12 @@ interface Props {
|
|
|
13
13
|
export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
14
14
|
const {
|
|
15
15
|
getState,
|
|
16
|
-
options: {
|
|
16
|
+
options: {
|
|
17
|
+
enableStickyHeader,
|
|
18
|
+
enableRowVirtualization,
|
|
19
|
+
muiTableContainerProps,
|
|
20
|
+
tableId,
|
|
21
|
+
},
|
|
17
22
|
} = tableInstance;
|
|
18
23
|
|
|
19
24
|
const { isFullScreen } = getState();
|
|
@@ -49,9 +54,10 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
49
54
|
ref={tableContainerRef}
|
|
50
55
|
sx={{
|
|
51
56
|
maxWidth: '100%',
|
|
52
|
-
maxHeight:
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
maxHeight:
|
|
58
|
+
enableStickyHeader || enableRowVirtualization
|
|
59
|
+
? `clamp(350px, calc(100vh - ${totalToolbarHeight}px), 9999px)`
|
|
60
|
+
: undefined,
|
|
55
61
|
overflow: 'auto',
|
|
56
62
|
...tableContainerProps?.sx,
|
|
57
63
|
}}
|
|
@@ -59,6 +65,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
59
65
|
maxHeight: isFullScreen
|
|
60
66
|
? `calc(100vh - ${totalToolbarHeight}px)`
|
|
61
67
|
: undefined,
|
|
68
|
+
...tableContainerProps?.style,
|
|
62
69
|
}}
|
|
63
70
|
>
|
|
64
71
|
<MRT_Table
|
|
@@ -5,7 +5,7 @@ import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
|
5
5
|
import { MRT_ToolbarTop } from '../toolbar/MRT_ToolbarTop';
|
|
6
6
|
import { MRT_ToolbarBottom } from '../toolbar/MRT_ToolbarBottom';
|
|
7
7
|
import { MRT_TableContainer } from './MRT_TableContainer';
|
|
8
|
-
import { MRT_TableInstance } from '..';
|
|
8
|
+
import type { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
10
|
interface Props {
|
|
11
11
|
tableInstance: MRT_TableInstance;
|
|
@@ -22,10 +22,8 @@ export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
|
22
22
|
useEffect(() => {
|
|
23
23
|
if (typeof window !== 'undefined') {
|
|
24
24
|
if (isFullScreen) {
|
|
25
|
-
document.body.style.overflow = 'hidden';
|
|
26
25
|
document.body.style.height = '100vh';
|
|
27
26
|
} else {
|
|
28
|
-
document.body.style.overflow = 'auto';
|
|
29
27
|
document.body.style.height = 'auto';
|
|
30
28
|
}
|
|
31
29
|
}
|
|
@@ -44,8 +42,6 @@ export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
|
44
42
|
sx={{
|
|
45
43
|
transition: 'all 0.2s ease-in-out',
|
|
46
44
|
...tablePaperProps?.sx,
|
|
47
|
-
}}
|
|
48
|
-
style={{
|
|
49
45
|
height: isFullScreen ? '100vh' : undefined,
|
|
50
46
|
margin: isFullScreen ? '0' : undefined,
|
|
51
47
|
maxHeight: isFullScreen ? '100vh' : undefined,
|
|
@@ -170,7 +170,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
170
170
|
id: 'mrt-row-actions',
|
|
171
171
|
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
172
172
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
173
|
-
size:
|
|
173
|
+
size: 70,
|
|
174
174
|
}),
|
|
175
175
|
showExpandColumn &&
|
|
176
176
|
createDisplayColumn(table, {
|
|
@@ -286,14 +286,17 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
286
286
|
...props.state,
|
|
287
287
|
} as TableState,
|
|
288
288
|
}),
|
|
289
|
-
setCurrentEditingCell
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
289
|
+
setCurrentEditingCell:
|
|
290
|
+
props.onCurrentEditingCellChange ?? setCurrentEditingCell,
|
|
291
|
+
setCurrentEditingRow:
|
|
292
|
+
props.onCurrentEditingRowChange ?? setCurrentEditingRow,
|
|
293
|
+
setCurrentFilterFns: props.onCurrentFilterFnsChange ?? setCurrentFilterFns,
|
|
294
|
+
setCurrentGlobalFilterFn:
|
|
295
|
+
props.onCurrentGlobalFilterFnChange ?? setCurrentGlobalFilterFn,
|
|
296
|
+
setIsDensePadding: props.onIsDensePaddingChange ?? setIsDensePadding,
|
|
297
|
+
setIsFullScreen: props.onIsFullScreenChange ?? setIsFullScreen,
|
|
298
|
+
setShowFilters: props.onShowFiltersChange ?? setShowFilters,
|
|
299
|
+
setShowGlobalFilter: props.onShowGlobalFilterChange ?? setShowGlobalFilter,
|
|
297
300
|
} as MRT_TableInstance;
|
|
298
301
|
|
|
299
302
|
useEffect(() => {
|