material-react-table 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -54,6 +54,7 @@ var ViewColumnIcon = require('@mui/icons-material/ViewColumn');
54
54
  var VisibilityOffIcon = require('@mui/icons-material/VisibilityOff');
55
55
  var reactVirtual = require('@tanstack/react-virtual');
56
56
  var Paper = require('@mui/material/Paper');
57
+ var material = require('@mui/material');
57
58
  var TableContainer = require('@mui/material/TableContainer');
58
59
  var Table = require('@mui/material/Table');
59
60
  var TableBody = require('@mui/material/TableBody');
@@ -747,7 +748,7 @@ const MRT_EditActionButtons = (_a) => {
747
748
  }
748
749
  };
749
750
  return (jsxRuntime.jsx(Box__default["default"], { onClick: (e) => e.stopPropagation(), sx: (theme) => (Object.assign({ display: 'flex', gap: '0.75rem' }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: variant === 'icon' ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip__default["default"], { title: localization.cancel, children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.cancel, onClick: handleCancel, children: jsxRuntime.jsx(CancelIcon, {}) }) }), ((isCreating && onCreatingRowSave) ||
750
- (isEditing && onEditingRowSave)) && (jsxRuntime.jsx(Tooltip__default["default"], { title: localization.save, children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.save, color: "info", onClick: handleSubmitRow, children: isSaving ? jsxRuntime.jsx(CircularProgress__default["default"], { size: 18 }) : jsxRuntime.jsx(SaveIcon, {}) }) }))] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Button__default["default"], { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxRuntime.jsxs(Button__default["default"], { onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsxRuntime.jsx(CircularProgress__default["default"], { color: "inherit", size: 18 }), localization.save] })] })) }));
751
+ (isEditing && onEditingRowSave)) && (jsxRuntime.jsx(Tooltip__default["default"], { title: localization.save, children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.save, color: "info", disabled: isSaving, onClick: handleSubmitRow, children: isSaving ? jsxRuntime.jsx(CircularProgress__default["default"], { size: 18 }) : jsxRuntime.jsx(SaveIcon, {}) }) }))] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Button__default["default"], { onClick: handleCancel, sx: { minWidth: '100px' }, children: localization.cancel }), jsxRuntime.jsxs(Button__default["default"], { disabled: isSaving, onClick: handleSubmitRow, sx: { minWidth: '100px' }, variant: "contained", children: [isSaving && jsxRuntime.jsx(CircularProgress__default["default"], { color: "inherit", size: 18 }), localization.save] })] })) }));
751
752
  };
752
753
 
753
754
  const parseCSSVarId = (id) => id.replace(/[^a-zA-Z0-9]/g, '_');
