material-react-table 1.9.2 → 1.9.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/README.md +1 -1
- package/dist/cjs/index.js +28 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +2 -2
- package/dist/esm/material-react-table.esm.js +28 -11
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +2 -2
- package/src/buttons/MRT_ToggleFiltersButton.tsx +2 -2
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +2 -2
- package/src/inputs/MRT_GlobalFilterTextField.tsx +9 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
- package/src/table/MRT_TableRoot.tsx +14 -2
- package/src/toolbar/MRT_TablePagination.tsx +4 -1
@@ -179,7 +179,7 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Prettify
|
|
179
179
|
} | null>>;
|
180
180
|
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
181
181
|
setShowAlertBanner: Dispatch<SetStateAction<boolean>>;
|
182
|
-
|
182
|
+
setShowColumnFilters: Dispatch<SetStateAction<boolean>>;
|
183
183
|
setShowGlobalFilter: Dispatch<SetStateAction<boolean>>;
|
184
184
|
setShowToolbarDropZone: Dispatch<SetStateAction<boolean>>;
|
185
185
|
}>;
|
@@ -656,7 +656,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Pr
|
|
656
656
|
onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
657
657
|
onIsFullScreenChange?: OnChangeFn<boolean>;
|
658
658
|
onShowAlertBannerChange?: OnChangeFn<boolean>;
|
659
|
-
|
659
|
+
onShowColumnFiltersChange?: OnChangeFn<boolean>;
|
660
660
|
onShowGlobalFilterChange?: OnChangeFn<boolean>;
|
661
661
|
onShowToolbarDropZoneChange?: OnChangeFn<boolean>;
|
662
662
|
positionActionsColumn?: 'first' | 'last';
|
@@ -834,7 +834,7 @@ const commonListItemStyles = {
|
|
834
834
|
};
|
835
835
|
const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
836
836
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
837
|
-
const { getState, toggleAllColumnsVisible, setColumnOrder, options: { columnFilterModeOptions, enableColumnFilterModes, enableColumnFilters, enableColumnResizing, enableGrouping, enableHiding, enablePinning, enableSorting, icons: { ArrowRightIcon, ClearAllIcon, ViewColumnIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, SortIcon, RestartAltIcon, VisibilityOffIcon, }, localization, renderColumnActionsMenuItems, }, refs: { filterInputRefs }, setColumnSizingInfo,
|
837
|
+
const { getState, toggleAllColumnsVisible, setColumnOrder, options: { columnFilterModeOptions, enableColumnFilterModes, enableColumnFilters, enableColumnResizing, enableGrouping, enableHiding, enablePinning, enableSorting, icons: { ArrowRightIcon, ClearAllIcon, ViewColumnIcon, DynamicFeedIcon, FilterListIcon, FilterListOffIcon, PushPinIcon, SortIcon, RestartAltIcon, VisibilityOffIcon, }, localization, renderColumnActionsMenuItems, }, refs: { filterInputRefs }, setColumnSizingInfo, setShowColumnFilters, } = table;
|
838
838
|
const { column } = header;
|
839
839
|
const { columnDef } = column;
|
840
840
|
const { columnSizing, columnVisibility, density } = getState();
|
@@ -875,7 +875,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
875
875
|
setAnchorEl(null);
|
876
876
|
};
|
877
877
|
const handleFilterByColumn = () => {
|
878
|
-
|
878
|
+
setShowColumnFilters(true);
|
879
879
|
queueMicrotask(() => { var _a; return (_a = filterInputRefs.current[`${column.id}-0`]) === null || _a === void 0 ? void 0 : _a.focus(); });
|
880
880
|
setAnchorEl(null);
|
881
881
|
};
|
@@ -1131,6 +1131,7 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
|
|
1131
1131
|
const textFieldProps = muiSearchTextFieldProps instanceof Function
|
1132
1132
|
? muiSearchTextFieldProps({ table })
|
1133
1133
|
: muiSearchTextFieldProps;
|
1134
|
+
const isMounted = useRef(false);
|
1134
1135
|
const [anchorEl, setAnchorEl] = useState(null);
|
1135
1136
|
const [searchValue, setSearchValue] = useState(globalFilter !== null && globalFilter !== void 0 ? globalFilter : '');
|
1136
1137
|
const handleChangeDebounced = useCallback(debounce((event) => {
|
@@ -1149,9 +1150,15 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
|
|
1149
1150
|
setGlobalFilter(undefined);
|
1150
1151
|
};
|
1151
1152
|
useEffect(() => {
|
1152
|
-
if (
|
1153
|
-
|
1153
|
+
if (isMounted.current) {
|
1154
|
+
if (globalFilter === undefined) {
|
1155
|
+
handleClear();
|
1156
|
+
}
|
1157
|
+
else {
|
1158
|
+
setSearchValue(globalFilter);
|
1159
|
+
}
|
1154
1160
|
}
|
1161
|
+
isMounted.current = true;
|
1155
1162
|
}, [globalFilter]);
|
1156
1163
|
return (React.createElement(Collapse, { in: showGlobalFilter, orientation: "horizontal", unmountOnExit: true, mountOnEnter: true },
|
1157
1164
|
React.createElement(TextField, Object.assign({ placeholder: localization.search, onChange: handleChange, value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "standard", InputProps: {
|
@@ -1205,7 +1212,7 @@ const MRT_TablePagination = ({ table, position = 'bottom', }) => {
|
|
1205
1212
|
? localization.goToLastPage
|
1206
1213
|
: type === 'next'
|
1207
1214
|
? localization.goToNextPage
|
1208
|
-
: localization.goToPreviousPage, labelDisplayedRows: ({ from, to, count }) => `${from}-${to} ${localization.of} ${count}`, labelRowsPerPage: localization.rowsPerPage, onPageChange: (_, newPage) => setPageIndex(newPage), onRowsPerPageChange: handleChangeRowsPerPage, page: pageIndex, rowsPerPage: pageSize, rowsPerPageOptions: [5, 10, 15, 20, 25, 30, 50, 100], showFirstButton: showFirstLastPageButtons, showLastButton: showFirstLastPageButtons }, tablePaginationProps, { SelectProps: Object.assign({ sx: { m: '0 1rem 0 1ch' }, MenuProps: { MenuListProps: { disablePadding: true }, sx: { m: 0 } } }, tablePaginationProps === null || tablePaginationProps === void 0 ? void 0 : tablePaginationProps.SelectProps), sx: (theme) => (Object.assign({ '& .MuiTablePagination-toolbar': {
|
1215
|
+
: localization.goToPreviousPage, labelDisplayedRows: ({ from, to, count }) => `${from}-${to} ${localization.of} ${count}`, labelRowsPerPage: localization.rowsPerPage, onPageChange: (_, newPage) => setPageIndex(newPage), onRowsPerPageChange: handleChangeRowsPerPage, page: Math.max(Math.min(pageIndex, Math.ceil(totalRowCount / pageSize) - 1), 0), rowsPerPage: pageSize, rowsPerPageOptions: [5, 10, 15, 20, 25, 30, 50, 100], showFirstButton: showFirstLastPageButtons, showLastButton: showFirstLastPageButtons }, tablePaginationProps, { SelectProps: Object.assign({ sx: { m: '0 1rem 0 1ch' }, MenuProps: { MenuListProps: { disablePadding: true }, sx: { m: 0 } } }, tablePaginationProps === null || tablePaginationProps === void 0 ? void 0 : tablePaginationProps.SelectProps), sx: (theme) => (Object.assign({ '& .MuiTablePagination-toolbar': {
|
1209
1216
|
display: 'flex',
|
1210
1217
|
alignItems: 'center',
|
1211
1218
|
}, '& .MuiTablePagination-selectLabel': {
|
@@ -1310,10 +1317,10 @@ const MRT_ToggleDensePaddingButton = (_a) => {
|
|
1310
1317
|
const MRT_ToggleFiltersButton = (_a) => {
|
1311
1318
|
var _b;
|
1312
1319
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
1313
|
-
const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, },
|
1320
|
+
const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, }, setShowColumnFilters, } = table;
|
1314
1321
|
const { showColumnFilters } = getState();
|
1315
1322
|
const handleToggleShowFilters = () => {
|
1316
|
-
|
1323
|
+
setShowColumnFilters(!showColumnFilters);
|
1317
1324
|
};
|
1318
1325
|
return (React.createElement(Tooltip, { arrow: true, title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.showHideFilters },
|
1319
1326
|
React.createElement(IconButton, Object.assign({ "aria-label": localization.showHideFilters, onClick: handleToggleShowFilters }, rest, { title: undefined }), showColumnFilters ? React.createElement(FilterListOffIcon, null) : React.createElement(FilterListIcon, null))));
|
@@ -1777,7 +1784,7 @@ const MRT_TableHeadCellFilterContainer = ({ header, table }) => {
|
|
1777
1784
|
|
1778
1785
|
const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
1779
1786
|
var _a, _b, _c;
|
1780
|
-
const { options: { icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs },
|
1787
|
+
const { options: { icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs }, setShowColumnFilters, } = table;
|
1781
1788
|
const { column } = header;
|
1782
1789
|
const { columnDef } = column;
|
1783
1790
|
const isRangeFilter = columnDef.filterVariant === 'range' ||
|
@@ -1799,7 +1806,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
|
1799
1806
|
React.createElement(Box, { component: "span", sx: { flex: '0 0' } },
|
1800
1807
|
React.createElement(Tooltip, { arrow: true, placement: "top", title: filterTooltip },
|
1801
1808
|
React.createElement(IconButton, { disableRipple: true, onClick: (event) => {
|
1802
|
-
|
1809
|
+
setShowColumnFilters(true);
|
1803
1810
|
queueMicrotask(() => {
|
1804
1811
|
var _a, _b;
|
1805
1812
|
(_a = filterInputRefs.current[`${column.id}-0`]) === null || _a === void 0 ? void 0 : _a.focus();
|
@@ -2893,7 +2900,7 @@ const MRT_TableRoot = (props) => {
|
|
2893
2900
|
const [hoveredRow, setHoveredRow] = useState((_k = initialState.hoveredRow) !== null && _k !== void 0 ? _k : null);
|
2894
2901
|
const [isFullScreen, setIsFullScreen] = useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _l !== void 0 ? _l : false);
|
2895
2902
|
const [showAlertBanner, setShowAlertBanner] = useState((_o = (_m = props.initialState) === null || _m === void 0 ? void 0 : _m.showAlertBanner) !== null && _o !== void 0 ? _o : false);
|
2896
|
-
const [showColumnFilters,
|
2903
|
+
const [showColumnFilters, setShowColumnFilters] = useState((_p = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _p !== void 0 ? _p : false);
|
2897
2904
|
const [showGlobalFilter, setShowGlobalFilter] = useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _q !== void 0 ? _q : false);
|
2898
2905
|
const [showToolbarDropZone, setShowToolbarDropZone] = useState((_r = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _r !== void 0 ? _r : false);
|
2899
2906
|
const displayColumns = useMemo(() => {
|
@@ -2990,7 +2997,7 @@ const MRT_TableRoot = (props) => {
|
|
2990
2997
|
tableHeadCellRefs,
|
2991
2998
|
tablePaperRef,
|
2992
2999
|
topToolbarRef,
|
2993
|
-
}, setColumnFilterFns: (_0 = props.onColumnFilterFnsChange) !== null && _0 !== void 0 ? _0 : setColumnFilterFns, setDensity: (_1 = props.onDensityChange) !== null && _1 !== void 0 ? _1 : setDensity, setDraggingColumn: (_2 = props.onDraggingColumnChange) !== null && _2 !== void 0 ? _2 : setDraggingColumn, setDraggingRow: (_3 = props.onDraggingRowChange) !== null && _3 !== void 0 ? _3 : setDraggingRow, setEditingCell: (_4 = props.onEditingCellChange) !== null && _4 !== void 0 ? _4 : setEditingCell, setEditingRow: (_5 = props.onEditingRowChange) !== null && _5 !== void 0 ? _5 : setEditingRow, setGlobalFilterFn: (_6 = props.onGlobalFilterFnChange) !== null && _6 !== void 0 ? _6 : setGlobalFilterFn, setHoveredColumn: (_7 = props.onHoveredColumnChange) !== null && _7 !== void 0 ? _7 : setHoveredColumn, setHoveredRow: (_8 = props.onHoveredRowChange) !== null && _8 !== void 0 ? _8 : setHoveredRow, setIsFullScreen: (_9 = props.onIsFullScreenChange) !== null && _9 !== void 0 ? _9 : setIsFullScreen, setShowAlertBanner: (_10 = props.onShowAlertBannerChange) !== null && _10 !== void 0 ? _10 : setShowAlertBanner,
|
3000
|
+
}, setColumnFilterFns: (_0 = props.onColumnFilterFnsChange) !== null && _0 !== void 0 ? _0 : setColumnFilterFns, setDensity: (_1 = props.onDensityChange) !== null && _1 !== void 0 ? _1 : setDensity, setDraggingColumn: (_2 = props.onDraggingColumnChange) !== null && _2 !== void 0 ? _2 : setDraggingColumn, setDraggingRow: (_3 = props.onDraggingRowChange) !== null && _3 !== void 0 ? _3 : setDraggingRow, setEditingCell: (_4 = props.onEditingCellChange) !== null && _4 !== void 0 ? _4 : setEditingCell, setEditingRow: (_5 = props.onEditingRowChange) !== null && _5 !== void 0 ? _5 : setEditingRow, setGlobalFilterFn: (_6 = props.onGlobalFilterFnChange) !== null && _6 !== void 0 ? _6 : setGlobalFilterFn, setHoveredColumn: (_7 = props.onHoveredColumnChange) !== null && _7 !== void 0 ? _7 : setHoveredColumn, setHoveredRow: (_8 = props.onHoveredRowChange) !== null && _8 !== void 0 ? _8 : setHoveredRow, setIsFullScreen: (_9 = props.onIsFullScreenChange) !== null && _9 !== void 0 ? _9 : setIsFullScreen, setShowAlertBanner: (_10 = props.onShowAlertBannerChange) !== null && _10 !== void 0 ? _10 : setShowAlertBanner, setShowColumnFilters: (_11 = props.onShowColumnFiltersChange) !== null && _11 !== void 0 ? _11 : setShowColumnFilters, setShowGlobalFilter: (_12 = props.onShowGlobalFilterChange) !== null && _12 !== void 0 ? _12 : setShowGlobalFilter, setShowToolbarDropZone: (_13 = props.onShowToolbarDropZoneChange) !== null && _13 !== void 0 ? _13 : setShowToolbarDropZone });
|
2994
3001
|
if (props.tableFeatures) {
|
2995
3002
|
props.tableFeatures.forEach((feature) => {
|
2996
3003
|
Object.assign(table, feature(table));
|
@@ -3015,6 +3022,16 @@ const MRT_TableRoot = (props) => {
|
|
3015
3022
|
}
|
3016
3023
|
}
|
3017
3024
|
}, [table.getState().isFullScreen]);
|
3025
|
+
//if page index is out of bounds, set it to the last page
|
3026
|
+
useEffect(() => {
|
3027
|
+
var _a;
|
3028
|
+
const { pageIndex, pageSize } = table.getState().pagination;
|
3029
|
+
const totalRowCount = (_a = props.rowCount) !== null && _a !== void 0 ? _a : table.getPrePaginationRowModel().rows.length;
|
3030
|
+
const firstVisibleRowIndex = pageIndex * pageSize;
|
3031
|
+
if (firstVisibleRowIndex > totalRowCount) {
|
3032
|
+
table.setPageIndex(Math.floor(totalRowCount / pageSize));
|
3033
|
+
}
|
3034
|
+
}, [props.rowCount, table.getPrePaginationRowModel().rows.length]);
|
3018
3035
|
return (React.createElement(React.Fragment, null,
|
3019
3036
|
React.createElement(Dialog, { PaperComponent: Box, TransitionComponent: !props.enableRowVirtualization ? Grow : undefined, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => table.setIsFullScreen(false), open: table.getState().isFullScreen, transitionDuration: 400 },
|
3020
3037
|
React.createElement(MRT_TablePaper, { table: table })),
|