material-react-table 0.40.0 → 0.40.1
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 +10 -2
- package/dist/cjs/index.js +28 -20
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/MaterialReactTable.d.ts +10 -2
- package/dist/esm/material-react-table.esm.js +28 -20
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +10 -3
- package/src/body/MRT_TableBody.tsx +15 -10
- package/src/head/MRT_TableHeadCell.tsx +21 -13
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +1 -1
- package/src/table/MRT_TableRoot.tsx +1 -1
- package/src/toolbar/MRT_ToolbarDropZone.tsx +10 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { MutableRefObject, Dispatch, SetStateAction, ReactNode, DragEvent } from 'react';
|
|
3
3
|
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, ToolbarProps, LinearProgressProps, CheckboxProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
|
|
4
4
|
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
5
|
-
import { Options } from 'react-virtual';
|
|
5
|
+
import { Options, VirtualItem } from 'react-virtual';
|
|
6
6
|
import * as _tanstack_table_core from '@tanstack/table-core';
|
|
7
7
|
import { RankingInfo } from '@tanstack/match-sorter-utils';
|
|
8
8
|
|
|
@@ -701,8 +701,16 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
701
701
|
virtualizerProps?: Partial<Options<HTMLDivElement>> | (({ table, }: {
|
|
702
702
|
table: MRT_TableInstance<TData>;
|
|
703
703
|
}) => Partial<Options<HTMLDivElement>>);
|
|
704
|
+
virtualizerInstanceRef?: MutableRefObject<Virtualizer | null>;
|
|
704
705
|
};
|
|
705
|
-
declare
|
|
706
|
+
declare type Virtualizer = {
|
|
707
|
+
virtualItems: VirtualItem[];
|
|
708
|
+
totalSize: number;
|
|
709
|
+
scrollToOffset: (index: number, options?: any | undefined) => void;
|
|
710
|
+
scrollToIndex: (index: number, options?: any | undefined) => void;
|
|
711
|
+
measure: () => void;
|
|
712
|
+
};
|
|
713
|
+
declare const _default: <TData extends Record<string, any> = {}>({ aggregationFns, autoResetExpanded, columnResizeMode, defaultColumn, editingMode, enableBottomToolbar, enableColumnActions, enableColumnFilters, enableColumnOrdering, enableColumnResizing, enableDensityToggle, enableExpandAll, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableGlobalFilterRankedResults, enableGrouping, enableHiding, enableMultiRowSelection, enableMultiSort, enablePagination, enablePinning, enableRowSelection, enableSelectAll, enableSorting, enableStickyHeader, enableTableFooter, enableTableHead, enableToolbarInternalActions, enableTopToolbar, filterFns, icons, localization, positionActionsColumn, positionExpandColumn, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, rowNumberMode, selectAllMode, sortingFns, ...rest }: MaterialReactTableProps<TData>) => JSX.Element;
|
|
706
714
|
|
|
707
715
|
interface Props$6<TData extends Record<string, any> = {}> {
|
|
708
716
|
cell: MRT_Cell<TData>;
|
|
@@ -741,4 +749,4 @@ interface Props<TData extends Record<string, any> = {}> extends IconButtonProps
|
|
|
741
749
|
}
|
|
742
750
|
declare const MRT_ToggleGlobalFilterButton: <TData extends Record<string, any> = {}>({ table, ...rest }: Props<TData>) => JSX.Element;
|
|
743
751
|
|
|
744
|
-
export { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, 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_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MaterialReactTableProps, _default as default };
|
|
752
|
+
export { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_CopyButton, MRT_DefinedColumnDef, MRT_DisplayColumnIds, MRT_FilterFn, MRT_FilterOption, 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_TableState, MRT_ToggleDensePaddingButton, MRT_ToggleFiltersButton, MRT_ToggleGlobalFilterButton, MaterialReactTableProps, Virtualizer, _default as default };
|
package/package.json
CHANGED
|
@@ -40,7 +40,7 @@ import type {
|
|
|
40
40
|
TableOptions,
|
|
41
41
|
TableState,
|
|
42
42
|
} from '@tanstack/react-table';
|
|
43
|
-
import type { Options as VirtualizerOptions } from 'react-virtual';
|
|
43
|
+
import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
|
|
44
44
|
// import type { VirtualizerOptions } from '@tanstack/react-virtual';
|
|
45
45
|
import { MRT_AggregationFns } from './aggregationFns';
|
|
46
46
|
import { MRT_Default_Icons, MRT_Icons } from './icons';
|
|
@@ -856,8 +856,17 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
856
856
|
// }: {
|
|
857
857
|
// table: MRT_TableInstance<TData>;
|
|
858
858
|
// }) => Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>);
|
|
859
|
+
virtualizerInstanceRef?: MutableRefObject<Virtualizer | null>;
|
|
859
860
|
};
|
|
860
861
|
|
|
862
|
+
export type Virtualizer = {
|
|
863
|
+
virtualItems: VirtualItem[];
|
|
864
|
+
totalSize: number;
|
|
865
|
+
scrollToOffset: (index: number, options?: any | undefined) => void;
|
|
866
|
+
scrollToIndex: (index: number, options?: any | undefined) => void;
|
|
867
|
+
measure: () => void;
|
|
868
|
+
};
|
|
869
|
+
|
|
861
870
|
export default <TData extends Record<string, any> = {}>({
|
|
862
871
|
aggregationFns,
|
|
863
872
|
autoResetExpanded = false,
|
|
@@ -866,7 +875,6 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
866
875
|
editingMode = 'modal',
|
|
867
876
|
enableBottomToolbar = true,
|
|
868
877
|
enableColumnActions = true,
|
|
869
|
-
enableColumnFilterModes = false,
|
|
870
878
|
enableColumnFilters = true,
|
|
871
879
|
enableColumnOrdering = false,
|
|
872
880
|
enableColumnResizing = false,
|
|
@@ -875,7 +883,6 @@ export default <TData extends Record<string, any> = {}>({
|
|
|
875
883
|
enableFilters = true,
|
|
876
884
|
enableFullScreenToggle = true,
|
|
877
885
|
enableGlobalFilter = true,
|
|
878
|
-
enableGlobalFilterModes = false,
|
|
879
886
|
enableGlobalFilterRankedResults = true,
|
|
880
887
|
enableGrouping = false,
|
|
881
888
|
enableHiding = true,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { FC, RefObject, useMemo } from 'react';
|
|
2
|
-
import { useVirtual } from 'react-virtual';
|
|
1
|
+
import React, { FC, RefObject, useEffect, useMemo } from 'react';
|
|
2
|
+
import { useVirtual } from 'react-virtual'; //stuck on v2 for now
|
|
3
3
|
// import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
|
|
4
4
|
import { TableBody } from '@mui/material';
|
|
5
5
|
import { MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
@@ -22,6 +22,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
22
22
|
enableRowVirtualization,
|
|
23
23
|
muiTableBodyProps,
|
|
24
24
|
virtualizerProps,
|
|
25
|
+
virtualizerInstanceRef,
|
|
25
26
|
},
|
|
26
27
|
} = table;
|
|
27
28
|
const { globalFilter, pagination, sorting } = getState();
|
|
@@ -62,7 +63,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
62
63
|
globalFilter,
|
|
63
64
|
]);
|
|
64
65
|
|
|
65
|
-
const
|
|
66
|
+
const virtualizer = enableRowVirtualization
|
|
66
67
|
? useVirtual({
|
|
67
68
|
size: rows.length,
|
|
68
69
|
parentRef: tableContainerRef,
|
|
@@ -71,7 +72,13 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
71
72
|
})
|
|
72
73
|
: ({} as any);
|
|
73
74
|
|
|
74
|
-
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (virtualizerInstanceRef) {
|
|
77
|
+
virtualizerInstanceRef.current = virtualizer;
|
|
78
|
+
}
|
|
79
|
+
}, [virtualizer]);
|
|
80
|
+
|
|
81
|
+
// const virtualizer: Virtualizer = enableRowVirtualization
|
|
75
82
|
// ? useVirtualizer({
|
|
76
83
|
// count: rows.length,
|
|
77
84
|
// estimateSize: () => (density === 'compact' ? 25 : 50),
|
|
@@ -81,12 +88,10 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
81
88
|
// })
|
|
82
89
|
// : ({} as any);
|
|
83
90
|
|
|
84
|
-
const virtualRows = enableRowVirtualization
|
|
85
|
-
? rowVirtualizer.virtualItems
|
|
86
|
-
: [];
|
|
91
|
+
const virtualRows = enableRowVirtualization ? virtualizer.virtualItems : [];
|
|
87
92
|
|
|
88
93
|
// const virtualRows = enableRowVirtualization
|
|
89
|
-
// ?
|
|
94
|
+
// ? virtualizer.getVirtualItems()
|
|
90
95
|
// : [];
|
|
91
96
|
|
|
92
97
|
let paddingTop = 0;
|
|
@@ -94,13 +99,13 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
94
99
|
if (enableRowVirtualization) {
|
|
95
100
|
paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
|
|
96
101
|
paddingBottom = !!virtualRows.length
|
|
97
|
-
?
|
|
102
|
+
? virtualizer.totalSize - virtualRows[virtualRows.length - 1].end
|
|
98
103
|
: 0;
|
|
99
104
|
}
|
|
100
105
|
// if (enableRowVirtualization) {
|
|
101
106
|
// paddingTop = !!virtualRows.length ? virtualRows[0].start : 0;
|
|
102
107
|
// paddingBottom = !!virtualRows.length
|
|
103
|
-
// ?
|
|
108
|
+
// ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
|
|
104
109
|
// : 0;
|
|
105
110
|
// }
|
|
106
111
|
|
|
@@ -28,8 +28,13 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
28
28
|
},
|
|
29
29
|
setHoveredColumn,
|
|
30
30
|
} = table;
|
|
31
|
-
const {
|
|
32
|
-
|
|
31
|
+
const {
|
|
32
|
+
density,
|
|
33
|
+
draggingColumn,
|
|
34
|
+
grouping,
|
|
35
|
+
hoveredColumn,
|
|
36
|
+
showColumnFilters,
|
|
37
|
+
} = getState();
|
|
33
38
|
const { column } = header;
|
|
34
39
|
const { columnDef } = column;
|
|
35
40
|
const { columnDefType } = columnDef;
|
|
@@ -221,17 +226,20 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
221
226
|
</Box>
|
|
222
227
|
{columnDefType !== 'group' && (
|
|
223
228
|
<Box sx={{ whiteSpace: 'nowrap' }}>
|
|
224
|
-
{
|
|
225
|
-
columnDef.enableColumnDragging !== false
|
|
226
|
-
(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
229
|
+
{enableColumnDragging !== false &&
|
|
230
|
+
columnDef.enableColumnDragging !== false &&
|
|
231
|
+
(enableColumnDragging ||
|
|
232
|
+
(enableColumnOrdering &&
|
|
233
|
+
columnDef.enableColumnOrdering !== false) ||
|
|
234
|
+
(enableGrouping &&
|
|
235
|
+
columnDef.enableGrouping !== false &&
|
|
236
|
+
!grouping.includes(column.id))) && (
|
|
237
|
+
<MRT_TableHeadCellGrabHandle
|
|
238
|
+
column={column}
|
|
239
|
+
table={table}
|
|
240
|
+
tableHeadCellRef={tableHeadCellRef}
|
|
241
|
+
/>
|
|
242
|
+
)}
|
|
235
243
|
{(enableColumnActions || columnDef.enableColumnActions) &&
|
|
236
244
|
columnDef.enableColumnActions !== false && (
|
|
237
245
|
<MRT_TableHeadCellColumnActionsButton
|
|
@@ -13,14 +13,22 @@ export const MRT_ToolbarDropZone: FC<Props> = ({ table }) => {
|
|
|
13
13
|
setHoveredColumn,
|
|
14
14
|
} = table;
|
|
15
15
|
|
|
16
|
-
const { draggingColumn, hoveredColumn } = getState();
|
|
16
|
+
const { draggingColumn, hoveredColumn, grouping } = getState();
|
|
17
17
|
|
|
18
18
|
const handleDragEnter = (_event: DragEvent<HTMLDivElement>) => {
|
|
19
19
|
setHoveredColumn({ id: 'drop-zone' });
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<Fade
|
|
23
|
+
<Fade
|
|
24
|
+
unmountOnExit
|
|
25
|
+
mountOnEnter
|
|
26
|
+
in={
|
|
27
|
+
!!enableGrouping &&
|
|
28
|
+
!!draggingColumn &&
|
|
29
|
+
!grouping.includes(draggingColumn.id)
|
|
30
|
+
}
|
|
31
|
+
>
|
|
24
32
|
<Box
|
|
25
33
|
sx={(theme) => ({
|
|
26
34
|
alignItems: 'center',
|