@@ -1416,11 +1417,12 @@ const useMRT_TableOptions = (_a) => {
1416
1417
  ? reactTable.getFacetedMinMaxValues()
1417
1418
  : undefined, getFacetedRowModel: enableFacetedValues ? reactTable.getFacetedRowModel() : undefined, getFacetedUniqueValues: enableFacetedValues
1418
1419
  ? reactTable.getFacetedUniqueValues()
1419
- : undefined, getFilteredRowModel: enableColumnFilters || enableGlobalFilter || enableFilters
1420
+ : undefined, getFilteredRowModel: (enableColumnFilters || enableGlobalFilter || enableFilters) &&
1421
+ !manualFiltering
1420
1422
  ? reactTable.getFilteredRowModel()
1421
- : undefined, getGroupedRowModel: enableGrouping ? reactTable.getGroupedRowModel() : undefined, getPaginationRowModel: enablePagination
1423
+ : undefined, getGroupedRowModel: enableGrouping && !manualGrouping ? reactTable.getGroupedRowModel() : undefined, getPaginationRowModel: enablePagination && !manualPagination
1422
1424
  ? reactTable.getPaginationRowModel()
1423
- : undefined, getSortedRowModel: enableSorting ? reactTable.getSortedRowModel() : undefined, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows, icons,
1425
+ : undefined, getSortedRowModel: enableSorting && !manualSorting ? reactTable.getSortedRowModel() : undefined, getSubRows: (row) => row === null || row === void 0 ? void 0 : row.subRows, icons,
1424
1426
  layoutMode,
1425
1427
  localization,
1426
1428
  manualFiltering,
@@ -1735,22 +1737,23 @@ const extraIndexRangeExtractor = (range, draggingIndex) => {
1735
1737
 
1736
1738
  const useMRT_ColumnVirtualizer = (table) => {
1737
1739
  var _a, _b, _c, _d;
1738
- const { getLeftLeafColumns, getRightLeafColumns, getState, getVisibleLeafColumns, options: { columnVirtualizerInstanceRef, columnVirtualizerOptions, enableColumnPinning, enableColumnVirtualization, }, refs: { tableContainerRef }, } = table;
1739
- const { columnPinning, draggingColumn } = getState();
1740
+ const { getState, options: { columnVirtualizerInstanceRef, columnVirtualizerOptions, enableColumnPinning, enableColumnVirtualization, }, refs: { tableContainerRef }, } = table;
1741
+ const { columnPinning, columnVisibility, draggingColumn } = getState();
1740
1742
  if (!enableColumnVirtualization)
1741
1743
  return undefined;
1742
1744
  const columnVirtualizerProps = parseFromValuesOrFunc(columnVirtualizerOptions, {
1743
1745
  table,
1744
1746
  });
1745
- const visibleColumns = getVisibleLeafColumns();
1747
+ const visibleColumns = table.getVisibleLeafColumns();
1746
1748
  const [leftPinnedIndexes, rightPinnedIndexes] = react.useMemo(() => enableColumnPinning
1747
1749
  ? [
1748
- getLeftLeafColumns().map((c) => c.getPinnedIndex()),
1749
- getRightLeafColumns()
1750
+ table.getLeftVisibleLeafColumns().map((c) => c.getPinnedIndex()),
1751
+ table
1752
+ .getRightVisibleLeafColumns()
1750
1753
  .map((column) => visibleColumns.length - column.getPinnedIndex() - 1)
1751
1754
  .sort((a, b) => a - b),
1752
1755
  ]
1753
- : [[], []], [columnPinning, enableColumnPinning]);
1756
+ : [[], []], [columnPinning, columnVisibility, enableColumnPinning]);
1754
1757
  const numPinnedLeft = leftPinnedIndexes.length;
1755
1758
  const numPinnedRight = rightPinnedIndexes.length;
1756
1759
  const draggingColumnIndex = react.useMemo(() => (draggingColumn === null || draggingColumn === void 0 ? void 0 : draggingColumn.id)
@@ -2893,26 +2896,12 @@ const MRT_FilterTextField = (_a) => {
2893
2896
  const { column } = header;
2894
2897
  const { columnDef } = column;
2895
2898
  const { filterVariant } = columnDef;
2896
- const textFieldProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterTextFieldProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterTextFieldProps, {
2897
- column,
2898
- table,
2899
- })), rest);
2900
- const autocompleteProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterAutocompleteProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterAutocompleteProps, {
2901
- column,
2902
- table,
2903
- }));
2904
- const datePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterDatePickerProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterDatePickerProps, {
2905
- column,
2906
- table,
2907
- }));
2908
- const dateTimePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterDateTimePickerProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterDateTimePickerProps, {
2909
- column,
2910
- table,
2911
- }));
2912
- const timePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterTimePickerProps, { column, table })), parseFromValuesOrFunc(columnDef.muiFilterTimePickerProps, {
2913
- column,
2914
- table,
2915
- }));
2899
+ const args = { column, rangeFilterIndex, table };
2900
+ const textFieldProps = Object.assign(Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterTextFieldProps, args)), parseFromValuesOrFunc(columnDef.muiFilterTextFieldProps, args)), rest);
2901
+ const autocompleteProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterAutocompleteProps, args)), parseFromValuesOrFunc(columnDef.muiFilterAutocompleteProps, args));
2902
+ const datePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterDatePickerProps, args)), parseFromValuesOrFunc(columnDef.muiFilterDatePickerProps, args));
2903
+ const dateTimePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterDateTimePickerProps, args)), parseFromValuesOrFunc(columnDef.muiFilterDateTimePickerProps, args));
2904
+ const timePickerProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiFilterTimePickerProps, args)), parseFromValuesOrFunc(columnDef.muiFilterTimePickerProps, args));
2916
2905
  const { allowedColumnFilterOptions, currentFilterOption, facetedUniqueValues, isAutocompleteFilter, isDateFilter, isMultiSelectFilter, isRangeFilter, isSelectFilter, isTextboxFilter, } = getColumnFilterInfo({ header, table });
2917
2906
  const dropdownOptions = useDropdownOptions({ header, table });
2918
2907
  const filterChipLabel = ['empty', 'notEmpty'].includes(currentFilterOption)
@@ -3795,13 +3784,13 @@ const MRT_TablePagination = (_a) => {
3795
3784
  var { position = 'bottom', table } = _a, rest = __rest(_a, ["position", "table"]);
3796
3785
  const theme = styles.useTheme();
3797
3786
  const isMobile = useMediaQuery__default["default"]('(max-width: 720px)');
3798
- const { getPrePaginationRowModel, getState, options: { enableToolbarInternalActions, icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, localization, muiPaginationProps, paginationDisplayMode, rowCount, }, setPageIndex, setPageSize, } = table;
3787
+ const { getState, options: { enableToolbarInternalActions, icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, localization, muiPaginationProps, paginationDisplayMode, }, } = table;
3799
3788
  const { pagination: { pageIndex = 0, pageSize = 10 }, showGlobalFilter, } = getState();
3800
3789
  const paginationProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiPaginationProps, {
3801
3790
  table,
3802
3791
  })), rest);
