@dooherceg/material-react-table 3.2.9 → 3.2.10
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 +10 -1
- package/dist/index.esm.js +36 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +36 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -1518,7 +1519,9 @@ type UseServerTableStateReturn = {
|
|
|
1518
1519
|
pagination: MRT_PaginationState;
|
|
1519
1520
|
sorting: MRT_SortingState;
|
|
1520
1521
|
columnVisibilityShowTrigger: number;
|
|
1522
|
+
refetchIndex: number;
|
|
1521
1523
|
};
|
|
1524
|
+
refetch: () => void;
|
|
1522
1525
|
};
|
|
1523
1526
|
type ColumnType = 'string' | 'number' | 'date' | 'dateTime' | 'enum' | 'icon' | 'dimension' | 'boolean' | 'actions' | 'object';
|
|
1524
1527
|
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 +1863,19 @@ type MaterialReactServerTableInstanceProps<TData extends MRT_RowData> = Partial<
|
|
|
1860
1863
|
resetState?: (table: MRT_TableInstance<TData>) => Promise<void> | void;
|
|
1861
1864
|
extendColumns?: Partial<MRT_ColumnDef<TData>>[];
|
|
1862
1865
|
};
|
|
1866
|
+
type MaterialReactServerTableHandle<TData extends MRT_RowData> = {
|
|
1867
|
+
refetch: () => void;
|
|
1868
|
+
table: MRT_TableInstance<TData>;
|
|
1869
|
+
};
|
|
1863
1870
|
|
|
1864
1871
|
type MaterialReactServerTableProps<TData extends MRT_RowData> = Omit<MaterialReactServerTableInstanceProps<TData>, 'config'> & {
|
|
1865
1872
|
loadConfig: () => Promise<MRT_TableConfig<TData>>;
|
|
1866
1873
|
};
|
|
1867
1874
|
declare const MaterialReactServerTable: <TData extends MRT_RowData & {
|
|
1868
1875
|
id: string;
|
|
1869
|
-
}>(
|
|
1876
|
+
}>(props: MaterialReactServerTableProps<TData> & {
|
|
1877
|
+
ref?: Ref<MaterialReactServerTableHandle<TData>>;
|
|
1878
|
+
}) => ReactElement;
|
|
1870
1879
|
|
|
1871
1880
|
type TableInstanceProp<TData extends MRT_RowData> = {
|
|
1872
1881
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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, }) => {
|
|
@@ -6308,7 +6322,9 @@ const MRT_NewEntryButton = (_a) => {
|
|
|
6308
6322
|
var _b;
|
|
6309
6323
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
|
6310
6324
|
const { options: { icons: { AddIcon }, localization, }, setNewEntryModal, } = table;
|
|
6311
|
-
const handleOpenNewEntryModal = () => {
|
|
6325
|
+
const handleOpenNewEntryModal = (event) => {
|
|
6326
|
+
// Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
|
|
6327
|
+
event.stopPropagation();
|
|
6312
6328
|
setNewEntryModal({ open: true });
|
|
6313
6329
|
};
|
|
6314
6330
|
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 })) }));
|
|
@@ -8515,6 +8531,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
|
|
|
8515
8531
|
const [expanded, setExpanded] = useState((_k = initialState === null || initialState === void 0 ? void 0 : initialState.expanded) !== null && _k !== void 0 ? _k : {});
|
|
8516
8532
|
const [rowSelection, setRowSelection] = useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.rowSelection) !== null && _l !== void 0 ? _l : {});
|
|
8517
8533
|
const [activeExports, setActiveExports] = useState(initialState === null || initialState === void 0 ? void 0 : initialState.activeExports);
|
|
8534
|
+
// Counter that increments on every manual refetch() call, without changing any other state
|
|
8535
|
+
const [refetchIndex, setRefetchIndex] = useState(0);
|
|
8536
|
+
const refetch = () => setRefetchIndex((prev) => prev + 1);
|
|
8518
8537
|
// --- Debounced save ---
|
|
8519
8538
|
// saveState is optional — if not provided, do nothing
|
|
8520
8539
|
const debouncedSave = useDebouncedCallback((partial) => {
|
|
@@ -8597,7 +8616,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
|
|
|
8597
8616
|
pagination,
|
|
8598
8617
|
sorting,
|
|
8599
8618
|
columnVisibilityShowTrigger,
|
|
8619
|
+
refetchIndex,
|
|
8600
8620
|
},
|
|
8621
|
+
refetch,
|
|
8601
8622
|
};
|
|
8602
8623
|
};
|
|
8603
8624
|
|
|
@@ -8641,7 +8662,7 @@ const buildInitialExportState = (availableExports, savedActiveExports) => {
|
|
|
8641
8662
|
grouped: false,
|
|
8642
8663
|
});
|
|
8643
8664
|
};
|
|
8644
|
-
const
|
|
8665
|
+
const MaterialReactServerTableInstanceComponent = (_a, ref) => {
|
|
8645
8666
|
var _b, _c;
|
|
8646
8667
|
var { config, loadData, saveState, getAllSelectableRowIds, getTotalRows, onSaveFilters, onDeleteSavedFilter, initialSavedFilters, loadExport, exportPermissions, enableNewEntryButton, actions, deleteRowsFn, editRowFn, enableResetState, resetState, extendColumns } = _a,
|
|
8647
8668
|
// Extra MRT_TableOptions props (e.g. formConfig) passed directly through to useMaterialReactTable
|
|
@@ -8669,7 +8690,7 @@ const MaterialReactServerTableInstance = (_a) => {
|
|
|
8669
8690
|
});
|
|
8670
8691
|
return Object.fromEntries(allowedEntries);
|
|
8671
8692
|
}, [config.availableExports, exportPermissions]);
|
|
8672
|
-
const { tableState, handlers, fetchTrigger } = useServerTableState({
|
|
8693
|
+
const { tableState, handlers, fetchTrigger, refetch } = useServerTableState({
|
|
8673
8694
|
initialState: Object.assign(Object.assign({}, config.initialState), { activeExports: buildInitialExportState(allowedExports, (_b = config.initialState) === null || _b === void 0 ? void 0 : _b.activeExports) }),
|
|
8674
8695
|
saveState,
|
|
8675
8696
|
});
|
|
@@ -8689,6 +8710,9 @@ const MaterialReactServerTableInstance = (_a) => {
|
|
|
8689
8710
|
editRowFn,
|
|
8690
8711
|
onSaveFilters,
|
|
8691
8712
|
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));
|
|
8713
|
+
// Lets any code that already has `table` (row actions, deleteRowsFn/editRowFn,
|
|
8714
|
+
// custom cell renderers, etc.) trigger a manual reload without needing a ref.
|
|
8715
|
+
table.refetch = refetch;
|
|
8692
8716
|
const fetchData = useCallback((tableInstance) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8693
8717
|
setIsLoading(true);
|
|
8694
8718
|
try {
|
|
@@ -8716,9 +8740,12 @@ const MaterialReactServerTableInstance = (_a) => {
|
|
|
8716
8740
|
fetchTrigger.pagination,
|
|
8717
8741
|
fetchTrigger.sorting,
|
|
8718
8742
|
fetchTrigger.columnVisibilityShowTrigger,
|
|
8743
|
+
fetchTrigger.refetchIndex,
|
|
8719
8744
|
]);
|
|
8745
|
+
useImperativeHandle(ref, () => ({ refetch, table }), [refetch, table]);
|
|
8720
8746
|
return jsx(MaterialReactTable, { table: table });
|
|
8721
8747
|
};
|
|
8748
|
+
const MaterialReactServerTableInstance = forwardRef(MaterialReactServerTableInstanceComponent);
|
|
8722
8749
|
|
|
8723
8750
|
const MaterialReactServerTableSkeleton = () => (jsxs(Paper, { "data-testid": "server-table-skeleton", sx: {
|
|
8724
8751
|
display: 'flex',
|
|
@@ -8741,7 +8768,7 @@ const MaterialReactServerTableSkeleton = () => (jsxs(Paper, { "data-testid": "se
|
|
|
8741
8768
|
px: '1.3rem',
|
|
8742
8769
|
}), 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
8770
|
|
|
8744
|
-
const
|
|
8771
|
+
const MaterialReactServerTableComponent = (_a, ref) => {
|
|
8745
8772
|
var { loadConfig, saveState, localization } = _a, instanceProps = __rest(_a, ["loadConfig", "saveState", "localization"]);
|
|
8746
8773
|
const mergedLocalization = Object.assign(Object.assign({}, MRT_Localization_HR), localization);
|
|
8747
8774
|
const [configLoading, setConfigLoading] = useState(true);
|
|
@@ -8777,8 +8804,9 @@ const MaterialReactServerTable = (_a) => {
|
|
|
8777
8804
|
if (!config) {
|
|
8778
8805
|
return (jsx(MaterialReactServerTableError, { description: mergedLocalization.serverTableErrorMessage }));
|
|
8779
8806
|
}
|
|
8780
|
-
return (jsx(MaterialReactServerTableInstance, Object.assign({ config: config, saveState: saveState }, instanceProps)));
|
|
8807
|
+
return (jsx(MaterialReactServerTableInstance, Object.assign({ ref: ref, config: config, saveState: saveState }, instanceProps)));
|
|
8781
8808
|
};
|
|
8809
|
+
const MaterialReactServerTable = forwardRef(MaterialReactServerTableComponent);
|
|
8782
8810
|
|
|
8783
8811
|
const MRT_ColumnPinningButtons = (_a) => {
|
|
8784
8812
|
var { column, table } = _a, rest = __rest(_a, ["column", "table"]);
|