@ackplus/react-tanstack-data-table 1.0.20 → 1.0.22
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/package.json
CHANGED
|
@@ -10,8 +10,6 @@ const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
|
10
10
|
exports.DataTablePagination = (0, react_1.memo)((props) => {
|
|
11
11
|
const { footerFilter = null, pagination, totalRow, containerSx, paginationProps, footerSx, slots, slotProps } = props, otherProps = tslib_1.__rest(props, ["footerFilter", "pagination", "totalRow", "containerSx", "paginationProps", "footerSx", "slots", "slotProps"]);
|
|
12
12
|
const { table } = (0, data_table_context_1.useDataTableContext)();
|
|
13
|
-
const paginationSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'pagination');
|
|
14
|
-
const PaginationSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'pagination', material_1.TablePagination);
|
|
15
13
|
const mergedContainerProps = (0, slot_helpers_1.mergeSlotProps)({
|
|
16
14
|
sx: Object.assign({ display: 'flex', alignItems: 'center', gap: 1, justifyContent: 'space-between', px: 2 }, containerSx),
|
|
17
15
|
});
|
|
@@ -32,6 +30,6 @@ exports.DataTablePagination = (0, react_1.memo)((props) => {
|
|
|
32
30
|
showLastButton: true,
|
|
33
31
|
labelRowsPerPage: 'Rows per page:',
|
|
34
32
|
labelDisplayedRows: ({ from, to, count }) => `${from}–${to} of ${count !== -1 ? count : `more than ${to}`}`,
|
|
35
|
-
},
|
|
36
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({}, mergedContainerProps, { children: [footerFilter && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: footerSx, children: footerFilter })), (0, jsx_runtime_1.jsx)(
|
|
33
|
+
}, Object.assign(Object.assign({}, paginationProps), otherProps));
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, Object.assign({}, mergedContainerProps, { children: [footerFilter && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: footerSx, children: footerFilter })), (0, jsx_runtime_1.jsx)(material_1.TablePagination, Object.assign({}, mergedPaginationProps))] })));
|
|
37
35
|
});
|
|
@@ -25,7 +25,7 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
25
25
|
pageIndex: 0,
|
|
26
26
|
pageSize: 10,
|
|
27
27
|
},
|
|
28
|
-
|
|
28
|
+
selectionState: { ids: [], type: 'include' },
|
|
29
29
|
globalFilter: '',
|
|
30
30
|
expanded: {},
|
|
31
31
|
columnOrder: [],
|
|
@@ -33,7 +33,7 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
33
33
|
left: [],
|
|
34
34
|
right: [],
|
|
35
35
|
},
|
|
36
|
-
|
|
36
|
+
columnFilter: {
|
|
37
37
|
filters: [],
|
|
38
38
|
logic: 'AND',
|
|
39
39
|
pendingFilters: [],
|
|
@@ -49,20 +49,15 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
49
49
|
const initialStateConfig = (0, react_1.useMemo)(() => {
|
|
50
50
|
return Object.assign(Object.assign({}, DEFAULT_INITIAL_STATE), initialState);
|
|
51
51
|
}, [initialState]);
|
|
52
|
-
const [sorting, setSorting] = (0, react_1.useState)(
|
|
53
|
-
const [pagination, setPagination] = (0, react_1.useState)(
|
|
54
|
-
const [globalFilter, setGlobalFilter] = (0, react_1.useState)(
|
|
55
|
-
const [selectionState, setSelectionState] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.selectionState) ||
|
|
56
|
-
const [columnFilter, setColumnFilter] = (0, react_1.useState)(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
const [expanded, setExpanded] = (0, react_1.useState)(initialStateConfig.expanded);
|
|
63
|
-
const [tableSize, setTableSize] = (0, react_1.useState)(initialTableSize);
|
|
64
|
-
const [columnOrder, setColumnOrder] = (0, react_1.useState)(initialStateConfig.columnOrder);
|
|
65
|
-
const [columnPinning, setColumnPinning] = (0, react_1.useState)(initialStateConfig.columnPinning);
|
|
52
|
+
const [sorting, setSorting] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || DEFAULT_INITIAL_STATE.sorting);
|
|
53
|
+
const [pagination, setPagination] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.pagination) || DEFAULT_INITIAL_STATE.pagination);
|
|
54
|
+
const [globalFilter, setGlobalFilter] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.globalFilter) || DEFAULT_INITIAL_STATE.globalFilter);
|
|
55
|
+
const [selectionState, setSelectionState] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.selectionState) || DEFAULT_INITIAL_STATE.selectionState);
|
|
56
|
+
const [columnFilter, setColumnFilter] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnFilter) || DEFAULT_INITIAL_STATE.columnFilter);
|
|
57
|
+
const [expanded, setExpanded] = (0, react_1.useState)({});
|
|
58
|
+
const [tableSize, setTableSize] = (0, react_1.useState)();
|
|
59
|
+
const [columnOrder, setColumnOrder] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder) || DEFAULT_INITIAL_STATE.columnOrder);
|
|
60
|
+
const [columnPinning, setColumnPinning] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnPinning) || DEFAULT_INITIAL_STATE.columnPinning);
|
|
66
61
|
const [serverData, setServerData] = (0, react_1.useState)(null);
|
|
67
62
|
const [serverTotal, setServerTotal] = (0, react_1.useState)(0);
|
|
68
63
|
const [exportController, setExportController] = (0, react_1.useState)(null);
|
|
@@ -307,7 +302,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
307
302
|
}
|
|
308
303
|
}, 0);
|
|
309
304
|
}, [isServerFiltering, fetchData, tableStateChange]);
|
|
310
|
-
const table = (0, react_table_1.useReactTable)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ _features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature], data: tableData, columns: enhancedColumns, initialState: Object.assign({},
|
|
305
|
+
const table = (0, react_table_1.useReactTable)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ _features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature], data: tableData, columns: enhancedColumns, initialState: Object.assign({}, DEFAULT_INITIAL_STATE), state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (enableSorting ? { sorting } : {})), (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnFilter ? { columnFilter } : {})), (enableRowSelection ? { selectionState } : {})), selectMode: selectMode, enableAdvanceSelection: !!enableRowSelection, isRowSelectable: isRowSelectable }, (enableRowSelection ? { onSelectionStateChange: handleSelectionStateChange } : {})), { enableAdvanceColumnFilter: enableColumnFilter, onColumnFilterChange: onColumnFilterChangeHandler, onColumnFilterApply: onColumnFilterApplyHandler }), (enableSorting ? { onSortingChange: handleSortingChange } : {})), (enablePagination ? { onPaginationChange: handlePaginationChange } : {})), (enableRowSelection ? { onRowSelectionChange: handleSelectionStateChange } : {})), (enableGlobalFilter ? { onGlobalFilterChange: handleGlobalFilterChange } : {})), (enableExpanding ? { onExpandedChange: setExpanded } : {})), (enableColumnDragging ? { onColumnOrderChange: handleColumnOrderChange } : {})), (enableColumnPinning ? { onColumnPinningChange: handleColumnPinningChange } : {})), { getCoreRowModel: (0, react_table_1.getCoreRowModel)() }), (enableSorting ? { getSortedRowModel: (0, react_table_1.getSortedRowModel)() } : {})), (enableColumnFilter ? { getFilteredRowModel: (0, column_filter_feature_1.getCombinedFilteredRowModel)() } : {})), (enablePagination ? { getPaginationRowModel: (0, react_table_1.getPaginationRowModel)() } : {})), { enableSorting: enableSorting, manualSorting: isServerSorting, manualFiltering: isServerFiltering, enableColumnResizing: enableColumnResizing, columnResizeMode: columnResizeMode, enableColumnPinning: enableColumnPinning }), (enableExpanding ? { getRowCanExpand: getRowCanExpand } : {})), { manualPagination: isServerPagination, autoResetPageIndex: false, rowCount: tableTotalRow, getRowId: (row, index) => (0, utils_1.generateRowId)(row, index, idKey), debugAll: false }));
|
|
311
306
|
const rows = ((_a = table.getRowModel()) === null || _a === void 0 ? void 0 : _a.rows) || [];
|
|
312
307
|
const rowVirtualizer = (0, react_virtual_1.useVirtualizer)({
|
|
313
308
|
count: rows.length,
|
|
@@ -366,7 +361,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
366
361
|
enhancedColumns,
|
|
367
362
|
enablePagination,
|
|
368
363
|
enableColumnPinning,
|
|
369
|
-
initialStateConfig,
|
|
364
|
+
initialStateConfig: Object.assign(Object.assign({}, DEFAULT_INITIAL_STATE), initialState),
|
|
370
365
|
selectMode,
|
|
371
366
|
onSelectionChange: handleSelectionStateChange,
|
|
372
367
|
handleColumnFilterStateChange,
|
|
@@ -607,6 +602,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
607
602
|
pageSize: ((_a = filters.pagination) === null || _a === void 0 ? void 0 : _a.pageSize) || ((_b = initialStateConfig.pagination) === null || _b === void 0 ? void 0 : _b.pageSize) || 10,
|
|
608
603
|
};
|
|
609
604
|
const allState = table.getState();
|
|
605
|
+
setPagination(pagination);
|
|
610
606
|
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
|
|
611
607
|
fetchData === null || fetchData === void 0 ? void 0 : fetchData({ pagination });
|
|
612
608
|
},
|
|
@@ -35,7 +35,7 @@ function ServerSideFetchingExample() {
|
|
|
35
35
|
const apiRef = (0, react_1.useRef)(null);
|
|
36
36
|
const handleFetchData = (0, react_1.useCallback)((filters) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
var _a, _b, _c;
|
|
38
|
-
console.log('🔄
|
|
38
|
+
console.log('🔄 handleFetchData', { filters });
|
|
39
39
|
setLoading(true);
|
|
40
40
|
setError(null);
|
|
41
41
|
setLastFetchParams(filters);
|
|
@@ -114,13 +114,12 @@ function ServerSideFetchingExample() {
|
|
|
114
114
|
}
|
|
115
115
|
}), [tab]);
|
|
116
116
|
const handleSelectionChange = (0, react_1.useCallback)((selection) => {
|
|
117
|
-
console.log('🔄 Selection changed:', selection);
|
|
118
117
|
setSelectionInfo(selection);
|
|
119
118
|
}, []);
|
|
120
119
|
(0, react_1.useEffect)(() => {
|
|
121
120
|
var _a;
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
if (tab) {
|
|
122
|
+
console.log('🔄 Refreshing data');
|
|
124
123
|
(_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.data.refresh();
|
|
125
124
|
}
|
|
126
125
|
}, [tab]);
|
|
@@ -233,7 +232,7 @@ function ServerSideFetchingExample() {
|
|
|
233
232
|
}, children: "Update Selected" })] })), enableGlobalFilter: true, enableColumnFilter: true, enableSorting: true, enablePagination: true, initialState: {
|
|
234
233
|
pagination: {
|
|
235
234
|
pageIndex: 0,
|
|
236
|
-
pageSize:
|
|
235
|
+
pageSize: 50,
|
|
237
236
|
},
|
|
238
237
|
columnPinning: {
|
|
239
238
|
left: [types_1.DEFAULT_SELECTION_COLUMN_NAME],
|
|
@@ -245,5 +244,9 @@ function ServerSideFetchingExample() {
|
|
|
245
244
|
console.log('Export completed:', result);
|
|
246
245
|
}, onExportError: (error) => {
|
|
247
246
|
console.error('Export error:', error);
|
|
248
|
-
}, enableHover: true, enableStripes: true, tableSize: "medium", enableColumnVisibility: true, enableTableSizeControl: true, enableReset: true, emptyMessage: "No employees found matching your criteria", skeletonRows: 10
|
|
247
|
+
}, enableHover: true, enableStripes: true, tableSize: "medium", enableColumnVisibility: true, enableTableSizeControl: true, enableReset: true, emptyMessage: "No employees found matching your criteria", skeletonRows: 10, slotProps: {
|
|
248
|
+
pagination: {
|
|
249
|
+
rowsPerPageOptions: [5, 10, 20, 50, 100, 200],
|
|
250
|
+
},
|
|
251
|
+
} })] }));
|
|
249
252
|
}
|
|
@@ -6,21 +6,14 @@ const react_1 = require("react");
|
|
|
6
6
|
function useDebouncedFetch(onFetchData, delay = 300) {
|
|
7
7
|
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
8
8
|
const debounceTimer = (0, react_1.useRef)(null);
|
|
9
|
-
const lastFetchParams = (0, react_1.useRef)('');
|
|
10
9
|
const debouncedFetch = (0, react_1.useCallback)((filters) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
10
|
if (!onFetchData)
|
|
12
11
|
return null;
|
|
13
|
-
const currentParams = JSON.stringify(filters);
|
|
14
12
|
if (debounceTimer.current) {
|
|
15
13
|
clearTimeout(debounceTimer.current);
|
|
16
14
|
}
|
|
17
15
|
return new Promise((resolve) => {
|
|
18
16
|
debounceTimer.current = setTimeout(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
if (lastFetchParams.current === currentParams) {
|
|
20
|
-
resolve(null);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
lastFetchParams.current = currentParams;
|
|
24
17
|
setIsLoading(true);
|
|
25
18
|
try {
|
|
26
19
|
const result = yield onFetchData(filters);
|