3803
- const totalRowCount = rowCount !== null && rowCount !== void 0 ? rowCount : getPrePaginationRowModel().rows.length;
3804
- const numberOfPages = Math.ceil(totalRowCount / pageSize);
3792
+ const totalRowCount = table.getRowCount();
3793
+ const numberOfPages = table.getPageCount();
3805
3794
  const showFirstLastPageButtons = numberOfPages > 2;
3806
3795
  const firstRowIndex = pageIndex * pageSize;
3807
3796
  const lastRowIndex = Math.min(pageIndex * pageSize + pageSize, totalRowCount);
@@ -3831,17 +3820,17 @@ const MRT_TablePagination = (_a) => {
3831
3820
  }, children: [showRowsPerPage && (jsxRuntime.jsxs(Box__default["default"], { sx: { alignItems: 'center', display: 'flex', gap: '8px' }, children: [jsxRuntime.jsx(InputLabel__default["default"], { htmlFor: "mrt-rows-per-page", sx: { mb: 0 }, children: localization.rowsPerPage }), jsxRuntime.jsx(Select__default["default"], Object.assign({ MenuProps: { disableScrollLock: true }, disableUnderline: true, disabled: disabled, inputProps: {
3832
3821
  'aria-label': localization.rowsPerPage,
3833
3822
  id: 'mrt-rows-per-page',
3834
- }, label: localization.rowsPerPage, onChange: (event) => setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard" }, SelectProps, { children: rowsPerPageOptions.map((option) => {
3823
+ }, label: localization.rowsPerPage, onChange: (event) => table.setPageSize(+event.target.value), sx: { mb: 0 }, value: pageSize, variant: "standard" }, SelectProps, { children: rowsPerPageOptions.map((option) => {
3835
3824
  var _a;
3836
3825
  const value = typeof option !== 'number' ? option.value : option;
3837
3826
  const label = typeof option !== 'number' ? option.label : `${option}`;
3838
3827
  return ((_a = SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.children) !== null && _a !== void 0 ? _a : ((SelectProps === null || SelectProps === void 0 ? void 0 : SelectProps.native) ? (jsxRuntime.jsx("option", { value: value, children: label }, value)) : (jsxRuntime.jsx(MenuItem__default["default"], { sx: { m: 0 }, value: value, children: label }, value))));
3839
- }) }))] })), paginationDisplayMode === 'pages' ? (jsxRuntime.jsx(Pagination__default["default"], Object.assign({ count: numberOfPages, disabled: disabled, onChange: (_e, newPageIndex) => setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsxRuntime.jsx(PaginationItem__default["default"], Object.assign({ slots: {
3828
+ }) }))] })), paginationDisplayMode === 'pages' ? (jsxRuntime.jsx(Pagination__default["default"], Object.assign({ count: numberOfPages, disabled: disabled, onChange: (_e, newPageIndex) => table.setPageIndex(newPageIndex - 1), page: pageIndex + 1, renderItem: (item) => (jsxRuntime.jsx(PaginationItem__default["default"], Object.assign({ slots: {
3840
3829
  first: FirstPageIcon,
3841
3830
  last: LastPageIcon,
3842
3831
  next: ChevronRightIcon,
3843
3832
  previous: ChevronLeftIcon,
3844
- } }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, restPaginationProps))) : paginationDisplayMode === 'default' ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Typography__default["default"], { align: "center", component: "span", sx: { m: '0 4px', minWidth: '8ch' }, variant: "body2", children: `${lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()}-${lastRowIndex.toLocaleString()} ${localization.of} ${totalRowCount.toLocaleString()}` }), jsxRuntime.jsxs(Box__default["default"], { gap: "xs", children: [showFirstButton && (jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToFirstPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToFirstPage, disabled: disableBack, onClick: () => setPageIndex(0), size: "small", children: jsxRuntime.jsx(FirstPageIcon, Object.assign({}, flipIconStyles(theme))) }) }) }))), jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToPreviousPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToPreviousPage, disabled: disableBack, onClick: () => setPageIndex(pageIndex - 1), size: "small", children: jsxRuntime.jsx(ChevronLeftIcon, Object.assign({}, flipIconStyles(theme))) }) }) })), jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToNextPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToNextPage, disabled: disableNext, onClick: () => setPageIndex(pageIndex + 1), size: "small", children: jsxRuntime.jsx(ChevronRightIcon, Object.assign({}, flipIconStyles(theme))) }) }) })), showLastButton && (jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToLastPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToLastPage, disabled: disableNext, onClick: () => setPageIndex(numberOfPages - 1), size: "small", children: jsxRuntime.jsx(LastPageIcon, Object.assign({}, flipIconStyles(theme))) }) }) })))] })] })) : null] }));
3833
+ } }, item))), showFirstButton: showFirstButton, showLastButton: showLastButton }, restPaginationProps))) : paginationDisplayMode === 'default' ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Typography__default["default"], { align: "center", component: "span", sx: { m: '0 4px', minWidth: '8ch' }, variant: "body2", children: `${lastRowIndex === 0 ? 0 : (firstRowIndex + 1).toLocaleString()}-${lastRowIndex.toLocaleString()} ${localization.of} ${totalRowCount.toLocaleString()}` }), jsxRuntime.jsxs(Box__default["default"], { gap: "xs", children: [showFirstButton && (jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToFirstPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToFirstPage, disabled: disableBack, onClick: () => table.firstPage(), size: "small", children: jsxRuntime.jsx(FirstPageIcon, Object.assign({}, flipIconStyles(theme))) }) }) }))), jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToPreviousPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToPreviousPage, disabled: disableBack, onClick: () => table.previousPage(), size: "small", children: jsxRuntime.jsx(ChevronLeftIcon, Object.assign({}, flipIconStyles(theme))) }) }) })), jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToNextPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToNextPage, disabled: disableNext, onClick: () => table.nextPage(), size: "small", children: jsxRuntime.jsx(ChevronRightIcon, Object.assign({}, flipIconStyles(theme))) }) }) })), showLastButton && (jsxRuntime.jsx(Tooltip__default["default"], Object.assign({}, tooltipProps, { title: localization.goToLastPage, children: jsxRuntime.jsx("span", { children: jsxRuntime.jsx(IconButton__default["default"], { "aria-label": localization.goToLastPage, disabled: disableNext, onClick: () => table.lastPage(), size: "small", children: jsxRuntime.jsx(LastPageIcon, Object.assign({}, flipIconStyles(theme))) }) }) })))] })] })) : null] }));
3845
3834
  };
