material-react-table 2.4.0 → 2.5.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/index.d.ts +54 -31
- package/dist/index.esm.js +202 -148
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +205 -151
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/body/MRT_TableBody.tsx +5 -12
- package/src/body/MRT_TableBodyCell.tsx +12 -17
- package/src/body/MRT_TableBodyCellValue.tsx +7 -1
- package/src/body/MRT_TableBodyRow.tsx +2 -3
- package/src/column.utils.ts +2 -1
- package/src/footer/MRT_TableFooter.tsx +0 -4
- package/src/footer/MRT_TableFooterRow.tsx +2 -4
- package/src/head/MRT_TableHead.tsx +0 -4
- package/src/head/MRT_TableHeadRow.tsx +2 -4
- package/src/hooks/useMRT_ColumnVirtualizer.ts +29 -26
- package/src/hooks/useMRT_DisplayColumns.tsx +67 -6
- package/src/hooks/useMRT_RowVirtualizer.ts +7 -3
- package/src/inputs/MRT_FilterTextField.tsx +3 -2
- package/src/inputs/MRT_SelectCheckbox.tsx +44 -21
- package/src/menus/MRT_ColumnActionMenu.tsx +8 -1
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +2 -1
- package/src/style.utils.ts +0 -19
- package/src/table/MRT_Table.tsx +0 -5
- package/src/toolbar/MRT_TablePagination.tsx +45 -33
- package/src/toolbar/MRT_TopToolbar.tsx +16 -4
- package/src/types.ts +49 -21
@@ -67,6 +67,7 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
|
|
67
67
|
renderColumnActionsMenuItems,
|
68
68
|
},
|
69
69
|
refs: { filterInputRefs },
|
70
|
+
setColumnFilterFns,
|
70
71
|
setColumnOrder,
|
71
72
|
setColumnSizingInfo,
|
72
73
|
setShowColumnFilters,
|
@@ -119,8 +120,14 @@ export const MRT_ColumnActionMenu = <TData extends MRT_RowData>({
|
|
119
120
|
};
|
120
121
|
|
121
122
|
const handleClearFilter = () => {
|
122
|
-
column.setFilterValue(
|
123
|
+
column.setFilterValue(undefined);
|
123
124
|
setAnchorEl(null);
|
125
|
+
if (['empty', 'notEmpty'].includes(columnDef._filterFn)) {
|
126
|
+
setColumnFilterFns((prev) => ({
|
127
|
+
...prev,
|
128
|
+
[header.id]: allowedColumnFilterOptions?.[0] ?? 'fuzzy',
|
129
|
+
}));
|
130
|
+
}
|
124
131
|
};
|
125
132
|
|
126
133
|
const handleFilterByColumn = () => {
|
@@ -89,8 +89,9 @@ export const MRT_ShowHideColumnsMenuItems = <TData extends MRT_RowData>({
|
|
89
89
|
}
|
90
90
|
};
|
91
91
|
|
92
|
-
if (!columnDef.header || columnDef.visibleInShowHideMenu === false)
|
92
|
+
if (!columnDef.header || columnDef.visibleInShowHideMenu === false) {
|
93
93
|
return null;
|
94
|
+
}
|
94
95
|
|
95
96
|
return (
|
96
97
|
<>
|
package/src/style.utils.ts
CHANGED
@@ -90,25 +90,6 @@ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
|
|
90
90
|
column.getIsPinned() === 'left'
|
91
91
|
? `${column.getStart('left')}px`
|
92
92
|
: undefined,
|
93
|
-
ml:
|
94
|
-
table.options.enableColumnVirtualization &&
|
95
|
-
column.getIsPinned() === 'left' &&
|
96
|
-
column.getPinnedIndex() === 0
|
97
|
-
? `-${
|
98
|
-
column.getSize() *
|
99
|
-
(table.getState().columnPinning.left?.length ?? 1)
|
100
|
-
}px`
|
101
|
-
: undefined,
|
102
|
-
mr:
|
103
|
-
table.options.enableColumnVirtualization &&
|
104
|
-
column.getIsPinned() === 'right' &&
|
105
|
-
column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
|
106
|
-
? `-${
|
107
|
-
column.getSize() *
|
108
|
-
(table.getState().columnPinning.right?.length ?? 1) *
|
109
|
-
1.2
|
110
|
-
}px`
|
111
|
-
: undefined,
|
112
93
|
opacity:
|
113
94
|
table.getState().draggingColumn?.id === column.id ||
|
114
95
|
table.getState().hoveredColumn?.id === column.id
|
package/src/table/MRT_Table.tsx
CHANGED
@@ -53,14 +53,9 @@ export const MRT_Table = <TData extends MRT_RowData>({
|
|
53
53
|
|
54
54
|
const columnVirtualizer = useMRT_ColumnVirtualizer(table);
|
55
55
|
|
56
|
-
const virtualColumns = columnVirtualizer
|
57
|
-
? columnVirtualizer.getVirtualItems()
|
58
|
-
: undefined;
|
59
|
-
|
60
56
|
const commonTableGroupProps = {
|
61
57
|
columnVirtualizer,
|
62
58
|
table,
|
63
|
-
virtualColumns,
|
64
59
|
};
|
65
60
|
|
66
61
|
return (
|
@@ -4,7 +4,7 @@ import InputLabel from '@mui/material/InputLabel';
|
|
4
4
|
import MenuItem from '@mui/material/MenuItem';
|
5
5
|
import Pagination, { type PaginationProps } from '@mui/material/Pagination';
|
6
6
|
import PaginationItem from '@mui/material/PaginationItem';
|
7
|
-
import Select from '@mui/material/Select';
|
7
|
+
import Select, { type SelectProps } from '@mui/material/Select';
|
8
8
|
import Tooltip from '@mui/material/Tooltip';
|
9
9
|
import Typography from '@mui/material/Typography';
|
10
10
|
import { parseFromValuesOrFunc } from '../column.utils';
|
@@ -15,6 +15,7 @@ const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
|
|
15
15
|
interface Props<TData extends MRT_RowData>
|
16
16
|
extends Partial<
|
17
17
|
PaginationProps & {
|
18
|
+
SelectProps?: Partial<SelectProps>;
|
18
19
|
disabled?: boolean;
|
19
20
|
rowsPerPageOptions?: { label: string; value: number }[] | number[];
|
20
21
|
showRowsPerPage?: boolean;
|
@@ -71,6 +72,9 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
71
72
|
..._rest
|
72
73
|
} = paginationProps ?? {};
|
73
74
|
|
75
|
+
const disableBack = pageIndex <= 0 || disabled;
|
76
|
+
const disableNext = lastRowIndex >= totalRowCount || disabled;
|
77
|
+
|
74
78
|
return (
|
75
79
|
<Box
|
76
80
|
className="MuiTablePagination-root"
|
@@ -165,47 +169,55 @@ export const MRT_TablePagination = <TData extends MRT_RowData>({
|
|
165
169
|
} ${totalRowCount.toLocaleString()}`}</Typography>
|
166
170
|
<Box gap="xs">
|
167
171
|
{showFirstButton && (
|
168
|
-
<Tooltip title={localization.goToFirstPage}>
|
172
|
+
<Tooltip enterDelay={1000} title={localization.goToFirstPage}>
|
173
|
+
<span>
|
174
|
+
<IconButton
|
175
|
+
aria-label={localization.goToFirstPage}
|
176
|
+
disabled={disableBack}
|
177
|
+
onClick={() => setPageIndex(0)}
|
178
|
+
size="small"
|
179
|
+
>
|
180
|
+
<FirstPageIcon />
|
181
|
+
</IconButton>
|
182
|
+
</span>
|
183
|
+
</Tooltip>
|
184
|
+
)}
|
185
|
+
<Tooltip enterDelay={1000} title={localization.goToPreviousPage}>
|
186
|
+
<span>
|
169
187
|
<IconButton
|
170
|
-
aria-label={localization.
|
171
|
-
disabled={
|
172
|
-
onClick={() => setPageIndex(
|
188
|
+
aria-label={localization.goToPreviousPage}
|
189
|
+
disabled={disableBack}
|
190
|
+
onClick={() => setPageIndex(pageIndex - 1)}
|
173
191
|
size="small"
|
174
192
|
>
|
175
|
-
<
|
193
|
+
<ChevronLeftIcon />
|
176
194
|
</IconButton>
|
177
|
-
</
|
178
|
-
)}
|
179
|
-
<Tooltip title={localization.goToPreviousPage}>
|
180
|
-
<IconButton
|
181
|
-
aria-label={localization.goToPreviousPage}
|
182
|
-
disabled={pageIndex <= 0 || disabled}
|
183
|
-
onClick={() => setPageIndex(pageIndex - 1)}
|
184
|
-
size="small"
|
185
|
-
>
|
186
|
-
<ChevronLeftIcon />
|
187
|
-
</IconButton>
|
195
|
+
</span>
|
188
196
|
</Tooltip>
|
189
|
-
<Tooltip title={localization.goToNextPage}>
|
190
|
-
<
|
191
|
-
aria-label={localization.goToNextPage}
|
192
|
-
disabled={lastRowIndex >= totalRowCount || disabled}
|
193
|
-
onClick={() => setPageIndex(pageIndex + 1)}
|
194
|
-
size="small"
|
195
|
-
>
|
196
|
-
<ChevronRightIcon />
|
197
|
-
</IconButton>
|
198
|
-
</Tooltip>
|
199
|
-
{showLastButton && (
|
200
|
-
<Tooltip title={localization.goToLastPage}>
|
197
|
+
<Tooltip enterDelay={1000} title={localization.goToNextPage}>
|
198
|
+
<span>
|
201
199
|
<IconButton
|
202
|
-
aria-label={localization.
|
203
|
-
disabled={
|
204
|
-
onClick={() => setPageIndex(
|
200
|
+
aria-label={localization.goToNextPage}
|
201
|
+
disabled={disableNext}
|
202
|
+
onClick={() => setPageIndex(pageIndex + 1)}
|
205
203
|
size="small"
|
206
204
|
>
|
207
|
-
<
|
205
|
+
<ChevronRightIcon />
|
208
206
|
</IconButton>
|
207
|
+
</span>
|
208
|
+
</Tooltip>
|
209
|
+
{showLastButton && (
|
210
|
+
<Tooltip enterDelay={1000} title={localization.goToLastPage}>
|
211
|
+
<span>
|
212
|
+
<IconButton
|
213
|
+
aria-label={localization.goToLastPage}
|
214
|
+
disabled={disableNext}
|
215
|
+
onClick={() => setPageIndex(numberOfPages - 1)}
|
216
|
+
size="small"
|
217
|
+
>
|
218
|
+
<LastPageIcon />
|
219
|
+
</IconButton>
|
220
|
+
</span>
|
209
221
|
</Tooltip>
|
210
222
|
)}
|
211
223
|
</Box>
|
@@ -36,11 +36,23 @@ export const MRT_TopToolbar = <TData extends MRT_RowData>({
|
|
36
36
|
const { isFullScreen, showGlobalFilter } = getState();
|
37
37
|
|
38
38
|
const isMobile = useMediaQuery('(max-width:720px)');
|
39
|
+
const isTablet = useMediaQuery('(max-width:1024px)');
|
39
40
|
|
40
41
|
const toolbarProps = parseFromValuesOrFunc(muiTopToolbarProps, { table });
|
41
42
|
|
42
43
|
const stackAlertBanner =
|
43
|
-
isMobile ||
|
44
|
+
isMobile ||
|
45
|
+
!!renderTopToolbarCustomActions ||
|
46
|
+
(showGlobalFilter && isTablet);
|
47
|
+
|
48
|
+
const globalFilterProps = {
|
49
|
+
sx: !isTablet
|
50
|
+
? {
|
51
|
+
zIndex: 2,
|
52
|
+
}
|
53
|
+
: undefined,
|
54
|
+
table,
|
55
|
+
};
|
44
56
|
|
45
57
|
return (
|
46
58
|
<Box
|
@@ -83,7 +95,7 @@ export const MRT_TopToolbar = <TData extends MRT_RowData>({
|
|
83
95
|
}}
|
84
96
|
>
|
85
97
|
{enableGlobalFilter && positionGlobalFilter === 'left' && (
|
86
|
-
<MRT_GlobalFilterTextField
|
98
|
+
<MRT_GlobalFilterTextField {...globalFilterProps} />
|
87
99
|
)}
|
88
100
|
{renderTopToolbarCustomActions?.({ table }) ?? <span />}
|
89
101
|
{enableToolbarInternalActions ? (
|
@@ -97,14 +109,14 @@ export const MRT_TopToolbar = <TData extends MRT_RowData>({
|
|
97
109
|
}}
|
98
110
|
>
|
99
111
|
{enableGlobalFilter && positionGlobalFilter === 'right' && (
|
100
|
-
<MRT_GlobalFilterTextField
|
112
|
+
<MRT_GlobalFilterTextField {...globalFilterProps} />
|
101
113
|
)}
|
102
114
|
<MRT_ToolbarInternalButtons table={table} />
|
103
115
|
</Box>
|
104
116
|
) : (
|
105
117
|
enableGlobalFilter &&
|
106
118
|
positionGlobalFilter === 'right' && (
|
107
|
-
<MRT_GlobalFilterTextField
|
119
|
+
<MRT_GlobalFilterTextField {...globalFilterProps} />
|
108
120
|
)
|
109
121
|
)}
|
110
122
|
</Box>
|
package/src/types.ts
CHANGED
@@ -93,28 +93,30 @@ export type MRT_ColumnFilterFnsState = Record<string, MRT_FilterOption>;
|
|
93
93
|
|
94
94
|
export type MRT_RowData = Record<string, any>;
|
95
95
|
|
96
|
-
export type
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
96
|
+
export type MRT_ColumnFiltersState = ColumnFiltersState;
|
97
|
+
export type MRT_ColumnOrderState = ColumnOrderState;
|
98
|
+
export type MRT_ColumnPinningState = ColumnPinningState;
|
99
|
+
export type MRT_ColumnSizingInfoState = ColumnSizingInfoState;
|
100
|
+
export type MRT_ColumnSizingState = ColumnSizingState;
|
101
|
+
export type MRT_ExpandedState = ExpandedState;
|
102
|
+
export type MRT_GroupingState = GroupingState;
|
103
|
+
export type MRT_PaginationState = PaginationState;
|
104
|
+
export type MRT_RowSelectionState = RowSelectionState;
|
105
|
+
export type MRT_SortingState = SortingState;
|
106
|
+
export type MRT_Updater<T> = Updater<T>;
|
107
|
+
export type MRT_VirtualItem = VirtualItem;
|
108
|
+
export type MRT_VisibilityState = VisibilityState;
|
109
|
+
|
110
|
+
export type MRT_VirtualizerOptions<
|
111
|
+
TScrollElement extends Element | Window = Element | Window,
|
112
|
+
TItemElement extends Element = Element,
|
113
|
+
> = VirtualizerOptions<TScrollElement, TItemElement>;
|
113
114
|
|
114
115
|
export type MRT_ColumnVirtualizer<
|
115
116
|
TScrollElement extends Element | Window = HTMLDivElement,
|
116
117
|
TItemElement extends Element = HTMLTableCellElement,
|
117
118
|
> = Virtualizer<TScrollElement, TItemElement> & {
|
119
|
+
virtualColumns: MRT_VirtualItem[];
|
118
120
|
virtualPaddingLeft?: number;
|
119
121
|
virtualPaddingRight?: number;
|
120
122
|
};
|
@@ -122,7 +124,16 @@ export type MRT_ColumnVirtualizer<
|
|
122
124
|
export type MRT_RowVirtualizer<
|
123
125
|
TScrollElement extends Element | Window = HTMLDivElement,
|
124
126
|
TItemElement extends Element = HTMLTableRowElement,
|
125
|
-
> = Virtualizer<TScrollElement, TItemElement
|
127
|
+
> = Virtualizer<TScrollElement, TItemElement> & {
|
128
|
+
virtualRows: MRT_VirtualItem[];
|
129
|
+
};
|
130
|
+
|
131
|
+
/**
|
132
|
+
* @deprecated use `MRT_ColumnVirtualizer` or `MRT_RowVirtualizer` instead
|
133
|
+
*/
|
134
|
+
export type MRT_Virtualizer<_TScrollElement = any, _TItemElement = any> =
|
135
|
+
| MRT_ColumnVirtualizer
|
136
|
+
| MRT_RowVirtualizer;
|
126
137
|
|
127
138
|
export type MRT_ColumnHelper<TData extends MRT_RowData> = {
|
128
139
|
accessor: <
|
@@ -374,6 +385,7 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
374
385
|
renderedCellValue: ReactNode;
|
375
386
|
row: MRT_Row<TData>;
|
376
387
|
rowRef?: RefObject<HTMLTableRowElement>;
|
388
|
+
staticRowIndex?: number;
|
377
389
|
table: MRT_TableInstance<TData>;
|
378
390
|
}) => ReactNode;
|
379
391
|
Edit?: (props: {
|
@@ -663,10 +675,19 @@ export type MRT_HeaderGroup<TData extends MRT_RowData> = Omit<
|
|
663
675
|
|
664
676
|
export type MRT_Row<TData extends MRT_RowData> = Omit<
|
665
677
|
Row<TData>,
|
666
|
-
|
678
|
+
| '_valuesCache'
|
679
|
+
| 'getAllCells'
|
680
|
+
| 'getParentRow'
|
681
|
+
| 'getParentRows'
|
682
|
+
| 'getRow'
|
683
|
+
| 'getVisibleCells'
|
684
|
+
| 'subRows'
|
667
685
|
> & {
|
668
686
|
_valuesCache: Record<LiteralUnion<string & DeepKeys<TData>>, any>;
|
669
687
|
getAllCells: () => MRT_Cell<TData>[];
|
688
|
+
getParentRow: () => MRT_Row<TData> | null;
|
689
|
+
getParentRows: () => MRT_Row<TData>[];
|
690
|
+
getRow: () => MRT_Row<TData>;
|
670
691
|
getVisibleCells: () => MRT_Cell<TData>[];
|
671
692
|
subRows?: MRT_Row<TData>[];
|
672
693
|
};
|
@@ -743,7 +764,9 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
743
764
|
columnFilterModeOptions?: Array<
|
744
765
|
LiteralUnion<string & MRT_FilterOption>
|
745
766
|
> | null;
|
746
|
-
columnVirtualizerInstanceRef?: MutableRefObject<
|
767
|
+
columnVirtualizerInstanceRef?: MutableRefObject<
|
768
|
+
MRT_ColumnVirtualizer | MRT_Virtualizer | null
|
769
|
+
>;
|
747
770
|
columnVirtualizerOptions?:
|
748
771
|
| ((props: {
|
749
772
|
table: MRT_TableInstance<TData>;
|
@@ -955,6 +978,7 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
955
978
|
| ((props: { table: MRT_TableInstance<TData> }) => Partial<
|
956
979
|
PaginationProps & {
|
957
980
|
SelectProps?: Partial<SelectProps>;
|
981
|
+
disabled?: boolean;
|
958
982
|
rowsPerPageOptions?: { label: string; value: number }[] | number[];
|
959
983
|
showRowsPerPage?: boolean;
|
960
984
|
}
|
@@ -962,6 +986,7 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
962
986
|
| Partial<
|
963
987
|
PaginationProps & {
|
964
988
|
SelectProps?: Partial<SelectProps>;
|
989
|
+
disabled?: boolean;
|
965
990
|
rowsPerPageOptions?: { label: string; value: number }[] | number[];
|
966
991
|
showRowsPerPage?: boolean;
|
967
992
|
}
|
@@ -981,6 +1006,7 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
981
1006
|
muiSelectCheckboxProps?:
|
982
1007
|
| ((props: {
|
983
1008
|
row: MRT_Row<TData>;
|
1009
|
+
staticRowIndex?: number;
|
984
1010
|
table: MRT_TableInstance<TData>;
|
985
1011
|
}) => CheckboxProps | RadioProps)
|
986
1012
|
| (CheckboxProps | RadioProps);
|
@@ -1175,7 +1201,9 @@ export type MRT_TableOptions<TData extends MRT_RowData> = Omit<
|
|
1175
1201
|
| 'sticky'
|
1176
1202
|
| 'top'
|
1177
1203
|
| 'top-and-bottom';
|
1178
|
-
rowVirtualizerInstanceRef?: MutableRefObject<
|
1204
|
+
rowVirtualizerInstanceRef?: MutableRefObject<
|
1205
|
+
MRT_RowVirtualizer | MRT_Virtualizer | null
|
1206
|
+
>;
|
1179
1207
|
rowVirtualizerOptions?:
|
1180
1208
|
| ((props: {
|
1181
1209
|
table: MRT_TableInstance<TData>;
|