@dooherceg/material-react-table 3.2.9 → 3.2.11

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/dist/index.d.ts CHANGED
@@ -647,6 +647,7 @@ type MRT_TableInstance<TData extends MRT_RowData> = Omit<Table<TData>, 'getAllCo
647
647
  setRows: (rows: MRT_RowManipulationInput<TData>) => void;
648
648
  upsertRow: (rows: MRT_RowManipulationInput<TData>) => void;
649
649
  removeRow: (rows: string | string[]) => void;
650
+ refetch?: () => void;
650
651
  };
651
652
  type MRT_DefinedTableOptions<TData extends MRT_RowData> = Omit<MRT_TableOptions<TData>, 'icons' | 'localization' | 'mrtTheme'> & {
652
653
  icons: MRT_Icons;
@@ -1291,6 +1292,9 @@ interface MRT_TableOptions<TData extends MRT_RowData> extends Omit<Partial<Table
1291
1292
  table: MRT_TableInstance<TData>;
1292
1293
  }) => BoxProps) | BoxProps;
1293
1294
  muiNewEntryModalProps?: MRT_NewEntryModalOverrides;
1295
+ newEntryButtonProps?: ((props: {
1296
+ table: MRT_TableInstance<TData>;
1297
+ }) => ButtonProps) | ButtonProps;
1294
1298
  formConfig?: MRT_FormConfig<TData>;
1295
1299
  onActionCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
1296
1300
  onColumnFilterFnsChange?: OnChangeFn<{
@@ -1518,7 +1522,9 @@ type UseServerTableStateReturn = {
1518
1522
  pagination: MRT_PaginationState;
1519
1523
  sorting: MRT_SortingState;
1520
1524
  columnVisibilityShowTrigger: number;
1525
+ refetchIndex: number;
1521
1526
  };
1527
+ refetch: () => void;
1522
1528
  };
1523
1529
  type ColumnType = 'string' | 'number' | 'date' | 'dateTime' | 'enum' | 'icon' | 'dimension' | 'boolean' | 'actions' | 'object';
1524
1530
  type MRT_FilterOperator = 'between' | 'contains' | 'current-month' | 'current-week' | 'endsWith' | 'equals' | 'from-today' | 'fuzzy' | 'greaterThan' | 'greaterThanOrEqualTo' | 'isAnyOf' | 'isEmpty' | 'isNotEmpty' | 'last-7-days' | 'last-month' | 'last-week' | 'lessThan' | 'lessThanOrEqualTo' | 'notContains' | 'notEquals' | 'startsWith' | 'to-today';
@@ -1860,13 +1866,19 @@ type MaterialReactServerTableInstanceProps<TData extends MRT_RowData> = Partial<
1860
1866
  resetState?: (table: MRT_TableInstance<TData>) => Promise<void> | void;
1861
1867
  extendColumns?: Partial<MRT_ColumnDef<TData>>[];
1862
1868
  };
1869
+ type MaterialReactServerTableHandle<TData extends MRT_RowData> = {
1870
+ refetch: () => void;
1871
+ table: MRT_TableInstance<TData>;
1872
+ };
1863
1873
 
1864
1874
  type MaterialReactServerTableProps<TData extends MRT_RowData> = Omit<MaterialReactServerTableInstanceProps<TData>, 'config'> & {
1865
1875
  loadConfig: () => Promise<MRT_TableConfig<TData>>;
1866
1876
  };
1867
1877
  declare const MaterialReactServerTable: <TData extends MRT_RowData & {
1868
1878
  id: string;
1869
- }>({ loadConfig, saveState, localization, ...instanceProps }: MaterialReactServerTableProps<TData>) => react_jsx_runtime.JSX.Element;
1879
+ }>(props: MaterialReactServerTableProps<TData> & {
1880
+ ref?: Ref<MaterialReactServerTableHandle<TData>>;
1881
+ }) => ReactElement;
1870
1882
 
