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
package/README.md
CHANGED
@@ -59,7 +59,7 @@ _All features can easily be enabled/disabled_
|
|
59
59
|
|
60
60
|
_**Fully Fleshed out [Docs](https://www.material-react-table.com/docs/guides#guides) are available for all features**_
|
61
61
|
|
62
|
-
- [x] <
|
62
|
+
- [x] < 45kb gzipped - [Bundlephobia](https://bundlephobia.com/package/material-react-table)
|
63
63
|
- [x] Advanced TypeScript Generics Support (TypeScript Optional)
|
64
64
|
- [x] Aggregation and Grouping (Sum, Average, Count, etc.)
|
65
65
|
- [x] Click To Copy Cell Values
|
package/dist/cjs/index.js
CHANGED
@@ -912,7 +912,7 @@ const commonListItemStyles = {
|
|
912
912
|
};
|
913
913
|
const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
914
914
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
915
|
-
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,
|
915
|
+
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;
|
916
916
|
const { column } = header;
|
917
917
|
const { columnDef } = column;
|
918
918
|
const { columnSizing, columnVisibility, density } = getState();
|
@@ -953,7 +953,7 @@ const MRT_ColumnActionMenu = ({ anchorEl, header, setAnchorEl, table, }) => {
|
|
953
953
|
setAnchorEl(null);
|
954
954
|
};
|
955
955
|
const handleFilterByColumn = () => {
|
956
|
-
|
956
|
+
setShowColumnFilters(true);
|
957
957
|
queueMicrotask(() => { var _a; return (_a = filterInputRefs.current[`${column.id}-0`]) === null || _a === void 0 ? void 0 : _a.focus(); });
|
958
958
|
setAnchorEl(null);
|
959
959
|
};
|
@@ -1209,6 +1209,7 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
|
|
1209
1209
|
const textFieldProps = muiSearchTextFieldProps instanceof Function
|
1210
1210
|
? muiSearchTextFieldProps({ table })
|
1211
1211
|
: muiSearchTextFieldProps;
|
1212
|
+
const isMounted = React.useRef(false);
|
1212
1213
|
const [anchorEl, setAnchorEl] = React.useState(null);
|
1213
1214
|
const [searchValue, setSearchValue] = React.useState(globalFilter !== null && globalFilter !== void 0 ? globalFilter : '');
|
1214
1215
|
const handleChangeDebounced = React.useCallback(utils.debounce((event) => {
|
@@ -1227,9 +1228,15 @@ const MRT_GlobalFilterTextField = ({ table, }) => {
|
|
1227
1228
|
setGlobalFilter(undefined);
|
1228
1229
|
};
|
1229
1230
|
React.useEffect(() => {
|
1230
|
-
if (
|
1231
|
-
|
1231
|
+
if (isMounted.current) {
|
1232
|
+
if (globalFilter === undefined) {
|
1233
|
+
handleClear();
|
1234
|
+
}
|
1235
|
+
else {
|
1236
|
+
setSearchValue(globalFilter);
|
1237
|
+
}
|
1232
1238
|
}
|
1239
|
+
isMounted.current = true;
|
1233
1240
|
}, [globalFilter]);
|
1234
1241
|
return (React__default["default"].createElement(Collapse__default["default"], { in: showGlobalFilter, orientation: "horizontal", unmountOnExit: true, mountOnEnter: true },
|
1235
1242
|
React__default["default"].createElement(TextField__default["default"], Object.assign({ placeholder: localization.search, onChange: handleChange, value: searchValue !== null && searchValue !== void 0 ? searchValue : '', variant: "standard", InputProps: {
|
@@ -1283,7 +1290,7 @@ const MRT_TablePagination = ({ table, position = 'bottom', }) => {
|
|
1283
1290
|
? localization.goToLastPage
|
1284
1291
|
: type === 'next'
|
1285
1292
|
? localization.goToNextPage
|
1286
|
-
: 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': {
|
1293
|
+
: 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': {
|
1287
1294
|
display: 'flex',
|
1288
1295
|
alignItems: 'center',
|
1289
1296
|
}, '& .MuiTablePagination-selectLabel': {
|
@@ -1388,10 +1395,10 @@ const MRT_ToggleDensePaddingButton = (_a) => {
|
|
1388
1395
|
const MRT_ToggleFiltersButton = (_a) => {
|
1389
1396
|
var _b;
|
1390
1397
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
1391
|
-
const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, },
|
1398
|
+
const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, }, setShowColumnFilters, } = table;
|
1392
1399
|
const { showColumnFilters } = getState();
|
1393
1400
|
const handleToggleShowFilters = () => {
|
1394
|
-
|
1401
|
+
setShowColumnFilters(!showColumnFilters);
|
1395
1402
|
};
|
1396
1403
|
return (React__default["default"].createElement(Tooltip__default["default"], { arrow: true, title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.showHideFilters },
|
1397
1404
|
React__default["default"].createElement(IconButton__default["default"], Object.assign({ "aria-label": localization.showHideFilters, onClick: handleToggleShowFilters }, rest, { title: undefined }), showColumnFilters ? React__default["default"].createElement(FilterListOffIcon, null) : React__default["default"].createElement(FilterListIcon, null))));
|
@@ -1855,7 +1862,7 @@ const MRT_TableHeadCellFilterContainer = ({ header, table }) => {
|
|
1855
1862
|
|
1856
1863
|
const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
1857
1864
|
var _a, _b, _c;
|
1858
|
-
const { options: { icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs },
|
1865
|
+
const { options: { icons: { FilterAltIcon }, localization, }, refs: { filterInputRefs }, setShowColumnFilters, } = table;
|
1859
1866
|
const { column } = header;
|
1860
1867
|
const { columnDef } = column;
|
1861
1868
|
const isRangeFilter = columnDef.filterVariant === 'range' ||
|
@@ -1877,7 +1884,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
|
|
1877
1884
|
React__default["default"].createElement(Box__default["default"], { component: "span", sx: { flex: '0 0' } },
|
1878
1885
|
React__default["default"].createElement(Tooltip__default["default"], { arrow: true, placement: "top", title: filterTooltip },
|
1879
1886
|
React__default["default"].createElement(IconButton__default["default"], { disableRipple: true, onClick: (event) => {
|
1880
|
-
|
1887
|
+
setShowColumnFilters(true);
|
1881
1888
|
queueMicrotask(() => {
|
1882
1889
|
var _a, _b;
|
1883
1890
|
(_a = filterInputRefs.current[`${column.id}-0`]) === null || _a === void 0 ? void 0 : _a.focus();
|
@@ -2971,7 +2978,7 @@ const MRT_TableRoot = (props) => {
|
|
2971
2978
|
const [hoveredRow, setHoveredRow] = React.useState((_k = initialState.hoveredRow) !== null && _k !== void 0 ? _k : null);
|
2972
2979
|
const [isFullScreen, setIsFullScreen] = React.useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _l !== void 0 ? _l : false);
|
2973
2980
|
const [showAlertBanner, setShowAlertBanner] = React.useState((_o = (_m = props.initialState) === null || _m === void 0 ? void 0 : _m.showAlertBanner) !== null && _o !== void 0 ? _o : false);
|
2974
|
-
const [showColumnFilters,
|
2981
|
+
const [showColumnFilters, setShowColumnFilters] = React.useState((_p = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _p !== void 0 ? _p : false);
|
2975
2982
|
const [showGlobalFilter, setShowGlobalFilter] = React.useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _q !== void 0 ? _q : false);
|
2976
2983
|
const [showToolbarDropZone, setShowToolbarDropZone] = React.useState((_r = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _r !== void 0 ? _r : false);
|
2977
2984
|
const displayColumns = React.useMemo(() => {
|
@@ -3068,7 +3075,7 @@ const MRT_TableRoot = (props) => {
|
|
3068
3075
|
tableHeadCellRefs,
|
3069
3076
|
tablePaperRef,
|
3070
3077
|
topToolbarRef,
|
3071
|
-
}, 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,
|
3078
|
+
}, 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 });
|
3072
3079
|
if (props.tableFeatures) {
|
3073
3080
|
props.tableFeatures.forEach((feature) => {
|
3074
3081
|
Object.assign(table, feature(table));
|
@@ -3093,6 +3100,16 @@ const MRT_TableRoot = (props) => {
|
|
3093
3100
|
}
|
3094
3101
|
}
|
3095
3102
|
}, [table.getState().isFullScreen]);
|
3103
|
+
//if page index is out of bounds, set it to the last page
|
3104
|
+
React.useEffect(() => {
|
3105
|
+
var _a;
|
3106
|
+
const { pageIndex, pageSize } = table.getState().pagination;
|
3107
|
+
const totalRowCount = (_a = props.rowCount) !== null && _a !== void 0 ? _a : table.getPrePaginationRowModel().rows.length;
|
3108
|
+
const firstVisibleRowIndex = pageIndex * pageSize;
|
3109
|
+
if (firstVisibleRowIndex > totalRowCount) {
|
3110
|
+
table.setPageIndex(Math.floor(totalRowCount / pageSize));
|
3111
|
+
}
|
3112
|
+
}, [props.rowCount, table.getPrePaginationRowModel().rows.length]);
|
3096
3113
|
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
3097
3114
|
React__default["default"].createElement(Dialog__default["default"], { PaperComponent: Box__default["default"], TransitionComponent: !props.enableRowVirtualization ? Grow__default["default"] : undefined, disablePortal: true, fullScreen: true, keepMounted: false, onClose: () => table.setIsFullScreen(false), open: table.getState().isFullScreen, transitionDuration: 400 },
|
3098
3115
|
React__default["default"].createElement(MRT_TablePaper, { table: table })),
|