material-react-table 1.9.1 → 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 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();
@@ -2293,11 +2300,11 @@ const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table }) => {
2293
2300
 
2294
2301
  const allowedTypes = ['string', 'number'];
2295
2302
  const MRT_TableBodyCellValue = ({ cell, table }) => {
2296
- var _a, _b, _c, _d;
2303
+ var _a, _b, _c;
2297
2304
  const { getState, options: { enableFilterMatchHighlighting }, } = table;
2298
2305
  const { column, row } = cell;
2299
2306
  const { columnDef } = column;
2300
- const { globalFilter } = getState();
2307
+ const { globalFilter, globalFilterFn } = getState();
2301
2308
  const filterValue = column.getFilterValue();
2302
2309
  let renderedCellValue = cell.getIsAggregated() && columnDef.AggregatedCell
2303
2310
  ? columnDef.AggregatedCell({
@@ -2327,13 +2334,16 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
2327
2334
  ((filterValue &&
2328
2335
  allowedTypes.includes(typeof filterValue) &&
2329
2336
  columnDef.filterVariant === 'text') ||
2330
- (globalFilter && allowedTypes.includes(typeof globalFilter)))) {
2337
+ (globalFilter &&
2338
+ allowedTypes.includes(typeof globalFilter) &&
2339
+ column.getCanGlobalFilter()))) {
2331
2340
  const chunks = highlightWords__default["default"] === null || highlightWords__default["default"] === void 0 ? void 0 : highlightWords__default["default"]({
2332
2341
  text: renderedCellValue === null || renderedCellValue === void 0 ? void 0 : renderedCellValue.toString(),
2333
- query: ((_b = (_a = column.getFilterValue()) !== null && _a !== void 0 ? _a : globalFilter) !== null && _b !== void 0 ? _b : '').toString(),
2342
+ query: ((_a = filterValue !== null && filterValue !== void 0 ? filterValue : globalFilter) !== null && _a !== void 0 ? _a : '').toString(),
2343
+ matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
2334
2344
  });
2335
- if ((chunks === null || chunks === void 0 ? void 0 : chunks.length) > 1 || ((_c = chunks === null || chunks === void 0 ? void 0 : chunks[0]) === null || _c === void 0 ? void 0 : _c.match)) {
2336
- renderedCellValue = (React__default["default"].createElement("span", { "aria-label": renderedCellValue, role: "note" }, (_d = chunks === null || chunks === void 0 ? void 0 : chunks.map(({ key, match, text }) => (React__default["default"].createElement(Box__default["default"], { "aria-hidden": "true", component: "span", key: key, sx: match
2345
+ if ((chunks === null || chunks === void 0 ? void 0 : chunks.length) > 1 || ((_b = chunks === null || chunks === void 0 ? void 0 : chunks[0]) === null || _b === void 0 ? void 0 : _b.match)) {
2346
+ renderedCellValue = (React__default["default"].createElement("span", { "aria-label": renderedCellValue, role: "note" }, (_c = chunks === null || chunks === void 0 ? void 0 : chunks.map(({ key, match, text }) => (React__default["default"].createElement(Box__default["default"], { "aria-hidden": "true", component: "span", key: key, sx: match
2337
2347
  ? {
2338
2348
  backgroundColor: (theme) => theme.palette.mode === 'dark'
2339
2349
  ? styles.darken(theme.palette.warning.dark, 0.25)
@@ -2342,7 +2352,7 @@ const MRT_TableBodyCellValue = ({ cell, table }) => {
2342
2352
  color: (theme) => theme.palette.mode === 'dark' ? 'white' : 'black',
2343
2353
  padding: '2px 1px',
2344
2354
  }
2345
- : undefined }, text)))) !== null && _d !== void 0 ? _d : renderedCellValue));
2355
+ : undefined }, text)))) !== null && _c !== void 0 ? _c : renderedCellValue));
2346
2356
  }
2347
2357
  }
2348
2358
  if (columnDef.Cell && !isGroupedValue) {
@@ -2968,7 +2978,7 @@ const MRT_TableRoot = (props) => {
2968
2978
  const [hoveredRow, setHoveredRow] = React.useState((_k = initialState.hoveredRow) !== null && _k !== void 0 ? _k : null);
2969
2979
  const [isFullScreen, setIsFullScreen] = React.useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.isFullScreen) !== null && _l !== void 0 ? _l : false);
2970
2980
  const [showAlertBanner, setShowAlertBanner] = React.useState((_o = (_m = props.initialState) === null || _m === void 0 ? void 0 : _m.showAlertBanner) !== null && _o !== void 0 ? _o : false);
2971
- 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);
2972
2982
  const [showGlobalFilter, setShowGlobalFilter] = React.useState((_q = initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) !== null && _q !== void 0 ? _q : false);
2973
2983
  const [showToolbarDropZone, setShowToolbarDropZone] = React.useState((_r = initialState === null || initialState === void 0 ? void 0 : initialState.showToolbarDropZone) !== null && _r !== void 0 ? _r : false);
2974
2984
  const displayColumns = React.useMemo(() => {
@@ -3065,7 +3075,7 @@ const MRT_TableRoot = (props) => {
3065
3075
  tableHeadCellRefs,
3066
3076
  tablePaperRef,
3067
3077
  topToolbarRef,
3068
- }, 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 });
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 });
3069
3079
  if (props.tableFeatures) {
3070
3080
  props.tableFeatures.forEach((feature) => {
3071
3081
  Object.assign(table, feature(table));
@@ -3090,6 +3100,16 @@ const MRT_TableRoot = (props) => {
3090
3100
  }
3091
3101
  }
3092
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]);
3093
3113
  return (React__default["default"].createElement(React__default["default"].Fragment, null,
3094
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 },
3095
3115
  React__default["default"].createElement(MRT_TablePaper, { table: table })),