1871
1883
  type TableInstanceProp<TData extends MRT_RowData> = {
1872
1884
  table: MRT_TableInstance<TData>;
package/dist/index.esm.js CHANGED
@@ -771,7 +771,12 @@ function MRT_DeleteRowButton({ onClick, }) {
771
771
  const iconButtonStyle = {
772
772
  p: 0,
773
773
  };
774
- return (jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: onClick, children: jsx(DeleteOutlineIcon, {}) }));
774
+ const handleClick = (event) => {
775
+ // Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
776
+ event.stopPropagation();
777
+ onClick();
778
+ };
779
+ return (jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: handleClick, children: jsx(DeleteOutlineIcon, {}) }));
775
780
  }
776
781
 
777
782
  const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
@@ -806,7 +811,11 @@ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
806
811
  const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
807
812
  setOpen(false);
808
813
  });
809
- return (jsxs(Fragment, { children: [jsx(Dialog, { open: open, onClose: () => setOpen(false), keepMounted: true, "aria-describedby": "alert-dialog-slide-description", role: "alertdialog", sx: dialogSx, children: jsxs(Stack, { flexDirection: "column", height: "min-content", sx: contentContainerSx, children: [jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", sx: Object.assign({ width: '100%' }, headerSx), children: [jsx(DialogTitle, { sx: Object.assign({ p: '0.7rem' }, titleSx), children: deleteConfirmationTitle }), jsx(DialogActions, { sx: {
814
+ return (jsxs(Fragment, { children: [jsx(Dialog, { open: open, onClose: () => setOpen(false), keepMounted: true, "aria-describedby": "alert-dialog-slide-description", role: "alertdialog", sx: dialogSx, children: jsxs(Stack, { flexDirection: "column", height: "min-content", sx: contentContainerSx,
815
+ // Dialog renders via a portal, but React still bubbles synthetic events up
816
+ // through the component tree — stop here so clicks inside the confirmation
817
+ // dialog don't reach muiTableBodyRowProps onClick (row click handlers).
818
+ onClick: (event) => event.stopPropagation(), children: [jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", sx: Object.assign({ width: '100%' }, headerSx), children: [jsx(DialogTitle, { sx: Object.assign({ p: '0.7rem' }, titleSx), children: deleteConfirmationTitle }), jsx(DialogActions, { sx: {
810
819
  p: '0.7rem',
811
820
  }, children: jsx(IconButton, Object.assign({ color: "error", "aria-label": "close", onClick: handleClose }, closeButtonProps, { children: jsx(CancelIcon, {}) })) })] }), jsxs(Stack, { children: [jsx(DialogContent, { sx: Object.assign({ pr: '6rem' }, bodySx), children: deleteConfirmationMessage }), jsxs(DialogActions, { sx: footerSx, children: [jsx(Button, Object.assign({ onClick: () => setOpen(false), disabled: deleting, autoFocus: true, variant: "soft" }, cancelButtonProps, { children: cancelButtonLabel })), jsx(Button, Object.assign({ onClick: handleConfirmDelete, disabled: deleting, variant: "contained", color: "error" }, confirmButtonProps, { children: deleting ? deletingLabel : confirmButtonLabel }))] })] })] }) }), jsx(MRT_DeleteRowButton, { onClick: handleDeleteRowButtonClick })] }));
812
821
  };
@@ -872,7 +881,12 @@ const createDeleteAction = (_a = {}) => {
872
881
  };
873
882
 
874
883
  const MRT_EditRowButton = ({ onClick }) => {
875
- return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: onClick, children: jsx(EditNoteIcon, {}) }));
884
+ const handleClick = (event) => {
885
+ // Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
886
+ event.stopPropagation();
887
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
888
+ };
889
+ return (jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: handleClick, children: jsx(EditNoteIcon, {}) }));
876
890
  };
877
891
 
