@ackplus/react-tanstack-data-table 1.0.19-beta-0.13 → 1.0.19-beta-0.15
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 +1 -1
- package/src/lib/components/headers/draggable-header.d.ts +2 -1
- package/src/lib/components/headers/draggable-header.js +7 -5
- package/src/lib/components/headers/table-header.js +1 -1
- package/src/lib/components/table/data-table.js +652 -100
- package/src/lib/components/table/data-table.types.d.ts +4 -2
- package/src/lib/components/toolbar/column-filter-control.js +0 -3
- package/src/lib/components/toolbar/data-table-toolbar.js +1 -1
- package/src/lib/components/toolbar/table-export-control.js +0 -1
- package/src/lib/examples/server-side-fetching-example.js +7 -8
- package/src/lib/features/column-filter.feature.js +0 -1
- package/src/lib/hooks/use-data-table-api.js +22 -14
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ interface DraggableHeaderProps<T> {
|
|
|
7
7
|
onColumnReorder?: (draggedColumnId: string, targetColumnId: string) => void;
|
|
8
8
|
slots?: Record<string, any>;
|
|
9
9
|
slotProps?: Record<string, any>;
|
|
10
|
+
alignment?: 'left' | 'center' | 'right';
|
|
10
11
|
}
|
|
11
|
-
export declare function DraggableHeader<T>({ header, enableSorting, draggable, onColumnReorder, slots, slotProps, }: DraggableHeaderProps<T>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>> | import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare function DraggableHeader<T>({ header, enableSorting, draggable, onColumnReorder, slots, slotProps, alignment, }: DraggableHeaderProps<T>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>> | import("react/jsx-runtime").JSX.Element;
|
|
12
13
|
export {};
|
|
@@ -7,7 +7,7 @@ const material_1 = require("@mui/material");
|
|
|
7
7
|
const react_table_1 = require("@tanstack/react-table");
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const slot_helpers_1 = require("../../utils/slot-helpers");
|
|
10
|
-
function DraggableHeader({ header, enableSorting = true, draggable = false, onColumnReorder, slots, slotProps, }) {
|
|
10
|
+
function DraggableHeader({ header, enableSorting = true, draggable = false, onColumnReorder, slots, slotProps, alignment, }) {
|
|
11
11
|
const [isDragging, setIsDragging] = (0, react_1.useState)(false);
|
|
12
12
|
const [dragOver, setDragOver] = (0, react_1.useState)(false);
|
|
13
13
|
const autoScrollIntervalRef = (0, react_1.useRef)(null);
|
|
@@ -18,6 +18,9 @@ function DraggableHeader({ header, enableSorting = true, draggable = false, onCo
|
|
|
18
18
|
const AUTO_SCROLL_THRESHOLD = 50;
|
|
19
19
|
const AUTO_SCROLL_SPEED = 10;
|
|
20
20
|
const AUTO_SCROLL_INTERVAL = 16;
|
|
21
|
+
const justifyContent = (0, react_1.useMemo)(() => {
|
|
22
|
+
return alignment === 'left' ? 'flex-start' : alignment === 'right' ? 'flex-end' : 'center';
|
|
23
|
+
}, [alignment]);
|
|
21
24
|
const findScrollableContainer = (0, react_1.useCallback)((element) => {
|
|
22
25
|
let searchElement = element;
|
|
23
26
|
if (!searchElement) {
|
|
@@ -191,6 +194,7 @@ function DraggableHeader({ header, enableSorting = true, draggable = false, onCo
|
|
|
191
194
|
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ref: headerElementRef, sx: {
|
|
192
195
|
display: 'flex',
|
|
193
196
|
alignItems: 'center',
|
|
197
|
+
justifyContent: justifyContent,
|
|
194
198
|
gap: 1,
|
|
195
199
|
cursor: getCursor(),
|
|
196
200
|
userSelect: 'none',
|
|
@@ -203,10 +207,8 @@ function DraggableHeader({ header, enableSorting = true, draggable = false, onCo
|
|
|
203
207
|
'&:active': {
|
|
204
208
|
cursor: draggable ? 'grabbing' : 'pointer',
|
|
205
209
|
},
|
|
206
|
-
}, draggable: draggable, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onClick: enableSorting ? handleSort : undefined, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
207
|
-
|
|
208
|
-
display: 'flex',
|
|
209
|
-
alignItems: 'center',
|
|
210
|
+
}, draggable: draggable, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleDrop, onClick: enableSorting ? handleSort : undefined, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "span", sx: {
|
|
211
|
+
display: 'inline-flex',
|
|
210
212
|
gap: 1,
|
|
211
213
|
}, children: [(0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext()), getSortIcon()] }) }));
|
|
212
214
|
}
|
|
@@ -28,7 +28,7 @@ function TableHeader({ draggable = false, enableColumnResizing = false, enableSt
|
|
|
28
28
|
pinnedRightPosition,
|
|
29
29
|
zIndex: isPinned ? 10 : 1,
|
|
30
30
|
disableStickyHeader: enableStickyHeader,
|
|
31
|
-
})) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.headerCell, { children: [(0, jsx_runtime_1.jsx)(draggable_header_1.DraggableHeader, { header: header, enableSorting: enableSorting, draggable: !!(draggable && !isPinned), onColumnReorder: onColumnReorder, slots: slots, slotProps: slotProps }), enableColumnResizing && header.column.getCanResize() ? ((0, jsx_runtime_1.jsx)(material_1.Box, { onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), sx: {
|
|
31
|
+
})) }, slotProps === null || slotProps === void 0 ? void 0 : slotProps.headerCell, { children: [(0, jsx_runtime_1.jsx)(draggable_header_1.DraggableHeader, { header: header, enableSorting: enableSorting, draggable: !!(draggable && !isPinned), onColumnReorder: onColumnReorder, slots: slots, slotProps: slotProps, alignment: alignment }), enableColumnResizing && header.column.getCanResize() ? ((0, jsx_runtime_1.jsx)(material_1.Box, { onMouseDown: header.getResizeHandler(), onTouchStart: header.getResizeHandler(), sx: {
|
|
32
32
|
position: 'absolute',
|
|
33
33
|
right: 0,
|
|
34
34
|
top: '25%',
|
|
@@ -40,7 +40,7 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
40
40
|
pendingLogic: 'AND',
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = true, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableContainerProps = {}, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableColumnVisibility = true, enableTableSizeControl = true, enableExport = true, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, slots = {}, slotProps = {}, }, ref) {
|
|
43
|
+
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = true, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableContainerProps = {}, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableColumnVisibility = true, enableTableSizeControl = true, enableExport = true, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onPaginationChange, onGlobalFilterChange, slots = {}, slotProps = {}, }, ref) {
|
|
44
44
|
var _a;
|
|
45
45
|
const isServerMode = dataMode === 'server';
|
|
46
46
|
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
@@ -68,14 +68,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
68
68
|
const initialStateConfig = (0, react_1.useMemo)(() => {
|
|
69
69
|
return Object.assign(Object.assign({}, DEFAULT_INITIAL_STATE), initialState);
|
|
70
70
|
}, [initialState]);
|
|
71
|
-
(0, react_1.useEffect)(() => {
|
|
72
|
-
setSorting(initialStateConfig.sorting);
|
|
73
|
-
setPagination(initialStateConfig.pagination);
|
|
74
|
-
setGlobalFilter(initialStateConfig.globalFilter);
|
|
75
|
-
setExpanded(initialStateConfig.expanded);
|
|
76
|
-
setColumnOrder(initialStateConfig.columnOrder);
|
|
77
|
-
setColumnPinning(initialStateConfig.columnPinning);
|
|
78
|
-
}, [initialStateConfig]);
|
|
79
71
|
const { debouncedFetch, isLoading: fetchLoading } = (0, debounced_fetch_utils_1.useDebouncedFetch)(onFetchData);
|
|
80
72
|
const tableData = (0, react_1.useMemo)(() => serverData ? serverData : data, [onFetchData, serverData, data]);
|
|
81
73
|
const tableTotalRow = (0, react_1.useMemo)(() => serverData ? serverTotal : totalRow, [onFetchData, serverTotal, totalRow]);
|
|
@@ -156,8 +148,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
156
148
|
sorting,
|
|
157
149
|
debouncedFetch,
|
|
158
150
|
]);
|
|
159
|
-
const fetchDataRef = (0, react_1.useRef)(fetchData);
|
|
160
|
-
fetchDataRef.current = fetchData;
|
|
161
151
|
const handleSelectionStateChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
162
152
|
setSelectionState((prevState) => {
|
|
163
153
|
const newSelectionState = typeof updaterOrValue === 'function'
|
|
@@ -174,14 +164,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
174
164
|
const handleColumnFilterStateChange = (0, react_1.useCallback)((filterState) => {
|
|
175
165
|
if (filterState && typeof filterState === 'object') {
|
|
176
166
|
setColumnFilter(filterState);
|
|
177
|
-
setTimeout(() => {
|
|
178
|
-
if (onColumnFiltersChange) {
|
|
179
|
-
onColumnFiltersChange(filterState);
|
|
180
|
-
}
|
|
181
|
-
}, 0);
|
|
182
167
|
}
|
|
183
168
|
}, [onColumnFiltersChange]);
|
|
184
|
-
const
|
|
169
|
+
const tableStateChange = (0, react_1.useCallback)((overrides = {}) => {
|
|
185
170
|
if (onDataStateChange) {
|
|
186
171
|
const currentState = Object.assign({ globalFilter,
|
|
187
172
|
columnFilter,
|
|
@@ -200,35 +185,35 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
200
185
|
columnOrder,
|
|
201
186
|
columnPinning,
|
|
202
187
|
]);
|
|
203
|
-
const stateChangeRef = (0, react_1.useRef)(notifyDataStateChange);
|
|
204
|
-
stateChangeRef.current = notifyDataStateChange;
|
|
205
188
|
const handleSortingChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
206
189
|
let newSorting = typeof updaterOrValue === 'function'
|
|
207
190
|
? updaterOrValue(sorting)
|
|
208
191
|
: updaterOrValue;
|
|
209
|
-
console.log('handleSortingChange', newSorting);
|
|
210
192
|
newSorting = newSorting.filter((sort) => sort.id);
|
|
211
193
|
setSorting(newSorting);
|
|
212
|
-
|
|
213
|
-
onSortingChange(newSorting);
|
|
214
|
-
}
|
|
194
|
+
onSortingChange === null || onSortingChange === void 0 ? void 0 : onSortingChange(newSorting);
|
|
215
195
|
if (isServerMode || isServerSorting) {
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
const pagination = resetPageToFirst();
|
|
197
|
+
tableStateChange({ sorting: newSorting, pagination });
|
|
198
|
+
fetchData({
|
|
218
199
|
sorting: newSorting,
|
|
200
|
+
pagination,
|
|
219
201
|
});
|
|
220
202
|
}
|
|
221
203
|
else if (onDataStateChange) {
|
|
204
|
+
const pagination = resetPageToFirst();
|
|
222
205
|
setTimeout(() => {
|
|
223
|
-
|
|
206
|
+
tableStateChange({ sorting: newSorting, pagination });
|
|
224
207
|
}, 0);
|
|
225
208
|
}
|
|
226
209
|
}, [
|
|
227
210
|
sorting,
|
|
228
211
|
onSortingChange,
|
|
212
|
+
fetchData,
|
|
229
213
|
isServerMode,
|
|
230
214
|
isServerSorting,
|
|
231
215
|
onDataStateChange,
|
|
216
|
+
tableStateChange,
|
|
232
217
|
]);
|
|
233
218
|
const handleColumnOrderChange = (0, react_1.useCallback)((updatedColumnOrder) => {
|
|
234
219
|
const newColumnOrder = typeof updatedColumnOrder === 'function'
|
|
@@ -253,33 +238,38 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
253
238
|
const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
|
|
254
239
|
if (isServerMode || isServerPagination) {
|
|
255
240
|
setTimeout(() => {
|
|
256
|
-
|
|
257
|
-
|
|
241
|
+
tableStateChange({ pagination: newPagination });
|
|
242
|
+
fetchData({ pagination: newPagination });
|
|
258
243
|
}, 0);
|
|
259
244
|
}
|
|
260
245
|
else if (onDataStateChange) {
|
|
261
246
|
setTimeout(() => {
|
|
262
|
-
|
|
247
|
+
tableStateChange({ pagination: newPagination });
|
|
263
248
|
}, 0);
|
|
264
249
|
}
|
|
265
|
-
|
|
250
|
+
setPagination(newPagination);
|
|
251
|
+
onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
|
|
252
|
+
}, [pagination, isServerMode, isServerPagination, onDataStateChange, fetchData, tableStateChange]);
|
|
266
253
|
const handleGlobalFilterChange = (0, react_1.useCallback)((updaterOrValue) => {
|
|
267
254
|
const newFilter = typeof updaterOrValue === 'function'
|
|
268
255
|
? updaterOrValue(globalFilter)
|
|
269
256
|
: updaterOrValue;
|
|
270
257
|
setGlobalFilter(newFilter);
|
|
271
258
|
if (isServerMode || isServerFiltering) {
|
|
259
|
+
const pagination = resetPageToFirst();
|
|
272
260
|
setTimeout(() => {
|
|
273
|
-
|
|
274
|
-
|
|
261
|
+
tableStateChange({ globalFilter: newFilter, pagination });
|
|
262
|
+
fetchData({ globalFilter: newFilter, pagination });
|
|
275
263
|
}, 0);
|
|
276
264
|
}
|
|
277
265
|
else if (onDataStateChange) {
|
|
266
|
+
const pagination = resetPageToFirst();
|
|
278
267
|
setTimeout(() => {
|
|
279
|
-
|
|
268
|
+
tableStateChange({ globalFilter: newFilter, pagination });
|
|
280
269
|
}, 0);
|
|
281
270
|
}
|
|
282
|
-
|
|
271
|
+
onGlobalFilterChange === null || onGlobalFilterChange === void 0 ? void 0 : onGlobalFilterChange(newFilter);
|
|
272
|
+
}, [globalFilter, isServerMode, isServerFiltering, onDataStateChange, fetchData, tableStateChange]);
|
|
283
273
|
const onColumnFilterChangeHandler = (0, react_1.useCallback)((updater) => {
|
|
284
274
|
const currentState = columnFilter;
|
|
285
275
|
const newState = typeof updater === 'function'
|
|
@@ -294,6 +284,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
294
284
|
handleColumnFilterStateChange(legacyFilterState);
|
|
295
285
|
}, [columnFilter, handleColumnFilterStateChange]);
|
|
296
286
|
const onColumnFilterApplyHandler = (0, react_1.useCallback)((appliedState) => {
|
|
287
|
+
const pagination = resetPageToFirst();
|
|
297
288
|
if (isServerFiltering) {
|
|
298
289
|
const serverFilterState = {
|
|
299
290
|
filters: appliedState.filters,
|
|
@@ -301,51 +292,22 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
301
292
|
pendingFilters: appliedState.pendingFilters,
|
|
302
293
|
pendingLogic: appliedState.pendingLogic,
|
|
303
294
|
};
|
|
304
|
-
|
|
295
|
+
tableStateChange({
|
|
305
296
|
columnFilter: serverFilterState,
|
|
297
|
+
pagination,
|
|
306
298
|
});
|
|
307
|
-
|
|
299
|
+
fetchData({
|
|
308
300
|
columnFilter: serverFilterState,
|
|
301
|
+
pagination,
|
|
309
302
|
});
|
|
310
303
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
selectMode: selectMode,
|
|
319
|
-
enableAdvanceSelection: !!enableRowSelection,
|
|
320
|
-
isRowSelectable: isRowSelectable,
|
|
321
|
-
onSelectionStateChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
322
|
-
enableAdvanceColumnFilter: enableColumnFilter,
|
|
323
|
-
onColumnFilterChange: onColumnFilterChangeHandler,
|
|
324
|
-
onColumnFilterApply: onColumnFilterApplyHandler,
|
|
325
|
-
onSortingChange: enableSorting ? handleSortingChange : undefined,
|
|
326
|
-
onPaginationChange: enablePagination ? handlePaginationChange : undefined,
|
|
327
|
-
onRowSelectionChange: enableRowSelection ? handleSelectionStateChange : undefined,
|
|
328
|
-
onGlobalFilterChange: enableGlobalFilter ? handleGlobalFilterChange : undefined,
|
|
329
|
-
onExpandedChange: enableExpanding ? setExpanded : undefined,
|
|
330
|
-
onColumnOrderChange: enableColumnDragging ? handleColumnOrderChange : undefined,
|
|
331
|
-
onColumnPinningChange: enableColumnPinning ? handleColumnPinningChange : undefined,
|
|
332
|
-
getCoreRowModel: (0, react_table_1.getCoreRowModel)(),
|
|
333
|
-
getSortedRowModel: (enableSorting && !isServerSorting) ? (0, react_table_1.getSortedRowModel)() : undefined,
|
|
334
|
-
getFilteredRowModel: (enableColumnFilter && !isServerFiltering) ? (0, column_filter_feature_1.getCombinedFilteredRowModel)() : undefined,
|
|
335
|
-
getPaginationRowModel: (enablePagination && !isServerPagination) ? (0, react_table_1.getPaginationRowModel)() : undefined,
|
|
336
|
-
enableSorting: enableSorting,
|
|
337
|
-
manualSorting: isServerSorting,
|
|
338
|
-
manualFiltering: isServerFiltering,
|
|
339
|
-
enableColumnResizing: enableColumnResizing,
|
|
340
|
-
columnResizeMode: columnResizeMode,
|
|
341
|
-
enableColumnPinning: enableColumnPinning,
|
|
342
|
-
getRowCanExpand: enableExpanding ? getRowCanExpand : undefined,
|
|
343
|
-
manualPagination: isServerPagination,
|
|
344
|
-
autoResetPageIndex: false,
|
|
345
|
-
rowCount: tableTotalRow,
|
|
346
|
-
getRowId: (row, index) => (0, utils_1.generateRowId)(row, index, idKey),
|
|
347
|
-
debugAll: false,
|
|
348
|
-
});
|
|
304
|
+
setTimeout(() => {
|
|
305
|
+
if (onColumnFiltersChange) {
|
|
306
|
+
onColumnFiltersChange(appliedState);
|
|
307
|
+
}
|
|
308
|
+
}, 0);
|
|
309
|
+
}, [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({}, initialStateConfig), 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 }));
|
|
349
311
|
const rows = ((_a = table.getRowModel()) === null || _a === void 0 ? void 0 : _a.rows) || [];
|
|
350
312
|
const rowVirtualizer = (0, react_virtual_1.useVirtualizer)({
|
|
351
313
|
count: rows.length,
|
|
@@ -354,6 +316,12 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
354
316
|
overscan: 10,
|
|
355
317
|
enabled: enableVirtualization && !enablePagination && rows.length > 0,
|
|
356
318
|
});
|
|
319
|
+
const resetPageToFirst = () => {
|
|
320
|
+
const newPagination = { pageIndex: 0, pageSize: pagination.pageSize };
|
|
321
|
+
setPagination(newPagination);
|
|
322
|
+
onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
|
|
323
|
+
return newPagination;
|
|
324
|
+
};
|
|
357
325
|
const handleColumnReorder = (0, react_1.useCallback)((draggedColumnId, targetColumnId) => {
|
|
358
326
|
const currentOrder = columnOrder.length > 0 ? columnOrder : enhancedColumns.map((col, index) => {
|
|
359
327
|
if (col.id)
|
|
@@ -375,9 +343,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
375
343
|
}, [columnOrder, enhancedColumns, handleColumnOrderChange]);
|
|
376
344
|
(0, react_1.useEffect)(() => {
|
|
377
345
|
if (initialLoadData && onFetchData) {
|
|
378
|
-
|
|
346
|
+
fetchData();
|
|
379
347
|
}
|
|
380
|
-
}, [initialLoadData
|
|
348
|
+
}, [initialLoadData]);
|
|
381
349
|
(0, react_1.useEffect)(() => {
|
|
382
350
|
if (enableColumnDragging && columnOrder.length === 0) {
|
|
383
351
|
const initialOrder = enhancedColumns.map((col, index) => {
|
|
@@ -392,6 +360,614 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
392
360
|
setColumnOrder(initialOrder);
|
|
393
361
|
}
|
|
394
362
|
}, [enableColumnDragging, enhancedColumns, columnOrder.length]);
|
|
363
|
+
(0, use_data_table_api_1.useDataTableApi)({
|
|
364
|
+
table,
|
|
365
|
+
idKey,
|
|
366
|
+
enhancedColumns,
|
|
367
|
+
enablePagination,
|
|
368
|
+
enableColumnPinning,
|
|
369
|
+
initialStateConfig,
|
|
370
|
+
selectMode,
|
|
371
|
+
onSelectionChange: handleSelectionStateChange,
|
|
372
|
+
handleColumnFilterStateChange,
|
|
373
|
+
onDataStateChange,
|
|
374
|
+
onFetchData: fetchData,
|
|
375
|
+
exportFilename,
|
|
376
|
+
onExportProgress,
|
|
377
|
+
onExportComplete,
|
|
378
|
+
onExportError,
|
|
379
|
+
onServerExport,
|
|
380
|
+
exportController,
|
|
381
|
+
setExportController,
|
|
382
|
+
isExporting,
|
|
383
|
+
onDataChange: setServerData,
|
|
384
|
+
dataMode,
|
|
385
|
+
}, internalApiRef);
|
|
386
|
+
(0, react_1.useImperativeHandle)(ref, () => internalApiRef.current, []);
|
|
387
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
388
|
+
table: {
|
|
389
|
+
getTable: () => table,
|
|
390
|
+
},
|
|
391
|
+
columnVisibility: {
|
|
392
|
+
showColumn: (columnId) => {
|
|
393
|
+
var _a;
|
|
394
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility(true);
|
|
395
|
+
},
|
|
396
|
+
hideColumn: (columnId) => {
|
|
397
|
+
var _a;
|
|
398
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility(false);
|
|
399
|
+
},
|
|
400
|
+
toggleColumn: (columnId) => {
|
|
401
|
+
var _a;
|
|
402
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility();
|
|
403
|
+
},
|
|
404
|
+
showAllColumns: () => {
|
|
405
|
+
table.toggleAllColumnsVisible(true);
|
|
406
|
+
},
|
|
407
|
+
hideAllColumns: () => {
|
|
408
|
+
table.toggleAllColumnsVisible(false);
|
|
409
|
+
},
|
|
410
|
+
resetColumnVisibility: () => {
|
|
411
|
+
table.resetColumnVisibility();
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
columnOrdering: {
|
|
415
|
+
setColumnOrder: (columnOrder) => {
|
|
416
|
+
table.setColumnOrder(columnOrder);
|
|
417
|
+
},
|
|
418
|
+
moveColumn: (columnId, toIndex) => {
|
|
419
|
+
const currentOrder = table.getState().columnOrder || [];
|
|
420
|
+
const currentIndex = currentOrder.indexOf(columnId);
|
|
421
|
+
if (currentIndex === -1)
|
|
422
|
+
return;
|
|
423
|
+
const newOrder = [...currentOrder];
|
|
424
|
+
newOrder.splice(currentIndex, 1);
|
|
425
|
+
newOrder.splice(toIndex, 0, columnId);
|
|
426
|
+
table.setColumnOrder(newOrder);
|
|
427
|
+
},
|
|
428
|
+
resetColumnOrder: () => {
|
|
429
|
+
const initialOrder = enhancedColumns.map((col, index) => {
|
|
430
|
+
if (col.id)
|
|
431
|
+
return col.id;
|
|
432
|
+
const anyCol = col;
|
|
433
|
+
if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
|
|
434
|
+
return anyCol.accessorKey;
|
|
435
|
+
}
|
|
436
|
+
return `column_${index}`;
|
|
437
|
+
});
|
|
438
|
+
table.setColumnOrder(initialOrder);
|
|
439
|
+
},
|
|
440
|
+
},
|
|
441
|
+
columnPinning: {
|
|
442
|
+
pinColumnLeft: (columnId) => {
|
|
443
|
+
const currentPinning = table.getState().columnPinning;
|
|
444
|
+
const newPinning = Object.assign({}, currentPinning);
|
|
445
|
+
newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
|
|
446
|
+
newPinning.left = [...(newPinning.left || []).filter(id => id !== columnId), columnId];
|
|
447
|
+
table.setColumnPinning(newPinning);
|
|
448
|
+
},
|
|
449
|
+
pinColumnRight: (columnId) => {
|
|
450
|
+
const currentPinning = table.getState().columnPinning;
|
|
451
|
+
const newPinning = Object.assign({}, currentPinning);
|
|
452
|
+
newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
|
|
453
|
+
newPinning.right = [...(newPinning.right || []).filter(id => id !== columnId), columnId];
|
|
454
|
+
table.setColumnPinning(newPinning);
|
|
455
|
+
},
|
|
456
|
+
unpinColumn: (columnId) => {
|
|
457
|
+
const currentPinning = table.getState().columnPinning;
|
|
458
|
+
const newPinning = {
|
|
459
|
+
left: (currentPinning.left || []).filter(id => id !== columnId),
|
|
460
|
+
right: (currentPinning.right || []).filter(id => id !== columnId),
|
|
461
|
+
};
|
|
462
|
+
table.setColumnPinning(newPinning);
|
|
463
|
+
},
|
|
464
|
+
setPinning: (pinning) => {
|
|
465
|
+
table.setColumnPinning(pinning);
|
|
466
|
+
},
|
|
467
|
+
resetColumnPinning: () => {
|
|
468
|
+
table.setColumnPinning(table.initialState.columnPinning);
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
columnResizing: {
|
|
472
|
+
resizeColumn: (columnId, width) => {
|
|
473
|
+
const currentSizing = table.getState().columnSizing;
|
|
474
|
+
table.setColumnSizing(Object.assign(Object.assign({}, currentSizing), { [columnId]: width }));
|
|
475
|
+
},
|
|
476
|
+
autoSizeColumn: (columnId) => {
|
|
477
|
+
var _a;
|
|
478
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.resetSize();
|
|
479
|
+
},
|
|
480
|
+
autoSizeAllColumns: () => {
|
|
481
|
+
table.resetColumnSizing();
|
|
482
|
+
},
|
|
483
|
+
resetColumnSizing: () => {
|
|
484
|
+
table.resetColumnSizing();
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
filtering: {
|
|
488
|
+
setGlobalFilter: (filter) => {
|
|
489
|
+
table.setGlobalFilter(filter);
|
|
490
|
+
},
|
|
491
|
+
clearGlobalFilter: () => {
|
|
492
|
+
table.setGlobalFilter('');
|
|
493
|
+
},
|
|
494
|
+
setColumnFilters: (filters) => {
|
|
495
|
+
handleColumnFilterStateChange(filters);
|
|
496
|
+
},
|
|
497
|
+
addColumnFilter: (columnId, operator, value) => {
|
|
498
|
+
const newFilter = {
|
|
499
|
+
id: `filter_${Date.now()}`,
|
|
500
|
+
columnId,
|
|
501
|
+
operator,
|
|
502
|
+
value,
|
|
503
|
+
};
|
|
504
|
+
const columnFilter = table.getState().columnFilter;
|
|
505
|
+
const currentFilters = columnFilter.filters || [];
|
|
506
|
+
const newFilters = [...currentFilters, newFilter];
|
|
507
|
+
handleColumnFilterStateChange({
|
|
508
|
+
filters: newFilters,
|
|
509
|
+
logic: columnFilter.logic,
|
|
510
|
+
pendingFilters: columnFilter.pendingFilters || [],
|
|
511
|
+
pendingLogic: columnFilter.pendingLogic || 'AND',
|
|
512
|
+
});
|
|
513
|
+
},
|
|
514
|
+
removeColumnFilter: (filterId) => {
|
|
515
|
+
const columnFilter = table.getState().columnFilter;
|
|
516
|
+
const currentFilters = columnFilter.filters || [];
|
|
517
|
+
const newFilters = currentFilters.filter((f) => f.id !== filterId);
|
|
518
|
+
handleColumnFilterStateChange({
|
|
519
|
+
filters: newFilters,
|
|
520
|
+
logic: columnFilter.logic,
|
|
521
|
+
pendingFilters: columnFilter.pendingFilters || [],
|
|
522
|
+
pendingLogic: columnFilter.pendingLogic || 'AND',
|
|
523
|
+
});
|
|
524
|
+
},
|
|
525
|
+
clearAllFilters: () => {
|
|
526
|
+
table.setGlobalFilter('');
|
|
527
|
+
handleColumnFilterStateChange({
|
|
528
|
+
filters: [],
|
|
529
|
+
logic: 'AND',
|
|
530
|
+
pendingFilters: [],
|
|
531
|
+
pendingLogic: 'AND',
|
|
532
|
+
});
|
|
533
|
+
},
|
|
534
|
+
resetFilters: () => {
|
|
535
|
+
table.resetGlobalFilter();
|
|
536
|
+
handleColumnFilterStateChange({
|
|
537
|
+
filters: [],
|
|
538
|
+
logic: 'AND',
|
|
539
|
+
pendingFilters: [],
|
|
540
|
+
pendingLogic: 'AND',
|
|
541
|
+
});
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
|
+
sorting: {
|
|
545
|
+
setSorting: (sortingState) => {
|
|
546
|
+
table.setSorting(sortingState);
|
|
547
|
+
},
|
|
548
|
+
sortColumn: (columnId, direction) => {
|
|
549
|
+
const column = table.getColumn(columnId);
|
|
550
|
+
if (!column)
|
|
551
|
+
return;
|
|
552
|
+
if (direction === false) {
|
|
553
|
+
column.clearSorting();
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
column.toggleSorting(direction === 'desc');
|
|
557
|
+
}
|
|
558
|
+
},
|
|
559
|
+
clearSorting: () => {
|
|
560
|
+
table.resetSorting();
|
|
561
|
+
},
|
|
562
|
+
resetSorting: () => {
|
|
563
|
+
table.resetSorting();
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
pagination: {
|
|
567
|
+
goToPage: (pageIndex) => {
|
|
568
|
+
table.setPageIndex(pageIndex);
|
|
569
|
+
},
|
|
570
|
+
nextPage: () => {
|
|
571
|
+
table.nextPage();
|
|
572
|
+
},
|
|
573
|
+
previousPage: () => {
|
|
574
|
+
table.previousPage();
|
|
575
|
+
},
|
|
576
|
+
setPageSize: (pageSize) => {
|
|
577
|
+
table.setPageSize(pageSize);
|
|
578
|
+
},
|
|
579
|
+
goToFirstPage: () => {
|
|
580
|
+
table.setPageIndex(0);
|
|
581
|
+
},
|
|
582
|
+
goToLastPage: () => {
|
|
583
|
+
const pageCount = table.getPageCount();
|
|
584
|
+
if (pageCount > 0) {
|
|
585
|
+
table.setPageIndex(pageCount - 1);
|
|
586
|
+
}
|
|
587
|
+
},
|
|
588
|
+
},
|
|
589
|
+
selection: {
|
|
590
|
+
selectRow: (rowId) => { var _a; return (_a = table.selectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
591
|
+
deselectRow: (rowId) => { var _a; return (_a = table.deselectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
592
|
+
toggleRowSelection: (rowId) => { var _a; return (_a = table.toggleRowSelected) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
593
|
+
selectAll: () => { var _a; return (_a = table.selectAll) === null || _a === void 0 ? void 0 : _a.call(table); },
|
|
594
|
+
deselectAll: () => { var _a; return (_a = table.deselectAll) === null || _a === void 0 ? void 0 : _a.call(table); },
|
|
595
|
+
toggleSelectAll: () => { var _a; return (_a = table.toggleAllRowsSelected) === null || _a === void 0 ? void 0 : _a.call(table); },
|
|
596
|
+
getSelectionState: () => { var _a; return ((_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table)) || { ids: [], type: 'include' }; },
|
|
597
|
+
getSelectedRows: () => table.getSelectedRows(),
|
|
598
|
+
getSelectedCount: () => table.getSelectedCount(),
|
|
599
|
+
isRowSelected: (rowId) => table.getIsRowSelected(rowId) || false,
|
|
600
|
+
},
|
|
601
|
+
data: {
|
|
602
|
+
refresh: () => {
|
|
603
|
+
var _a, _b;
|
|
604
|
+
const filters = table.getState();
|
|
605
|
+
const pagination = {
|
|
606
|
+
pageIndex: 0,
|
|
607
|
+
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
|
+
};
|
|
609
|
+
const allState = table.getState();
|
|
610
|
+
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
|
|
611
|
+
fetchData === null || fetchData === void 0 ? void 0 : fetchData({ pagination });
|
|
612
|
+
},
|
|
613
|
+
reload: () => {
|
|
614
|
+
const allState = table.getState();
|
|
615
|
+
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
|
|
616
|
+
onFetchData === null || onFetchData === void 0 ? void 0 : onFetchData({});
|
|
617
|
+
},
|
|
618
|
+
getAllData: () => {
|
|
619
|
+
var _a;
|
|
620
|
+
return ((_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original)) || [];
|
|
621
|
+
},
|
|
622
|
+
getRowData: (rowId) => {
|
|
623
|
+
var _a, _b;
|
|
624
|
+
return (_b = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.find(row => String(row.original[idKey]) === rowId)) === null || _b === void 0 ? void 0 : _b.original;
|
|
625
|
+
},
|
|
626
|
+
getRowByIndex: (index) => {
|
|
627
|
+
var _a, _b;
|
|
628
|
+
return (_b = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.original;
|
|
629
|
+
},
|
|
630
|
+
updateRow: (rowId, updates) => {
|
|
631
|
+
var _a;
|
|
632
|
+
const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
|
|
633
|
+
? Object.assign(Object.assign({}, row.original), updates) : row.original);
|
|
634
|
+
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData || []);
|
|
635
|
+
},
|
|
636
|
+
updateRowByIndex: (index, updates) => {
|
|
637
|
+
var _a;
|
|
638
|
+
const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
639
|
+
if (newData === null || newData === void 0 ? void 0 : newData[index]) {
|
|
640
|
+
newData[index] = Object.assign(Object.assign({}, newData[index]), updates);
|
|
641
|
+
setServerData(newData);
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
insertRow: (newRow, index) => {
|
|
645
|
+
var _a;
|
|
646
|
+
const newData = ((_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original)) || [];
|
|
647
|
+
if (index !== undefined) {
|
|
648
|
+
newData.splice(index, 0, newRow);
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
newData.push(newRow);
|
|
652
|
+
}
|
|
653
|
+
setServerData(newData || []);
|
|
654
|
+
},
|
|
655
|
+
deleteRow: (rowId) => {
|
|
656
|
+
var _a;
|
|
657
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => String(row.original[idKey]) !== rowId);
|
|
658
|
+
setServerData === null || setServerData === void 0 ? void 0 : setServerData((newData === null || newData === void 0 ? void 0 : newData.map(row => row.original)) || []);
|
|
659
|
+
},
|
|
660
|
+
deleteRowByIndex: (index) => {
|
|
661
|
+
var _a;
|
|
662
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
663
|
+
newData.splice(index, 1);
|
|
664
|
+
setServerData(newData);
|
|
665
|
+
},
|
|
666
|
+
deleteSelectedRows: () => {
|
|
667
|
+
var _a;
|
|
668
|
+
const selectedRowIds = Object.keys(table.getState().rowSelection)
|
|
669
|
+
.filter(key => table.getState().rowSelection[key]);
|
|
670
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => !selectedRowIds.includes(String(row.original[idKey])));
|
|
671
|
+
setServerData((newData === null || newData === void 0 ? void 0 : newData.map(row => row.original)) || []);
|
|
672
|
+
table.resetRowSelection();
|
|
673
|
+
},
|
|
674
|
+
replaceAllData: (newData) => {
|
|
675
|
+
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
676
|
+
},
|
|
677
|
+
updateMultipleRows: (updates) => {
|
|
678
|
+
var _a;
|
|
679
|
+
const updateMap = new Map(updates.map(u => [u.rowId, u.data]));
|
|
680
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => {
|
|
681
|
+
const rowId = String(row.original[idKey]);
|
|
682
|
+
const updateData = updateMap.get(rowId);
|
|
683
|
+
return updateData ? Object.assign(Object.assign({}, row.original), updateData) : row.original;
|
|
684
|
+
});
|
|
685
|
+
setServerData(newData || []);
|
|
686
|
+
},
|
|
687
|
+
insertMultipleRows: (newRows, startIndex) => {
|
|
688
|
+
var _a;
|
|
689
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
690
|
+
if (startIndex !== undefined) {
|
|
691
|
+
newData.splice(startIndex, 0, ...newRows);
|
|
692
|
+
}
|
|
693
|
+
else {
|
|
694
|
+
newData.push(...newRows);
|
|
695
|
+
}
|
|
696
|
+
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
697
|
+
},
|
|
698
|
+
deleteMultipleRows: (rowIds) => {
|
|
699
|
+
var _a, _b;
|
|
700
|
+
const idsToDelete = new Set(rowIds);
|
|
701
|
+
const newData = (_b = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => !idsToDelete.has(String(row.original[idKey])))) === null || _b === void 0 ? void 0 : _b.map(row => row.original);
|
|
702
|
+
setServerData(newData);
|
|
703
|
+
},
|
|
704
|
+
updateField: (rowId, fieldName, value) => {
|
|
705
|
+
var _a;
|
|
706
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
|
|
707
|
+
? Object.assign(Object.assign({}, row.original), { [fieldName]: value }) : row.original);
|
|
708
|
+
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
709
|
+
},
|
|
710
|
+
updateFieldByIndex: (index, fieldName, value) => {
|
|
711
|
+
var _a;
|
|
712
|
+
const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
|
|
713
|
+
if (newData[index]) {
|
|
714
|
+
newData[index] = Object.assign(Object.assign({}, newData[index]), { [fieldName]: value });
|
|
715
|
+
setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
findRows: (predicate) => {
|
|
719
|
+
var _a, _b;
|
|
720
|
+
return (_b = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => predicate(row.original))) === null || _b === void 0 ? void 0 : _b.map(row => row.original);
|
|
721
|
+
},
|
|
722
|
+
findRowIndex: (predicate) => {
|
|
723
|
+
var _a;
|
|
724
|
+
return (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.findIndex(row => predicate(row.original));
|
|
725
|
+
},
|
|
726
|
+
getDataCount: () => {
|
|
727
|
+
var _a;
|
|
728
|
+
return ((_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.length) || 0;
|
|
729
|
+
},
|
|
730
|
+
getFilteredDataCount: () => {
|
|
731
|
+
return table.getFilteredRowModel().rows.length;
|
|
732
|
+
},
|
|
733
|
+
},
|
|
734
|
+
layout: {
|
|
735
|
+
resetLayout: () => {
|
|
736
|
+
table.resetColumnSizing();
|
|
737
|
+
table.resetColumnVisibility();
|
|
738
|
+
table.resetSorting();
|
|
739
|
+
table.resetGlobalFilter();
|
|
740
|
+
},
|
|
741
|
+
resetAll: () => {
|
|
742
|
+
table.resetColumnSizing();
|
|
743
|
+
table.resetColumnVisibility();
|
|
744
|
+
table.resetSorting();
|
|
745
|
+
table.resetGlobalFilter();
|
|
746
|
+
table.resetColumnOrder();
|
|
747
|
+
table.resetExpanded();
|
|
748
|
+
table.resetRowSelection();
|
|
749
|
+
table.resetColumnPinning();
|
|
750
|
+
handleColumnFilterStateChange(initialStateConfig.columnFilter || { filters: [], logic: 'AND', pendingFilters: [], pendingLogic: 'AND' });
|
|
751
|
+
if (enablePagination) {
|
|
752
|
+
table.setPagination(initialStateConfig.pagination || { pageIndex: 0, pageSize: 10 });
|
|
753
|
+
}
|
|
754
|
+
if (enableColumnPinning) {
|
|
755
|
+
table.setColumnPinning(initialStateConfig.columnPinning || { left: [], right: [] });
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
saveLayout: () => {
|
|
759
|
+
return {
|
|
760
|
+
columnVisibility: table.getState().columnVisibility,
|
|
761
|
+
columnSizing: table.getState().columnSizing,
|
|
762
|
+
columnOrder: table.getState().columnOrder,
|
|
763
|
+
columnPinning: table.getState().columnPinning,
|
|
764
|
+
sorting: table.getState().sorting,
|
|
765
|
+
pagination: table.getState().pagination,
|
|
766
|
+
globalFilter: table.getState().globalFilter,
|
|
767
|
+
columnFilter: table.getState().columnFilter,
|
|
768
|
+
};
|
|
769
|
+
},
|
|
770
|
+
restoreLayout: (layout) => {
|
|
771
|
+
if (layout.columnVisibility) {
|
|
772
|
+
table.setColumnVisibility(layout.columnVisibility);
|
|
773
|
+
}
|
|
774
|
+
if (layout.columnSizing) {
|
|
775
|
+
table.setColumnSizing(layout.columnSizing);
|
|
776
|
+
}
|
|
777
|
+
if (layout.columnOrder) {
|
|
778
|
+
table.setColumnOrder(layout.columnOrder);
|
|
779
|
+
}
|
|
780
|
+
if (layout.columnPinning) {
|
|
781
|
+
table.setColumnPinning(layout.columnPinning);
|
|
782
|
+
}
|
|
783
|
+
if (layout.sorting) {
|
|
784
|
+
table.setSorting(layout.sorting);
|
|
785
|
+
}
|
|
786
|
+
if (layout.pagination && enablePagination) {
|
|
787
|
+
table.setPagination(layout.pagination);
|
|
788
|
+
}
|
|
789
|
+
if (layout.globalFilter !== undefined) {
|
|
790
|
+
table.setGlobalFilter(layout.globalFilter);
|
|
791
|
+
}
|
|
792
|
+
if (layout.columnFilter) {
|
|
793
|
+
handleColumnFilterStateChange(layout.columnFilter);
|
|
794
|
+
}
|
|
795
|
+
},
|
|
796
|
+
},
|
|
797
|
+
state: {
|
|
798
|
+
getTableState: () => {
|
|
799
|
+
return table.getState();
|
|
800
|
+
},
|
|
801
|
+
getCurrentFilters: () => {
|
|
802
|
+
return table.getState().columnFilter;
|
|
803
|
+
},
|
|
804
|
+
getCurrentSorting: () => {
|
|
805
|
+
return table.getState().sorting;
|
|
806
|
+
},
|
|
807
|
+
getCurrentPagination: () => {
|
|
808
|
+
return table.getState().pagination;
|
|
809
|
+
},
|
|
810
|
+
getCurrentSelection: () => {
|
|
811
|
+
return Object.keys(table.getState().rowSelection)
|
|
812
|
+
.filter(key => table.getState().rowSelection[key]);
|
|
813
|
+
},
|
|
814
|
+
},
|
|
815
|
+
export: {
|
|
816
|
+
exportCSV: (...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (options = {}) {
|
|
817
|
+
var _a;
|
|
818
|
+
const { filename = exportFilename, } = options;
|
|
819
|
+
try {
|
|
820
|
+
const controller = new AbortController();
|
|
821
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
822
|
+
if (dataMode === 'server' && onServerExport) {
|
|
823
|
+
const currentFilters = {
|
|
824
|
+
globalFilter: table.getState().globalFilter,
|
|
825
|
+
columnFilter: table.getState().columnFilter,
|
|
826
|
+
sorting: table.getState().sorting,
|
|
827
|
+
pagination: table.getState().pagination,
|
|
828
|
+
};
|
|
829
|
+
yield (0, utils_1.exportServerData)(table, {
|
|
830
|
+
format: 'csv',
|
|
831
|
+
filename,
|
|
832
|
+
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
833
|
+
currentFilters,
|
|
834
|
+
selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
|
|
835
|
+
onProgress: onExportProgress,
|
|
836
|
+
onComplete: onExportComplete,
|
|
837
|
+
onError: onExportError,
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
yield (0, utils_1.exportClientData)(table, {
|
|
842
|
+
format: 'csv',
|
|
843
|
+
filename,
|
|
844
|
+
onProgress: onExportProgress,
|
|
845
|
+
onComplete: onExportComplete,
|
|
846
|
+
onError: onExportError,
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
catch (error) {
|
|
851
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
852
|
+
message: error.message || 'Export failed',
|
|
853
|
+
code: 'EXPORT_ERROR',
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
finally {
|
|
857
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
858
|
+
}
|
|
859
|
+
}),
|
|
860
|
+
exportExcel: (...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (options = {}) {
|
|
861
|
+
var _a;
|
|
862
|
+
const { filename = exportFilename } = options;
|
|
863
|
+
try {
|
|
864
|
+
const controller = new AbortController();
|
|
865
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
866
|
+
if (dataMode === 'server' && onServerExport) {
|
|
867
|
+
const currentFilters = {
|
|
868
|
+
globalFilter: table.getState().globalFilter,
|
|
869
|
+
columnFilter: table.getState().columnFilter,
|
|
870
|
+
sorting: table.getState().sorting,
|
|
871
|
+
pagination: table.getState().pagination,
|
|
872
|
+
};
|
|
873
|
+
yield (0, utils_1.exportServerData)(table, {
|
|
874
|
+
format: 'excel',
|
|
875
|
+
filename,
|
|
876
|
+
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
877
|
+
currentFilters,
|
|
878
|
+
selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
|
|
879
|
+
onProgress: onExportProgress,
|
|
880
|
+
onComplete: onExportComplete,
|
|
881
|
+
onError: onExportError,
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
else {
|
|
885
|
+
yield (0, utils_1.exportClientData)(table, {
|
|
886
|
+
format: 'excel',
|
|
887
|
+
filename,
|
|
888
|
+
onProgress: onExportProgress,
|
|
889
|
+
onComplete: onExportComplete,
|
|
890
|
+
onError: onExportError,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
catch (error) {
|
|
895
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
896
|
+
message: error.message || 'Export failed',
|
|
897
|
+
code: 'EXPORT_ERROR',
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
finally {
|
|
901
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
902
|
+
}
|
|
903
|
+
}),
|
|
904
|
+
exportServerData: (options) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
905
|
+
var _a;
|
|
906
|
+
const { format, filename = exportFilename, fetchData = onServerExport, } = options;
|
|
907
|
+
if (!fetchData) {
|
|
908
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
909
|
+
message: 'No server export function provided',
|
|
910
|
+
code: 'NO_SERVER_EXPORT',
|
|
911
|
+
});
|
|
912
|
+
return;
|
|
913
|
+
}
|
|
914
|
+
try {
|
|
915
|
+
const controller = new AbortController();
|
|
916
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
917
|
+
const currentFilters = {
|
|
918
|
+
globalFilter: table.getState().globalFilter,
|
|
919
|
+
columnFilter: table.getState().columnFilter,
|
|
920
|
+
sorting: table.getState().sorting,
|
|
921
|
+
pagination: table.getState().pagination,
|
|
922
|
+
};
|
|
923
|
+
yield (0, utils_1.exportServerData)(table, {
|
|
924
|
+
format,
|
|
925
|
+
filename,
|
|
926
|
+
fetchData: (filters, selection) => fetchData(filters, selection),
|
|
927
|
+
currentFilters,
|
|
928
|
+
selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
|
|
929
|
+
onProgress: onExportProgress,
|
|
930
|
+
onComplete: onExportComplete,
|
|
931
|
+
onError: onExportError,
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
catch (error) {
|
|
935
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
936
|
+
message: error.message || 'Export failed',
|
|
937
|
+
code: 'EXPORT_ERROR',
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
finally {
|
|
941
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
942
|
+
}
|
|
943
|
+
}),
|
|
944
|
+
isExporting: () => isExporting || false,
|
|
945
|
+
cancelExport: () => {
|
|
946
|
+
exportController === null || exportController === void 0 ? void 0 : exportController.abort();
|
|
947
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
948
|
+
},
|
|
949
|
+
},
|
|
950
|
+
}), [
|
|
951
|
+
table,
|
|
952
|
+
enhancedColumns,
|
|
953
|
+
handleColumnFilterStateChange,
|
|
954
|
+
idKey,
|
|
955
|
+
onDataStateChange,
|
|
956
|
+
onFetchData,
|
|
957
|
+
enableColumnPinning,
|
|
958
|
+
enablePagination,
|
|
959
|
+
exportFilename,
|
|
960
|
+
onExportProgress,
|
|
961
|
+
onExportComplete,
|
|
962
|
+
onExportError,
|
|
963
|
+
onServerExport,
|
|
964
|
+
exportController,
|
|
965
|
+
setExportController,
|
|
966
|
+
isExporting,
|
|
967
|
+
dataMode,
|
|
968
|
+
selectMode,
|
|
969
|
+
onSelectionChange,
|
|
970
|
+
]);
|
|
395
971
|
const LoadingRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'loadingRow', rows_1.LoadingRows);
|
|
396
972
|
const EmptyRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'emptyRow', rows_1.EmptyDataRow);
|
|
397
973
|
const renderTableRows = (0, react_1.useCallback)(() => {
|
|
@@ -449,30 +1025,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
449
1025
|
}
|
|
450
1026
|
}
|
|
451
1027
|
}, [exportController, onExportCancel]);
|
|
452
|
-
(0, use_data_table_api_1.useDataTableApi)({
|
|
453
|
-
table,
|
|
454
|
-
idKey,
|
|
455
|
-
enhancedColumns,
|
|
456
|
-
enablePagination,
|
|
457
|
-
enableColumnPinning,
|
|
458
|
-
initialStateConfig,
|
|
459
|
-
selectMode,
|
|
460
|
-
onSelectionChange: handleSelectionStateChange,
|
|
461
|
-
handleColumnFilterStateChange,
|
|
462
|
-
onDataStateChange,
|
|
463
|
-
onFetchData: fetchData,
|
|
464
|
-
exportFilename,
|
|
465
|
-
onExportProgress,
|
|
466
|
-
onExportComplete,
|
|
467
|
-
onExportError,
|
|
468
|
-
onServerExport,
|
|
469
|
-
exportController,
|
|
470
|
-
setExportController,
|
|
471
|
-
isExporting,
|
|
472
|
-
onDataChange: setServerData,
|
|
473
|
-
dataMode,
|
|
474
|
-
}, internalApiRef);
|
|
475
|
-
(0, react_1.useImperativeHandle)(ref, () => internalApiRef.current, []);
|
|
476
1028
|
const RootSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'root', material_1.Box);
|
|
477
1029
|
const ToolbarSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'toolbar', toolbar_1.DataTableToolbar);
|
|
478
1030
|
const BulkActionsSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'bulkActionsToolbar', toolbar_1.BulkActionsToolbar);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Row, SortingState, ColumnResizeMode, ColumnPinningState, RowData } from '@tanstack/react-table';
|
|
1
|
+
import { Row, SortingState, ColumnResizeMode, ColumnPinningState, RowData, PaginationState } from '@tanstack/react-table';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import type { ColumnFilterState, TableFilters, TableState } from '../../types';
|
|
4
4
|
import { DataTableColumn } from '../../types';
|
|
@@ -91,7 +91,9 @@ export interface DataTableProps<T> {
|
|
|
91
91
|
emptyMessage?: string;
|
|
92
92
|
skeletonRows?: number;
|
|
93
93
|
onColumnFiltersChange?: (filterState: ColumnFilterState) => void;
|
|
94
|
-
|
|
94
|
+
onPaginationChange?: (pagination: PaginationState) => void;
|
|
95
|
+
onGlobalFilterChange?: (globalFilter: string) => void;
|
|
96
|
+
onColumnFilterChange?: (columnFilter: ColumnFilterState) => void;
|
|
95
97
|
selectionColumn?: {
|
|
96
98
|
width?: number;
|
|
97
99
|
pinLeft?: boolean;
|
|
@@ -31,7 +31,6 @@ function ColumnFilterControl() {
|
|
|
31
31
|
const addFilter = (0, react_1.useCallback)((columnId, operator) => {
|
|
32
32
|
var _a, _b;
|
|
33
33
|
let defaultOperator = operator || '';
|
|
34
|
-
console.log('addFilter', columnId, operator, filterableColumns);
|
|
35
34
|
if (columnId && !operator) {
|
|
36
35
|
const column = filterableColumns === null || filterableColumns === void 0 ? void 0 : filterableColumns.find(col => col.id === columnId);
|
|
37
36
|
const columnType = (0, column_helpers_1.getColumnType)(column);
|
|
@@ -115,13 +114,11 @@ function ColumnFilterControl() {
|
|
|
115
114
|
const hasPendingChanges = pendingFiltersCount > 0 || (filters.length === 0 && hasAppliedFilters);
|
|
116
115
|
(0, react_1.useEffect)(() => {
|
|
117
116
|
var _a;
|
|
118
|
-
console.log('useEffect', filters.length, filterableColumns, { activeFiltersCount });
|
|
119
117
|
if (filters.length === 0 && filterableColumns && (filterableColumns === null || filterableColumns === void 0 ? void 0 : filterableColumns.length) > 0 && activeFiltersCount === 0) {
|
|
120
118
|
const firstColumn = filterableColumns[0];
|
|
121
119
|
const columnType = (0, column_helpers_1.getColumnType)(firstColumn);
|
|
122
120
|
const operators = filters_1.FILTER_OPERATORS[columnType] || filters_1.FILTER_OPERATORS.text;
|
|
123
121
|
const defaultOperator = ((_a = operators[0]) === null || _a === void 0 ? void 0 : _a.value) || 'contains';
|
|
124
|
-
console.log('useEffect', firstColumn, columnType, operators, defaultOperator);
|
|
125
122
|
addFilter(firstColumn === null || firstColumn === void 0 ? void 0 : firstColumn.id, defaultOperator);
|
|
126
123
|
}
|
|
127
124
|
}, [filters.length, filterableColumns, addFilter, activeFiltersCount]);
|
|
@@ -22,5 +22,5 @@ function DataTableToolbar({ extraFilter = null, enableGlobalFilter = true, title
|
|
|
22
22
|
const ColumnVisibilityControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'columnVisibilityControl', column_visibility_control_1.ColumnVisibilityControl);
|
|
23
23
|
const ColumnResetControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'resetButton', column_reset_control_1.ColumnResetControl);
|
|
24
24
|
const TableExportControlSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'exportButton', table_export_control_1.TableExportControl);
|
|
25
|
-
return ((0, jsx_runtime_1.jsx)(ToolbarSlot, Object.assign({ table: table }, slotProps.toolbar, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { width: '100%' }, children: [(title || subtitle) ? ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mb: 2 }, children: [title ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", component: "div", children: title })) : null, subtitle ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: subtitle })) : null] })) : null, (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 2, justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 0.5, alignItems: "center", sx: { flex: 1 }, children: [
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(ToolbarSlot, Object.assign({ table: table }, slotProps.toolbar, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { width: '100%' }, children: [(title || subtitle) ? ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { mb: 2 }, children: [title ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", component: "div", children: title })) : null, subtitle ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", color: "text.secondary", children: subtitle })) : null] })) : null, (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 2, justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 0.5, alignItems: "center", sx: { flex: 1 }, children: [enableTableSizeControl ? (0, jsx_runtime_1.jsx)(TableSizeControlSlot, Object.assign({}, slotProps.tableSizeControl)) : null, enableColumnFilter ? (0, jsx_runtime_1.jsx)(ColumnCustomFilterControlSlot, Object.assign({}, slotProps.columnCustomFilterControl)) : null, enableColumnPinning ? (0, jsx_runtime_1.jsx)(ColumnPinningControlSlot, Object.assign({}, slotProps.columnPinningControl)) : null, enableColumnVisibility ? (0, jsx_runtime_1.jsx)(ColumnVisibilityControlSlot, Object.assign({}, slotProps.columnVisibilityControl)) : null, enableReset ? (0, jsx_runtime_1.jsx)(ColumnResetControlSlot, Object.assign({}, slotProps.resetButton)) : null, enableExport ? (0, jsx_runtime_1.jsx)(TableExportControlSlot, Object.assign({}, slotProps.exportButton)) : null, enableGlobalFilter ? (0, jsx_runtime_1.jsx)(TableSearchControlSlot, Object.assign({}, slotProps.searchInput)) : null] }), (0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", spacing: 1, alignItems: "center", children: extraFilter })] })] }) })));
|
|
26
26
|
}
|
|
@@ -23,7 +23,6 @@ function TableExportControl({ exportFilename: propsExportFilename, onServerExpor
|
|
|
23
23
|
const handleExport = (format) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
var _a, _b;
|
|
25
25
|
try {
|
|
26
|
-
console.log('handleExport', dataMode, onServerExport);
|
|
27
26
|
if (dataMode === 'server' && onServerExport) {
|
|
28
27
|
const currentState = table.getState();
|
|
29
28
|
const currentFilters = {
|
|
@@ -6,6 +6,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const material_1 = require("@mui/material");
|
|
8
8
|
const data_table_1 = require("../components/table/data-table");
|
|
9
|
+
const types_1 = require("../types");
|
|
9
10
|
const MOCK_EMPLOYEES = Array.from({ length: 1000 }, (_, index) => {
|
|
10
11
|
const departments = ['Engineering', 'Marketing', 'Sales', 'HR', 'Finance', 'Operations'];
|
|
11
12
|
const roles = ['Manager', 'Senior', 'Junior', 'Lead', 'Director', 'Specialist'];
|
|
@@ -35,7 +36,6 @@ function ServerSideFetchingExample() {
|
|
|
35
36
|
const handleFetchData = (0, react_1.useCallback)((filters) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
37
|
var _a, _b, _c;
|
|
37
38
|
console.log('🔄 Fetching data with filters:', filters);
|
|
38
|
-
console.log('🔄 Tab:', { tab }, 'Current tab:');
|
|
39
39
|
setLoading(true);
|
|
40
40
|
setError(null);
|
|
41
41
|
setLastFetchParams(filters);
|
|
@@ -99,11 +99,6 @@ function ServerSideFetchingExample() {
|
|
|
99
99
|
const end = start + pageSize;
|
|
100
100
|
pageData = filteredData.slice(start, end);
|
|
101
101
|
}
|
|
102
|
-
console.log('✅ Data fetched successfully:', {
|
|
103
|
-
total,
|
|
104
|
-
pageSize: pageData.length,
|
|
105
|
-
filters: filters.pagination
|
|
106
|
-
});
|
|
107
102
|
return {
|
|
108
103
|
data: pageData,
|
|
109
104
|
total: total,
|
|
@@ -117,7 +112,7 @@ function ServerSideFetchingExample() {
|
|
|
117
112
|
finally {
|
|
118
113
|
setLoading(false);
|
|
119
114
|
}
|
|
120
|
-
}), []);
|
|
115
|
+
}), [tab]);
|
|
121
116
|
const handleSelectionChange = (0, react_1.useCallback)((selection) => {
|
|
122
117
|
console.log('🔄 Selection changed:', selection);
|
|
123
118
|
setSelectionInfo(selection);
|
|
@@ -227,7 +222,7 @@ function ServerSideFetchingExample() {
|
|
|
227
222
|
var _a;
|
|
228
223
|
(_a = apiRef.current) === null || _a === void 0 ? void 0 : _a.data.refresh();
|
|
229
224
|
console.log('Refreshed data');
|
|
230
|
-
}, children: "Refresh Data" })] })] }) }), selectionInfo && ((0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Current Selection Info" }), (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: { p: 2, bgcolor: 'grey.50' }, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Selection Type:" }), " ", selectionInfo.type] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Selected IDs:" }), " [", selectionInfo.ids.join(', '), "]"] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Count:" }), " ", selectionInfo.ids.length] })] }) })] }) })), (0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Export & Column Configuration" }), (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "info", sx: { mb: 2 }, children: (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "hideInExport Demo:" }), " The Salary column has `hideInExport: true` so it will be excluded from CSV/Excel exports. Try exporting to see the difference!"] }) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Exportable columns:" }), " Name, Email, Department, Role, Status, Join Date"] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", color: "warning.main", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Hidden from export:" }), " Salary (contains sensitive data)"] })] })] }) }), lastFetchParams && ((0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Last Fetch Parameters" }), (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: { p: 2, bgcolor: 'grey.50' }, children: (0, jsx_runtime_1.jsx)("pre", { style: { fontSize: '12px', margin: 0, overflow: 'auto' }, children: JSON.stringify(lastFetchParams, null, 2) }) })] }) })), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: { mb: 3 } }), (0, jsx_runtime_1.jsx)(data_table_1.DataTable, { ref: apiRef, columns: columns, dataMode: "server", initialLoadData: true, onFetchData: handleFetchData, loading: loading, enableRowSelection: true, enableMultiRowSelection: true, selectMode: "page", onSelectionChange: handleSelectionChange, enableBulkActions: true, bulkActions: (selectionState) => ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Button, { variant: "contained", size: "small", color: "error", onClick: () => {
|
|
225
|
+
}, children: "Refresh Data" })] })] }) }), selectionInfo && ((0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Current Selection Info" }), (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: { p: 2, bgcolor: 'grey.50' }, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Selection Type:" }), " ", selectionInfo.type] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Selected IDs:" }), " [", selectionInfo.ids.join(', '), "]"] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Count:" }), " ", selectionInfo.ids.length] })] }) })] }) })), (0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Export & Column Configuration" }), (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "info", sx: { mb: 2 }, children: (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "hideInExport Demo:" }), " The Salary column has `hideInExport: true` so it will be excluded from CSV/Excel exports. Try exporting to see the difference!"] }) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Exportable columns:" }), " Name, Email, Department, Role, Status, Join Date"] }), (0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "body2", color: "warning.main", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Hidden from export:" }), " Salary (contains sensitive data)"] })] })] }) }), lastFetchParams && ((0, jsx_runtime_1.jsx)(material_1.Card, { sx: { mb: 3 }, children: (0, jsx_runtime_1.jsxs)(material_1.CardContent, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", gutterBottom: true, children: "Last Fetch Parameters" }), (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: { p: 2, bgcolor: 'grey.50' }, children: (0, jsx_runtime_1.jsx)("pre", { style: { fontSize: '12px', margin: 0, overflow: 'auto' }, children: JSON.stringify(lastFetchParams, null, 2) }) })] }) })), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: { mb: 3 } }), (0, jsx_runtime_1.jsx)(data_table_1.DataTable, { ref: apiRef, columns: columns, dataMode: "server", initialLoadData: true, onFetchData: handleFetchData, loading: loading, enableRowSelection: true, enableMultiRowSelection: true, selectMode: "page", onSelectionChange: handleSelectionChange, enableColumnPinning: true, enableColumnResizing: true, enableColumnDragging: true, enableBulkActions: true, bulkActions: (selectionState) => ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, children: [(0, jsx_runtime_1.jsxs)(material_1.Button, { variant: "contained", size: "small", color: "error", onClick: () => {
|
|
231
226
|
console.log('Bulk delete action triggered');
|
|
232
227
|
console.log('Selection state:', selectionState);
|
|
233
228
|
alert(`Would delete ${selectionState.ids.length} items`);
|
|
@@ -240,6 +235,10 @@ function ServerSideFetchingExample() {
|
|
|
240
235
|
pageIndex: 0,
|
|
241
236
|
pageSize: 10,
|
|
242
237
|
},
|
|
238
|
+
columnPinning: {
|
|
239
|
+
left: [types_1.DEFAULT_SELECTION_COLUMN_NAME],
|
|
240
|
+
right: [],
|
|
241
|
+
},
|
|
243
242
|
}, enableExport: true, exportFilename: "employees", onServerExport: handleServerExport, onExportProgress: (progress) => {
|
|
244
243
|
console.log('Export progress:', progress);
|
|
245
244
|
}, onExportComplete: (result) => {
|
|
@@ -36,7 +36,6 @@ exports.ColumnFilterFeature = {
|
|
|
36
36
|
table.addPendingColumnFilter = (columnId, operator, value) => {
|
|
37
37
|
if (!table.options.enableAdvanceColumnFilter)
|
|
38
38
|
return;
|
|
39
|
-
console.log('addPendingColumnFilter', columnId, operator, value);
|
|
40
39
|
table.setColumnFilterState((old) => {
|
|
41
40
|
const newFilter = {
|
|
42
41
|
id: `filter_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`,
|
|
@@ -6,6 +6,15 @@ const react_1 = require("react");
|
|
|
6
6
|
const export_utils_1 = require("../utils/export-utils");
|
|
7
7
|
function useDataTableApi(props, ref) {
|
|
8
8
|
const { table, idKey, enhancedColumns, enablePagination, enableColumnPinning, initialStateConfig, selectMode = 'page', onSelectionChange, handleColumnFilterStateChange, onDataStateChange, onFetchData, onDataChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, exportController, setExportController, isExporting, dataMode = 'client', } = props;
|
|
9
|
+
const getTableFilters = (0, react_1.useCallback)((withAllState = false) => {
|
|
10
|
+
const state = table.getState();
|
|
11
|
+
return Object.assign({ sorting: state.sorting, globalFilter: state.globalFilter, columnFilter: state.columnFilter, pagination: state.pagination }, (withAllState ? {
|
|
12
|
+
columnOrder: state.columnOrder,
|
|
13
|
+
columnPinning: state.columnPinning,
|
|
14
|
+
columnVisibility: state.columnVisibility,
|
|
15
|
+
columnSizing: state.columnSizing,
|
|
16
|
+
} : {}));
|
|
17
|
+
}, [table]);
|
|
9
18
|
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
10
19
|
table: {
|
|
11
20
|
getTable: () => table,
|
|
@@ -222,22 +231,21 @@ function useDataTableApi(props, ref) {
|
|
|
222
231
|
},
|
|
223
232
|
data: {
|
|
224
233
|
refresh: () => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
234
|
+
var _a, _b;
|
|
235
|
+
const filters = getTableFilters();
|
|
236
|
+
filters.pagination = {
|
|
237
|
+
pageIndex: 0,
|
|
238
|
+
pageSize: ((_a = filters.pagination) === null || _a === void 0 ? void 0 : _a.pageSize) || ((_b = initialStateConfig.pagination) === null || _b === void 0 ? void 0 : _b.pageSize) || 10,
|
|
239
|
+
};
|
|
240
|
+
const allState = getTableFilters(true);
|
|
241
|
+
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
|
|
242
|
+
onFetchData === null || onFetchData === void 0 ? void 0 : onFetchData(filters);
|
|
232
243
|
},
|
|
233
244
|
reload: () => {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (onFetchData) {
|
|
239
|
-
onFetchData({ pagination: { pageIndex: 0, pageSize: pagination.pageSize } });
|
|
240
|
-
}
|
|
245
|
+
const filters = getTableFilters();
|
|
246
|
+
const allState = getTableFilters(true);
|
|
247
|
+
onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
|
|
248
|
+
onFetchData === null || onFetchData === void 0 ? void 0 : onFetchData(filters);
|
|
241
249
|
},
|
|
242
250
|
getAllData: () => {
|
|
243
251
|
var _a;
|