3846
3835
 
3847
3836
  const MRT_ToolbarDropZone = (_a) => {
@@ -3919,9 +3908,7 @@ const MRT_ShowHideColumnsMenuItems = (_a) => {
3919
3908
  const { columnOrder } = getState();
3920
3909
  const { columnDef } = column;
3921
3910
  const { columnDefType } = columnDef;
3922
- const switchChecked = (columnDefType !== 'group' && column.getIsVisible()) ||
3923
- (columnDefType === 'group' &&
3924
- column.getLeafColumns().some((col) => col.getIsVisible()));
3911
+ const switchChecked = column.getIsVisible();
3925
3912
  const handleToggleColumnHidden = (column) => {
3926
3913
  var _a, _b;
3927
3914
  if (columnDefType === 'group') {
@@ -4200,6 +4187,7 @@ const MRT_TablePaper = (_a) => {
4200
4187
  const { getState, options: { enableBottomToolbar, enableTopToolbar, mrtTheme: { baseBackgroundColor }, muiTablePaperProps, renderBottomToolbar, renderTopToolbar, }, refs: { tablePaperRef }, } = table;
4201
4188
  const { isFullScreen } = getState();
4202
4189
  const paperProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiTablePaperProps, { table })), rest);
4190
+ const theme = material.useTheme();
4203
4191
  return (jsxRuntime.jsxs(Paper__default["default"], Object.assign({ elevation: 2 }, paperProps, { ref: (ref) => {
4204
4192
  tablePaperRef.current = ref;
4205
4193
  if (paperProps === null || paperProps === void 0 ? void 0 : paperProps.ref) {
@@ -4219,7 +4207,7 @@ const MRT_TablePaper = (_a) => {
4219
4207
  right: 0,
4220
4208
  top: 0,
4221
4209
  width: '100dvw',
4222
- zIndex: 999,
4210
+ zIndex: theme.zIndex.modal,
4223
4211
  }
4224
4212
  : {})), paperProps === null || paperProps === void 0 ? void 0 : paperProps.style), sx: (theme) => (Object.assign({ backgroundColor: baseBackgroundColor, backgroundImage: 'unset', overflow: 'hidden', transition: 'all 100ms ease-in-out' }, parseFromValuesOrFunc(paperProps === null || paperProps === void 0 ? void 0 : paperProps.sx, theme))), children: [enableTopToolbar &&
4225
4213
  ((_b = parseFromValuesOrFunc(renderTopToolbar, { table })) !== null && _b !== void 0 ? _b : (jsxRuntime.jsx(MRT_TopToolbar, { table: table }))), jsxRuntime.jsx(MRT_TableContainer, { table: table }), enableBottomToolbar &&