878
892
  const EditRowAction = ({ onEditButtonClick, }) => {
@@ -6305,13 +6319,19 @@ const MRT_SavedFiltersButton = ({ onSelectFilter, table, }) => {
6305
6319
  };
6306
6320
 
6307
6321
  const MRT_NewEntryButton = (_a) => {
6308
- var _b;
6322
+ var _b, _c;
6309
6323
  var { table } = _a, rest = __rest(_a, ["table"]);
6310
- const { options: { icons: { AddIcon }, localization, }, setNewEntryModal, } = table;
6311
- const handleOpenNewEntryModal = () => {
6324
+ const { options: { icons: { AddIcon }, localization, newEntryButtonProps, }, setNewEntryModal, } = table;
6325
+ const handleOpenNewEntryModal = (event) => {
6326
+ // Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
6327
+ event.stopPropagation();
6312
6328
  setNewEntryModal({ open: true });
6313
6329
  };
6314
- return (jsx(Tooltip, { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.newEntry, children: jsx(Button, Object.assign({ "aria-label": localization.newEntry, onClick: handleOpenNewEntryModal, size: "small", startIcon: jsx(AddIcon, { fontSize: "small" }), variant: "text" }, rest, { title: undefined, children: localization.newEntry })) }));
6330
+ // When the consumer supplies onClick via newEntryButtonProps (or rest), it fully
6331
+ // replaces handleOpenNewEntryModal below — matches the override convention used by
6332
+ // every other mui*ButtonProps option in this codebase.
6333
+ const buttonProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(newEntryButtonProps, { table })), rest);
6334
+ return (jsx(Tooltip, { title: (_b = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.title) !== null && _b !== void 0 ? _b : localization.newEntry, children: jsx(Button, Object.assign({ "aria-label": localization.newEntry, onClick: handleOpenNewEntryModal, size: "small", startIcon: jsx(AddIcon, { fontSize: "small" }), variant: "text" }, buttonProps, { title: undefined, children: (_c = buttonProps === null || buttonProps === void 0 ? void 0 : buttonProps.children) !== null && _c !== void 0 ? _c : localization.newEntry })) }));
6315
6335
  };
6316
6336
 
6317
6337
  const MRT_ShowHideColumnsMenuItems = (_a) => {
@@ -8515,6 +8535,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
8515
8535
  const [expanded, setExpanded] = useState((_k = initialState === null || initialState === void 0 ? void 0 : initialState.expanded) !== null && _k !== void 0 ? _k : {});
8516
8536
  const [rowSelection, setRowSelection] = useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.rowSelection) !== null && _l !== void 0 ? _l : {});
8517
8537
  const [activeExports, setActiveExports] = useState(initialState === null || initialState === void 0 ? void 0 : initialState.activeExports);
8538
+ // Counter that increments on every manual refetch() call, without changing any other state
8539
+ const [refetchIndex, setRefetchIndex] = useState(0);
8540
+ const refetch = () => setRefetchIndex((prev) => prev + 1);
8518
8541
  // --- Debounced save ---
8519
8542
  // saveState is optional — if not provided, do nothing
8520
8543
  const debouncedSave = useDebouncedCallback((partial) => {
@@ -8597,7 +8620,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
8597
8620
  pagination,
8598
8621
  sorting,
8599
8622
  columnVisibilityShowTrigger,
8623
+ refetchIndex,
8600
8624
  },
8625
+ refetch,
8601
8626
  };
8602
8627
  };
8603
8628
 
@@ -8641,7 +8666,7 @@ const buildInitialExportState = (availableExports, savedActiveExports) => {
8641
8666
  grouped: false,
8642
8667
  });
8643
8668
  };
8644
- const MaterialReactServerTableInstance = (_a) => {
8669
+ const MaterialReactServerTableInstanceComponent = (_a, ref) => {
8645
8670
  var _b, _c;
8646
8671
  var { config, loadData, saveState, getAllSelectableRowIds, getTotalRows, onSaveFilters, onDeleteSavedFilter, initialSavedFilters, loadExport, exportPermissions, enableNewEntryButton, actions, deleteRowsFn, editRowFn, enableResetState, resetState, extendColumns } = _a,
8647
8672
  // Extra MRT_TableOptions props (e.g. formConfig) passed directly through to useMaterialReactTable
@@ -8669,7 +8694,7 @@ const MaterialReactServerTableInstance = (_a) => {
8669
8694
  });
8670
8695
  return Object.fromEntries(allowedEntries);
8671
8696
  }, [config.availableExports, exportPermissions]);
