material-react-table 1.0.0-beta.4 → 1.0.0-beta.7

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.
@@ -47,6 +47,8 @@ export interface MRT_Localization {
47
47
  max: string;
48
48
  min: string;
49
49
  move: string;
50
+ noRecordsToDisplay: string;
51
+ noResultsFound: string;
50
52
  or: string;
51
53
  pinToLeft: string;
52
54
  pinToRight: string;
@@ -1,4 +1,4 @@
1
- import { Dispatch, DragEvent, MutableRefObject, ReactNode, SetStateAction } from 'react';
1
+ import { Dispatch, MutableRefObject, ReactNode, SetStateAction } from 'react';
2
2
  import type { AlertProps, ButtonProps, CheckboxProps, ChipProps, IconButtonProps, LinearProgressProps, PaperProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
3
3
  import type { Cell, Column, ColumnDef, DeepKeys, FilterFn, Header, HeaderGroup, OnChangeFn, Row, SortingFn, Table, TableOptions, TableState } from '@tanstack/react-table';
4
4
  import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
@@ -40,6 +40,7 @@ export declare type MRT_TableInstance<TData extends Record<string, any> = {}> =
40
40
  filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
41
41
  searchInputRef: MutableRefObject<HTMLInputElement>;
42
42
  tableContainerRef: MutableRefObject<HTMLDivElement>;
43
+ tablePaperRef: MutableRefObject<HTMLDivElement>;
43
44
  topToolbarRef: MutableRefObject<HTMLDivElement>;
44
45
  };
45
46
  setColumnFilterFns: Dispatch<SetStateAction<{
@@ -439,13 +440,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
439
440
  muiTopToolbarProps?: ToolbarProps | (({ table }: {
440
441
  table: MRT_TableInstance<TData>;
441
442
  }) => ToolbarProps);
442
- onColumnDrop?: ({ event, draggedColumn, targetColumn, }: {
443
- event: DragEvent<HTMLButtonElement>;
444
- draggedColumn: MRT_Column<TData>;
445
- targetColumn: MRT_Column<TData> | {
446
- id: string;
447
- } | null;
448
- }) => void;
449
443
  onDensityChange?: OnChangeFn<boolean>;
450
444
  onDraggingColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
451
445
  onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
@@ -464,13 +458,6 @@ export declare type MaterialReactTableProps<TData extends Record<string, any> =
464
458
  onHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
465
459
  onHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
466
460
  onIsFullScreenChange?: OnChangeFn<boolean>;
467
- onRowDrop?: ({ event, draggedRow, targetRow, }: {
468
- event: DragEvent<HTMLButtonElement>;
469
- draggedRow: MRT_Row<TData>;
470
- targetRow: MRT_Row<TData> | {
471
- id: string;
472
- } | null;
473
- }) => void;
474
461
  onShowAlertBannerChange?: OnChangeFn<boolean>;
475
462
  onShowFiltersChange?: OnChangeFn<boolean>;
476
463
  onShowGlobalFilterChange?: OnChangeFn<boolean>;
@@ -47,6 +47,8 @@ export interface MRT_Localization {
47
47
  max: string;
48
48
  min: string;
49
49
  move: string;
50
+ noRecordsToDisplay: string;
51
+ noResultsFound: string;
50
52
  or: string;
51
53
  pinToLeft: string;
52
54
  pinToRight: string;
@@ -200,6 +200,8 @@ const MRT_DefaultLocalization_EN = {
200
200
  max: 'Max',
201
201
  min: 'Min',
202
202
  move: 'Move',
203
+ noRecordsToDisplay: 'No records to display',
204
+ noResultsFound: 'No results found',
203
205
  or: 'or',
204
206
  pinToLeft: 'Pin to left',
205
207
  pinToRight: 'Pin to right',
@@ -469,11 +471,11 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
469
471
  var _a;
470
472
  const { options: { icons: { DragHandleIcon }, localization, }, } = table;
471
473
  return (React.createElement(Tooltip, { arrow: true, enterDelay: 1000, enterNextDelay: 1000, placement: "top", title: (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.title) !== null && _a !== void 0 ? _a : localization.move },
472
- React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", onDragStart: onDragStart, onDragEnd: onDragEnd, size: "small" }, iconButtonProps, { onClick: (e) => {
474
+ React.createElement(IconButton, Object.assign({ disableRipple: true, draggable: "true", size: "small" }, iconButtonProps, { onClick: (e) => {
473
475
  var _a;
474
476
  e.stopPropagation();
475
477
  (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onClick) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, e);
476
- }, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
478
+ }, onDragStart: onDragStart, onDragEnd: onDragEnd, sx: (theme) => (Object.assign({ cursor: 'grab', m: 0, opacity: 0.5, p: '2px', transition: 'all 0.2s ease-in-out', '&:hover': {
477
479
  backgroundColor: 'transparent',
478
480
  opacity: 1,
479
481
  }, '&:active': {
@@ -1302,7 +1304,11 @@ const MRT_TopToolbar = ({ table }) => {
1302
1304
  width: '100%',
1303
1305
  } },
1304
1306
  enableGlobalFilter && positionGlobalFilter === 'left' && (React.createElement(MRT_GlobalFilterTextField, { table: table })), (_a = renderTopToolbarCustomActions === null || renderTopToolbarCustomActions === void 0 ? void 0 : renderTopToolbarCustomActions({ table })) !== null && _a !== void 0 ? _a : React.createElement("span", null),
1305
- enableToolbarInternalActions ? (React.createElement(Box, { sx: { display: 'flex', flexWrap: 'wrap' } },
1307
+ enableToolbarInternalActions ? (React.createElement(Box, { sx: {
1308
+ display: 'flex',
1309
+ flexWrap: 'wrap-reverse',
1310
+ justifyContent: 'flex-end',
1311
+ } },
1306
1312
  enableGlobalFilter && positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })),
1307
1313
  React.createElement(MRT_ToolbarInternalButtons, { table: table }))) : (enableGlobalFilter &&
1308
1314
  positionGlobalFilter === 'right' && (React.createElement(MRT_GlobalFilterTextField, { table: table })))),
@@ -1594,11 +1600,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1594
1600
  const { options: { icons: { FilterAltIcon }, localization, }, } = table;
1595
1601
  const { column } = header;
1596
1602
  const { columnDef } = column;
1597
- const isRangeFilter = [
1598
- 'between',
1599
- 'betweenInclusive',
1600
- 'inNumberRange',
1601
- ].includes(columnDef._filterFn);
1603
+ const isRangeFilter = columnDef.filterVariant === 'range' ||
1604
+ ['between', 'betweenInclusive', 'inNumberRange'].includes(columnDef._filterFn);
1602
1605
  const currentFilterOption = columnDef._filterFn;
1603
1606
  const filterTooltip = localization.filteringByColumn
1604
1607
  .replace('{column}', String(columnDef.header))
@@ -1610,8 +1613,8 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1610
1613
  ? column.getFilterValue().join(`" ${isRangeFilter ? localization.and : localization.or} "`)
1611
1614
  : column.getFilterValue()}"`)
1612
1615
  .replace('" "', '');
1613
- return (React.createElement(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && isRangeFilter) ||
1614
- (!isRangeFilter && // @ts-ignore
1616
+ return (React.createElement(Grow, { unmountOnExit: true, in: (!!column.getFilterValue() && !isRangeFilter) ||
1617
+ (isRangeFilter && // @ts-ignore
1615
1618
  (!!((_b = column.getFilterValue()) === null || _b === void 0 ? void 0 : _b[0]) || !!((_c = column.getFilterValue()) === null || _c === void 0 ? void 0 : _c[1]))) },
1616
1619
  React.createElement("span", null,
1617
1620
  React.createElement(Tooltip, { arrow: true, placement: "top", title: filterTooltip },
@@ -1628,7 +1631,7 @@ const MRT_TableHeadCellFilterLabel = ({ header, table }) => {
1628
1631
  };
1629
1632
 
1630
1633
  const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1631
- const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps, onColumnDrop, }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1634
+ const { getState, options: { enableColumnOrdering, muiTableHeadCellDragHandleProps }, setColumnOrder, setDraggingColumn, setHoveredColumn, } = table;
1632
1635
  const { columnDef } = column;
1633
1636
  const { hoveredColumn, draggingColumn, columnOrder } = getState();
1634
1637
  const mIconButtonProps = muiTableHeadCellDragHandleProps instanceof Function
@@ -1638,16 +1641,15 @@ const MRT_TableHeadCellGrabHandle = ({ column, table, tableHeadCellRef, }) => {
1638
1641
  ? columnDef.muiTableHeadCellDragHandleProps({ column, table })
1639
1642
  : columnDef.muiTableHeadCellDragHandleProps;
1640
1643
  const iconButtonProps = Object.assign(Object.assign({}, mIconButtonProps), mcIconButtonProps);
1641
- const handleDragStart = (e) => {
1644
+ const handleDragStart = (event) => {
1645
+ var _a;
1646
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1642
1647
  setDraggingColumn(column);
1643
- e.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1648
+ event.dataTransfer.setDragImage(tableHeadCellRef.current, 0, 0);
1644
1649
  };
1645
1650
  const handleDragEnd = (event) => {
1646
- onColumnDrop === null || onColumnDrop === void 0 ? void 0 : onColumnDrop({
1647
- event,
1648
- draggedColumn: column,
1649
- targetColumn: hoveredColumn,
1650
- });
1651
+ var _a;
1652
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1651
1653
  if ((hoveredColumn === null || hoveredColumn === void 0 ? void 0 : hoveredColumn.id) === 'drop-zone') {
1652
1654
  column.toggleGrouping();
1653
1655
  }
@@ -1936,21 +1938,20 @@ const MRT_CopyButton = ({ cell, children, table, }) => {
1936
1938
  };
1937
1939
 
1938
1940
  const MRT_TableBodyRowGrabHandle = ({ cell, rowRef, table, }) => {
1939
- const { options: { muiTableBodyRowDragHandleProps, onRowDrop }, } = table;
1941
+ const { options: { muiTableBodyRowDragHandleProps }, } = table;
1940
1942
  const { row } = cell;
1941
1943
  const iconButtonProps = muiTableBodyRowDragHandleProps instanceof Function
1942
1944
  ? muiTableBodyRowDragHandleProps({ row, table })
1943
1945
  : muiTableBodyRowDragHandleProps;
1944
- const handleDragStart = (e) => {
1945
- e.dataTransfer.setDragImage(rowRef.current, 0, 0);
1946
+ const handleDragStart = (event) => {
1947
+ var _a;
1948
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragStart) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1949
+ event.dataTransfer.setDragImage(rowRef.current, 0, 0);
1946
1950
  table.setDraggingRow(row);
1947
1951
  };
1948
1952
  const handleDragEnd = (event) => {
1949
- onRowDrop === null || onRowDrop === void 0 ? void 0 : onRowDrop({
1950
- event,
1951
- draggedRow: table.getState().draggingRow,
1952
- targetRow: table.getState().hoveredRow,
1953
- });
1953
+ var _a;
1954
+ (_a = iconButtonProps === null || iconButtonProps === void 0 ? void 0 : iconButtonProps.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(iconButtonProps, event);
1954
1955
  table.setDraggingRow(null);
1955
1956
  table.setHoveredRow(null);
1956
1957
  };
@@ -2155,8 +2156,9 @@ const MRT_TableBodyRow = ({ row, rowIndex, table, virtualRow, }) => {
2155
2156
  };
2156
2157
 
2157
2158
  const MRT_TableBody = ({ table }) => {
2158
- const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef }, } = table;
2159
- const { globalFilter, pagination, sorting } = getState();
2159
+ var _a;
2160
+ const { getRowModel, getPrePaginationRowModel, getState, options: { enableGlobalFilterRankedResults, enablePagination, enableRowVirtualization, localization, manualFiltering, manualSorting, muiTableBodyProps, virtualizerInstanceRef, virtualizerProps, }, refs: { tableContainerRef, tablePaperRef }, } = table;
2161
+ const { columnFilters, globalFilter, pagination, sorting } = getState();
2160
2162
  const tableBodyProps = muiTableBodyProps instanceof Function
2161
2163
  ? muiTableBodyProps({ table })
2162
2164
  : muiTableBodyProps;
@@ -2221,7 +2223,18 @@ const MRT_TableBody = ({ table }) => {
2221
2223
  // ? virtualizer.getTotalSize() - virtualRows[virtualRows.length - 1].end
2222
2224
  // : 0;
2223
2225
  // }
2224
- return (React.createElement(TableBody, Object.assign({}, tableBodyProps),
2226
+ return (React.createElement(TableBody, Object.assign({}, tableBodyProps), !rows.length ? (React.createElement("tr", null,
2227
+ React.createElement("td", { colSpan: table.getVisibleLeafColumns().length },
2228
+ React.createElement(Typography, { sx: {
2229
+ color: 'text.secondary',
2230
+ fontStyle: 'italic',
2231
+ maxWidth: `min(100vw, ${(_a = tablePaperRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth}px)`,
2232
+ py: '2rem',
2233
+ textAlign: 'center',
2234
+ width: '100%',
2235
+ } }, globalFilter || columnFilters.length
2236
+ ? localization.noResultsFound
2237
+ : localization.noRecordsToDisplay)))) : (React.createElement(React.Fragment, null,
2225
2238
  enableRowVirtualization && paddingTop > 0 && (React.createElement("tr", null,
2226
2239
  React.createElement("td", { style: { height: `${paddingTop}px` } }))),
2227
2240
  (enableRowVirtualization ? virtualRows : rows).map((rowOrVirtualRow, rowIndex) => {
@@ -2231,7 +2244,7 @@ const MRT_TableBody = ({ table }) => {
2231
2244
  return (React.createElement(MRT_TableBodyRow, { key: row.id, row: row, rowIndex: enableRowVirtualization ? rowOrVirtualRow.index : rowIndex, table: table, virtualRow: enableRowVirtualization ? rowOrVirtualRow : null }));
2232
2245
  }),
2233
2246
  enableRowVirtualization && paddingBottom > 0 && (React.createElement("tr", null,
2234
- React.createElement("td", { style: { height: `${paddingBottom}px` } })))));
2247
+ React.createElement("td", { style: { height: `${paddingBottom}px` } })))))));
2235
2248
  };
2236
2249
 
2237
2250
  const MRT_TableFooterCell = ({ footer, table }) => {
@@ -2285,11 +2298,11 @@ const MRT_TableFooter = ({ table }) => {
2285
2298
  ? muiTableFooterProps({ table })
2286
2299
  : muiTableFooterProps;
2287
2300
  const stickFooter = (isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
2288
- return (React.createElement(TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ position: stickFooter ? 'sticky' : undefined, bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2301
+ return (React.createElement(TableFooter, Object.assign({}, tableFooterProps, { sx: (theme) => (Object.assign({ backgroundColor: lighten(theme.palette.background.default, 0.06), bottom: stickFooter ? 0 : undefined, opacity: stickFooter ? 0.95 : undefined, outline: stickFooter
2289
2302
  ? theme.palette.mode === 'light'
2290
2303
  ? `1px solid ${theme.palette.grey[300]}`
2291
2304
  : `1px solid ${theme.palette.grey[700]}`
2292
- : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2305
+ : undefined, position: stickFooter ? 'sticky' : undefined }, ((tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx) instanceof Function
2293
2306
  ? tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx(theme)
2294
2307
  : tableFooterProps === null || tableFooterProps === void 0 ? void 0 : tableFooterProps.sx))) }), getFooterGroups().map((footerGroup) => (React.createElement(MRT_TableFooterRow, { footerGroup: footerGroup, key: footerGroup.id, table: table })))));
2295
2308
  };
@@ -2343,7 +2356,7 @@ const MRT_TableContainer = ({ table }) => {
2343
2356
  };
2344
2357
 
2345
2358
  const MRT_TablePaper = ({ table }) => {
2346
- const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, } = table;
2359
+ const { getState, options: { enableBottomToolbar, enableTopToolbar, muiTablePaperProps }, refs: { tablePaperRef }, } = table;
2347
2360
  const { isFullScreen } = getState();
2348
2361
  useEffect(() => {
2349
2362
  if (typeof window !== 'undefined') {
@@ -2358,7 +2371,13 @@ const MRT_TablePaper = ({ table }) => {
2358
2371
  const tablePaperProps = muiTablePaperProps instanceof Function
2359
2372
  ? muiTablePaperProps({ table })
2360
2373
  : muiTablePaperProps;
2361
- return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2374
+ return (React.createElement(Paper, Object.assign({ elevation: 2 }, tablePaperProps, { ref: (ref) => {
2375
+ tablePaperRef.current = ref;
2376
+ if (tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.ref) {
2377
+ //@ts-ignore
2378
+ tablePaperProps.ref.current = ref;
2379
+ }
2380
+ }, sx: (theme) => (Object.assign({ transition: 'all 0.2s ease-in-out' }, ((tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx) instanceof Function
2362
2381
  ? tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx(theme)
2363
2382
  : tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.sx))), style: Object.assign(Object.assign({}, tablePaperProps === null || tablePaperProps === void 0 ? void 0 : tablePaperProps.style), { height: isFullScreen ? '100vh' : undefined, margin: isFullScreen ? '0' : undefined, maxHeight: isFullScreen ? '100vh' : undefined, maxWidth: isFullScreen ? '100vw' : undefined, padding: isFullScreen ? '0' : undefined, width: isFullScreen ? '100vw' : undefined }) }),
2364
2383
  enableTopToolbar && React.createElement(MRT_TopToolbar, { table: table }),
@@ -2391,6 +2410,7 @@ const MRT_TableRoot = (props) => {
2391
2410
  const filterInputRefs = useRef({});
2392
2411
  const searchInputRef = useRef(null);
2393
2412
  const tableContainerRef = useRef(null);
2413
+ const tablePaperRef = useRef(null);
2394
2414
  const topToolbarRef = useRef(null);
2395
2415
  const initialState = useMemo(() => {
2396
2416
  var _a, _b;
@@ -2511,6 +2531,7 @@ const MRT_TableRoot = (props) => {
2511
2531
  filterInputRefs,
2512
2532
  searchInputRef,
2513
2533
  tableContainerRef,
2534
+ tablePaperRef,
2514
2535
  topToolbarRef,
2515
2536
  }, setColumnFilterFns: (_x = props.onFilterFnsChange) !== null && _x !== void 0 ? _x : setColumnFilterFns, setDensity: (_y = props.onDensityChange) !== null && _y !== void 0 ? _y : setDensity, setDraggingColumn: (_z = props.onDraggingColumnChange) !== null && _z !== void 0 ? _z : setDraggingColumn, setDraggingRow: (_0 = props.onDraggingRowChange) !== null && _0 !== void 0 ? _0 : setDraggingRow, setEditingCell: (_1 = props.onEditingCellChange) !== null && _1 !== void 0 ? _1 : setEditingCell, setEditingRow: (_2 = props.onEditingRowChange) !== null && _2 !== void 0 ? _2 : setEditingRow, setGlobalFilterFn: (_3 = props.onGlobalFilterFnChange) !== null && _3 !== void 0 ? _3 : setGlobalFilterFn, setHoveredColumn: (_4 = props.onHoveredColumnChange) !== null && _4 !== void 0 ? _4 : setHoveredColumn, setHoveredRow: (_5 = props.onHoveredRowChange) !== null && _5 !== void 0 ? _5 : setHoveredRow, setIsFullScreen: (_6 = props.onIsFullScreenChange) !== null && _6 !== void 0 ? _6 : setIsFullScreen, setShowAlertBanner: (_7 = props.onShowAlertBannerChange) !== null && _7 !== void 0 ? _7 : setShowAlertBanner, setShowFilters: (_8 = props.onShowFiltersChange) !== null && _8 !== void 0 ? _8 : setShowFilters, setShowGlobalFilter: (_9 = props.onShowGlobalFilterChange) !== null && _9 !== void 0 ? _9 : setShowGlobalFilter });
2516
2537
  if (props.tableInstanceRef) {