material-react-table 1.9.2 → 1.9.4

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 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] < 43kb gzipped - [Bundlephobia](https://bundlephobia.com/package/material-react-table)
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, setShowFilters, } = table;
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
- setShowFilters(true);
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 (globalFilter === undefined) {
1231
- handleClear();
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, }, setShowFilters, } = table;
1398
+ const { getState, options: { icons: { FilterListIcon, FilterListOffIcon }, localization, }, setShowColumnFilters, } = table;
1392
1399
  const { showColumnFilters } = getState();
1393
1400
  const handleToggleShowFilters = () => {
1394
- setShowFilters(!showColumnFilters);
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 }, setShowFilters, } = table;
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
- setShowFilters(true);
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, setShowFilters] = React.useState((_p = initialState === null || initialState === void 0 ? void 0 : initialState.showColumnFilters) !== null && _p !== void 0 ? _p : false);
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(() => {
@@ -3009,6 +3016,8 @@ const MRT_TableRoot = (props) => {
3009
3016
  props.localization,
3010
3017
  props.positionActionsColumn,
3011
3018
  props.renderDetailPanel,
3019
+ props.renderRowActionMenuItems,
3020
+ props.renderRowActions,
3012
3021
  (_s = props.state) === null || _s === void 0 ? void 0 : _s.columnOrder,
3013
3022
  (_t = props.state) === null || _t === void 0 ? void 0 : _t.grouping,
3014
3023
  ]);
@@ -3068,7 +3077,7 @@ const MRT_TableRoot = (props) => {
3068
3077
  tableHeadCellRefs,
3069
3078
  tablePaperRef,
3070
3079
  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, setShowFilters: (_11 = props.onShowFiltersChange) !== null && _11 !== void 0 ? _11 : setShowFilters, setShowGlobalFilter: (_12 = props.onShowGlobalFilterChange) !== null && _12 !== void 0 ? _12 : setShowGlobalFilter, setShowToolbarDropZone: (_13 = props.onShowToolbarDropZoneChange) !== null && _13 !== void 0 ? _13 : setShowToolbarDropZone });
3080
+ }, 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
3081
  if (props.tableFeatures) {
3073
3082
  props.tableFeatures.forEach((feature) => {
3074
3083
  Object.assign(table, feature(table));
@@ -3093,6 +3102,16 @@ const MRT_TableRoot = (props) => {
3093
3102
  }
3094
3103
  }
3095
3104
  }, [table.getState().isFullScreen]);
3105
+ //if page index is out of bounds, set it to the last page
3106
+ React.useEffect(() => {
3107
+ var _a;
3108
+ const { pageIndex, pageSize } = table.getState().pagination;
3109
+ const totalRowCount = (_a = props.rowCount) !== null && _a !== void 0 ? _a : table.getPrePaginationRowModel().rows.length;
3110
+ const firstVisibleRowIndex = pageIndex * pageSize;
3111
+ if (firstVisibleRowIndex > totalRowCount) {
3112
+ table.setPageIndex(Math.floor(totalRowCount / pageSize));
3113
+ }
3114
+ }, [props.rowCount, table.getPrePaginationRowModel().rows.length]);
3096
3115
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
3097
3116
  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
3117
  React__default["default"].createElement(MRT_TablePaper, { table: table })),