8672
- const { tableState, handlers, fetchTrigger } = useServerTableState({
8697
+ const { tableState, handlers, fetchTrigger, refetch } = useServerTableState({
8673
8698
  initialState: Object.assign(Object.assign({}, config.initialState), { activeExports: buildInitialExportState(allowedExports, (_b = config.initialState) === null || _b === void 0 ? void 0 : _b.activeExports) }),
8674
8699
  saveState,
8675
8700
  });
@@ -8689,6 +8714,9 @@ const MaterialReactServerTableInstance = (_a) => {
8689
8714
  editRowFn,
8690
8715
  onSaveFilters,
8691
8716
  onDeleteSavedFilter, initialSavedFilters: initialSavedFilters !== null && initialSavedFilters !== void 0 ? initialSavedFilters : (_c = config.initialState) === null || _c === void 0 ? void 0 : _c.savedFilters, availableExports: hasAvailableExports ? allowedExports : undefined, loadExport: hasAvailableExports ? loadExport : undefined, enableNewEntryButton }, tableOptionsOverrides), handlers));
8717
+ // Lets any code that already has `table` (row actions, deleteRowsFn/editRowFn,
8718
+ // custom cell renderers, etc.) trigger a manual reload without needing a ref.
8719
+ table.refetch = refetch;
8692
8720
  const fetchData = useCallback((tableInstance) => __awaiter(void 0, void 0, void 0, function* () {
8693
8721
  setIsLoading(true);
8694
8722
  try {
@@ -8716,9 +8744,12 @@ const MaterialReactServerTableInstance = (_a) => {
8716
8744
  fetchTrigger.pagination,
8717
8745
  fetchTrigger.sorting,
8718
8746
  fetchTrigger.columnVisibilityShowTrigger,
8747
+ fetchTrigger.refetchIndex,
8719
8748
  ]);
8749
+ useImperativeHandle(ref, () => ({ refetch, table }), [refetch, table]);
8720
8750
  return jsx(MaterialReactTable, { table: table });
8721
8751
  };
8752
+ const MaterialReactServerTableInstance = forwardRef(MaterialReactServerTableInstanceComponent);
8722
8753
 
8723
8754
  const MaterialReactServerTableSkeleton = () => (jsxs(Paper, { "data-testid": "server-table-skeleton", sx: {
8724
8755
  display: 'flex',
@@ -8741,7 +8772,7 @@ const MaterialReactServerTableSkeleton = () => (jsxs(Paper, { "data-testid": "se
8741
8772
  px: '1.3rem',
8742
8773
  }), children: jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '1rem' }, children: [jsx(Skeleton, { animation: "wave", height: 36, variant: "rounded", width: 136 }), jsx(Skeleton, { animation: "wave", height: 31, variant: "text", width: 176 }), jsx(Skeleton, { animation: "wave", height: 22, variant: "text", width: 70 }), jsx(Skeleton, { animation: "wave", height: 24, variant: "circular", width: 24 }), jsx(Skeleton, { animation: "wave", height: 24, variant: "circular", width: 24 })] }) })] }));
8743
8774
 
8744
- const MaterialReactServerTable = (_a) => {
8775
+ const MaterialReactServerTableComponent = (_a, ref) => {
8745
8776
  var { loadConfig, saveState, localization } = _a, instanceProps = __rest(_a, ["loadConfig", "saveState", "localization"]);
8746
8777
  const mergedLocalization = Object.assign(Object.assign({}, MRT_Localization_HR), localization);
8747
8778
  const [configLoading, setConfigLoading] = useState(true);
@@ -8777,8 +8808,9 @@ const MaterialReactServerTable = (_a) => {
8777
8808
  if (!config) {
8778
8809
  return (jsx(MaterialReactServerTableError, { description: mergedLocalization.serverTableErrorMessage }));
8779
8810
  }
8780
- return (jsx(MaterialReactServerTableInstance, Object.assign({ config: config, saveState: saveState }, instanceProps)));
8811
+ return (jsx(MaterialReactServerTableInstance, Object.assign({ ref: ref, config: config, saveState: saveState }, instanceProps)));
8781
8812
  };
8813
+ const MaterialReactServerTable = forwardRef(MaterialReactServerTableComponent);
8782
8814
 
8783
8815
  const MRT_ColumnPinningButtons = (_a) => {
8784
8816
  var { column, table } = _a, rest = __rest(_a, ["column", "table"]);