@ackplus/react-tanstack-data-table 1.0.19-beta-0.13 → 1.0.19-beta-0.14

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ackplus/react-tanstack-data-table",
3
3
  "type": "commonjs",
4
- "version": "1.0.19-beta-0.13",
4
+ "version": "1.0.19-beta-0.14",
5
5
  "description": "A powerful React data table component built with MUI and TanStack Table",
6
6
  "keywords": [
7
7
  "react",
@@ -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
- flex: 1,
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%',
@@ -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'
@@ -181,7 +171,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
181
171
  }, 0);
182
172
  }
183
173
  }, [onColumnFiltersChange]);
184
- const notifyDataStateChange = (0, react_1.useCallback)((overrides = {}) => {
174
+ const tableStateChange = (0, react_1.useCallback)((overrides = {}) => {
185
175
  if (onDataStateChange) {
186
176
  const currentState = Object.assign({ globalFilter,
187
177
  columnFilter,
@@ -200,35 +190,34 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
200
190
  columnOrder,
201
191
  columnPinning,
202
192
  ]);
203
- const stateChangeRef = (0, react_1.useRef)(notifyDataStateChange);
204
- stateChangeRef.current = notifyDataStateChange;
205
193
  const handleSortingChange = (0, react_1.useCallback)((updaterOrValue) => {
206
194
  let newSorting = typeof updaterOrValue === 'function'
207
195
  ? updaterOrValue(sorting)
208
196
  : updaterOrValue;
209
- console.log('handleSortingChange', newSorting);
210
197
  newSorting = newSorting.filter((sort) => sort.id);
211
198
  setSorting(newSorting);
212
199
  if (onSortingChange) {
213
200
  onSortingChange(newSorting);
214
201
  }
215
202
  if (isServerMode || isServerSorting) {
216
- stateChangeRef.current({ sorting: newSorting });
217
- fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({
203
+ tableStateChange({ sorting: newSorting });
204
+ fetchData({
218
205
  sorting: newSorting,
219
206
  });
220
207
  }
221
208
  else if (onDataStateChange) {
222
209
  setTimeout(() => {
223
- stateChangeRef.current({ sorting: newSorting });
210
+ tableStateChange({ sorting: newSorting });
224
211
  }, 0);
225
212
  }
226
213
  }, [
227
214
  sorting,
228
215
  onSortingChange,
216
+ fetchData,
229
217
  isServerMode,
230
218
  isServerSorting,
231
219
  onDataStateChange,
220
+ tableStateChange,
232
221
  ]);
233
222
  const handleColumnOrderChange = (0, react_1.useCallback)((updatedColumnOrder) => {
234
223
  const newColumnOrder = typeof updatedColumnOrder === 'function'
@@ -253,16 +242,16 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
253
242
  const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
254
243
  if (isServerMode || isServerPagination) {
255
244
  setTimeout(() => {
256
- stateChangeRef.current({ pagination: newPagination });
257
- fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({ pagination: newPagination });
245
+ tableStateChange({ pagination: newPagination });
246
+ fetchData({ pagination: newPagination });
258
247
  }, 0);
259
248
  }
260
249
  else if (onDataStateChange) {
261
250
  setTimeout(() => {
262
- stateChangeRef.current({ pagination: newPagination });
251
+ tableStateChange({ pagination: newPagination });
263
252
  }, 0);
264
253
  }
265
- }, [pagination, isServerMode, isServerPagination, onDataStateChange]);
254
+ }, [pagination, isServerMode, isServerPagination, onDataStateChange, fetchData, tableStateChange]);
266
255
  const handleGlobalFilterChange = (0, react_1.useCallback)((updaterOrValue) => {
267
256
  const newFilter = typeof updaterOrValue === 'function'
268
257
  ? updaterOrValue(globalFilter)
@@ -270,16 +259,16 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
270
259
  setGlobalFilter(newFilter);
271
260
  if (isServerMode || isServerFiltering) {
272
261
  setTimeout(() => {
273
- stateChangeRef.current({ globalFilter: newFilter });
274
- fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({ globalFilter: newFilter });
262
+ tableStateChange({ globalFilter: newFilter });
263
+ fetchData({ globalFilter: newFilter });
275
264
  }, 0);
276
265
  }
277
266
  else if (onDataStateChange) {
278
267
  setTimeout(() => {
279
- stateChangeRef.current({ globalFilter: newFilter });
268
+ tableStateChange({ globalFilter: newFilter });
280
269
  }, 0);
281
270
  }
282
- }, [globalFilter, isServerMode, isServerFiltering, onDataStateChange]);
271
+ }, [globalFilter, isServerMode, isServerFiltering, onDataStateChange, fetchData, tableStateChange]);
283
272
  const onColumnFilterChangeHandler = (0, react_1.useCallback)((updater) => {
284
273
  const currentState = columnFilter;
285
274
  const newState = typeof updater === 'function'
@@ -301,51 +290,15 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
301
290
  pendingFilters: appliedState.pendingFilters,
302
291
  pendingLogic: appliedState.pendingLogic,
303
292
  };
304
- stateChangeRef.current({
293
+ tableStateChange({
305
294
  columnFilter: serverFilterState,
306
295
  });
307
- fetchDataRef === null || fetchDataRef === void 0 ? void 0 : fetchDataRef.current({
296
+ fetchData({
308
297
  columnFilter: serverFilterState,
309
298
  });
310
299
  }
311
- }, [isServerFiltering]);
312
- const table = (0, react_table_1.useReactTable)({
313
- _features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature],
314
- data: tableData,
315
- columns: enhancedColumns,
316
- initialState: Object.assign({}, initialStateConfig),
317
- state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ sorting }, (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnFilter ? { columnFilter } : {})), (enableRowSelection ? { selectionState } : {})),
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
- });
300
+ }, [isServerFiltering, fetchData, tableStateChange]);
301
+ 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
302
  const rows = ((_a = table.getRowModel()) === null || _a === void 0 ? void 0 : _a.rows) || [];
350
303
  const rowVirtualizer = (0, react_virtual_1.useVirtualizer)({
351
304
  count: rows.length,
@@ -375,9 +328,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
375
328
  }, [columnOrder, enhancedColumns, handleColumnOrderChange]);
376
329
  (0, react_1.useEffect)(() => {
377
330
  if (initialLoadData && onFetchData) {
378
- fetchDataRef.current();
331
+ fetchData();
379
332
  }
380
- }, [initialLoadData, onFetchData]);
333
+ }, [initialLoadData]);
381
334
  (0, react_1.useEffect)(() => {
382
335
  if (enableColumnDragging && columnOrder.length === 0) {
383
336
  const initialOrder = enhancedColumns.map((col, index) => {
@@ -392,6 +345,614 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
392
345
  setColumnOrder(initialOrder);
393
346
  }
394
347
  }, [enableColumnDragging, enhancedColumns, columnOrder.length]);
348
+ (0, use_data_table_api_1.useDataTableApi)({
349
+ table,
350
+ idKey,
351
+ enhancedColumns,
352
+ enablePagination,
353
+ enableColumnPinning,
354
+ initialStateConfig,
355
+ selectMode,
356
+ onSelectionChange: handleSelectionStateChange,
357
+ handleColumnFilterStateChange,
358
+ onDataStateChange,
359
+ onFetchData: fetchData,
360
+ exportFilename,
361
+ onExportProgress,
362
+ onExportComplete,
363
+ onExportError,
364
+ onServerExport,
365
+ exportController,
366
+ setExportController,
367
+ isExporting,
368
+ onDataChange: setServerData,
369
+ dataMode,
370
+ }, internalApiRef);
371
+ (0, react_1.useImperativeHandle)(ref, () => internalApiRef.current, []);
372
+ (0, react_1.useImperativeHandle)(ref, () => ({
373
+ table: {
374
+ getTable: () => table,
375
+ },
376
+ columnVisibility: {
377
+ showColumn: (columnId) => {
378
+ var _a;
379
+ (_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility(true);
380
+ },
381
+ hideColumn: (columnId) => {
382
+ var _a;
383
+ (_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility(false);
384
+ },
385
+ toggleColumn: (columnId) => {
386
+ var _a;
387
+ (_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility();
388
+ },
389
+ showAllColumns: () => {
390
+ table.toggleAllColumnsVisible(true);
391
+ },
392
+ hideAllColumns: () => {
393
+ table.toggleAllColumnsVisible(false);
394
+ },
395
+ resetColumnVisibility: () => {
396
+ table.resetColumnVisibility();
397
+ },
398
+ },
399
+ columnOrdering: {
400
+ setColumnOrder: (columnOrder) => {
401
+ table.setColumnOrder(columnOrder);
402
+ },
403
+ moveColumn: (columnId, toIndex) => {
404
+ const currentOrder = table.getState().columnOrder || [];
405
+ const currentIndex = currentOrder.indexOf(columnId);
406
+ if (currentIndex === -1)
407
+ return;
408
+ const newOrder = [...currentOrder];
409
+ newOrder.splice(currentIndex, 1);
410
+ newOrder.splice(toIndex, 0, columnId);
411
+ table.setColumnOrder(newOrder);
412
+ },
413
+ resetColumnOrder: () => {
414
+ const initialOrder = enhancedColumns.map((col, index) => {
415
+ if (col.id)
416
+ return col.id;
417
+ const anyCol = col;
418
+ if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
419
+ return anyCol.accessorKey;
420
+ }
421
+ return `column_${index}`;
422
+ });
423
+ table.setColumnOrder(initialOrder);
424
+ },
425
+ },
426
+ columnPinning: {
427
+ pinColumnLeft: (columnId) => {
428
+ const currentPinning = table.getState().columnPinning;
429
+ const newPinning = Object.assign({}, currentPinning);
430
+ newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
431
+ newPinning.left = [...(newPinning.left || []).filter(id => id !== columnId), columnId];
432
+ table.setColumnPinning(newPinning);
433
+ },
434
+ pinColumnRight: (columnId) => {
435
+ const currentPinning = table.getState().columnPinning;
436
+ const newPinning = Object.assign({}, currentPinning);
437
+ newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
438
+ newPinning.right = [...(newPinning.right || []).filter(id => id !== columnId), columnId];
439
+ table.setColumnPinning(newPinning);
440
+ },
441
+ unpinColumn: (columnId) => {
442
+ const currentPinning = table.getState().columnPinning;
443
+ const newPinning = {
444
+ left: (currentPinning.left || []).filter(id => id !== columnId),
445
+ right: (currentPinning.right || []).filter(id => id !== columnId),
446
+ };
447
+ table.setColumnPinning(newPinning);
448
+ },
449
+ setPinning: (pinning) => {
450
+ table.setColumnPinning(pinning);
451
+ },
452
+ resetColumnPinning: () => {
453
+ table.setColumnPinning(table.initialState.columnPinning);
454
+ },
455
+ },
456
+ columnResizing: {
457
+ resizeColumn: (columnId, width) => {
458
+ const currentSizing = table.getState().columnSizing;
459
+ table.setColumnSizing(Object.assign(Object.assign({}, currentSizing), { [columnId]: width }));
460
+ },
461
+ autoSizeColumn: (columnId) => {
462
+ var _a;
463
+ (_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.resetSize();
464
+ },
465
+ autoSizeAllColumns: () => {
466
+ table.resetColumnSizing();
467
+ },
468
+ resetColumnSizing: () => {
469
+ table.resetColumnSizing();
470
+ },
471
+ },
472
+ filtering: {
473
+ setGlobalFilter: (filter) => {
474
+ table.setGlobalFilter(filter);
475
+ },
476
+ clearGlobalFilter: () => {
477
+ table.setGlobalFilter('');
478
+ },
479
+ setColumnFilters: (filters) => {
480
+ handleColumnFilterStateChange(filters);
481
+ },
482
+ addColumnFilter: (columnId, operator, value) => {
483
+ const newFilter = {
484
+ id: `filter_${Date.now()}`,
485
+ columnId,
486
+ operator,
487
+ value,
488
+ };
489
+ const columnFilter = table.getState().columnFilter;
490
+ const currentFilters = columnFilter.filters || [];
491
+ const newFilters = [...currentFilters, newFilter];
492
+ handleColumnFilterStateChange({
493
+ filters: newFilters,
494
+ logic: columnFilter.logic,
495
+ pendingFilters: columnFilter.pendingFilters || [],
496
+ pendingLogic: columnFilter.pendingLogic || 'AND',
497
+ });
498
+ },
499
+ removeColumnFilter: (filterId) => {
500
+ const columnFilter = table.getState().columnFilter;
501
+ const currentFilters = columnFilter.filters || [];
502
+ const newFilters = currentFilters.filter((f) => f.id !== filterId);
503
+ handleColumnFilterStateChange({
504
+ filters: newFilters,
505
+ logic: columnFilter.logic,
506
+ pendingFilters: columnFilter.pendingFilters || [],
507
+ pendingLogic: columnFilter.pendingLogic || 'AND',
508
+ });
509
+ },
510
+ clearAllFilters: () => {
511
+ table.setGlobalFilter('');
512
+ handleColumnFilterStateChange({
513
+ filters: [],
514
+ logic: 'AND',
515
+ pendingFilters: [],
516
+ pendingLogic: 'AND',
517
+ });
518
+ },
519
+ resetFilters: () => {
520
+ table.resetGlobalFilter();
521
+ handleColumnFilterStateChange({
522
+ filters: [],
523
+ logic: 'AND',
524
+ pendingFilters: [],
525
+ pendingLogic: 'AND',
526
+ });
527
+ },
528
+ },
529
+ sorting: {
530
+ setSorting: (sortingState) => {
531
+ table.setSorting(sortingState);
532
+ },
533
+ sortColumn: (columnId, direction) => {
534
+ const column = table.getColumn(columnId);
535
+ if (!column)
536
+ return;
537
+ if (direction === false) {
538
+ column.clearSorting();
539
+ }
540
+ else {
541
+ column.toggleSorting(direction === 'desc');
542
+ }
543
+ },
544
+ clearSorting: () => {
545
+ table.resetSorting();
546
+ },
547
+ resetSorting: () => {
548
+ table.resetSorting();
549
+ },
550
+ },
551
+ pagination: {
552
+ goToPage: (pageIndex) => {
553
+ table.setPageIndex(pageIndex);
554
+ },
555
+ nextPage: () => {
556
+ table.nextPage();
557
+ },
558
+ previousPage: () => {
559
+ table.previousPage();
560
+ },
561
+ setPageSize: (pageSize) => {
562
+ table.setPageSize(pageSize);
563
+ },
564
+ goToFirstPage: () => {
565
+ table.setPageIndex(0);
566
+ },
567
+ goToLastPage: () => {
568
+ const pageCount = table.getPageCount();
569
+ if (pageCount > 0) {
570
+ table.setPageIndex(pageCount - 1);
571
+ }
572
+ },
573
+ },
574
+ selection: {
575
+ selectRow: (rowId) => { var _a; return (_a = table.selectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
576
+ deselectRow: (rowId) => { var _a; return (_a = table.deselectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
577
+ toggleRowSelection: (rowId) => { var _a; return (_a = table.toggleRowSelected) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
578
+ selectAll: () => { var _a; return (_a = table.selectAll) === null || _a === void 0 ? void 0 : _a.call(table); },
579
+ deselectAll: () => { var _a; return (_a = table.deselectAll) === null || _a === void 0 ? void 0 : _a.call(table); },
580
+ toggleSelectAll: () => { var _a; return (_a = table.toggleAllRowsSelected) === null || _a === void 0 ? void 0 : _a.call(table); },
581
+ getSelectionState: () => { var _a; return ((_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table)) || { ids: [], type: 'include' }; },
582
+ getSelectedRows: () => table.getSelectedRows(),
583
+ getSelectedCount: () => table.getSelectedCount(),
584
+ isRowSelected: (rowId) => table.getIsRowSelected(rowId) || false,
585
+ },
586
+ data: {
587
+ refresh: () => {
588
+ var _a, _b;
589
+ const filters = table.getState();
590
+ const pagination = {
591
+ pageIndex: 0,
592
+ pageSize: ((_a = filters.pagination) === null || _a === void 0 ? void 0 : _a.pageSize) || ((_b = initialStateConfig.pagination) === null || _b === void 0 ? void 0 : _b.pageSize) || 10,
593
+ };
594
+ const allState = table.getState();
595
+ onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
596
+ fetchData === null || fetchData === void 0 ? void 0 : fetchData({ pagination });
597
+ },
598
+ reload: () => {
599
+ const allState = table.getState();
600
+ onDataStateChange === null || onDataStateChange === void 0 ? void 0 : onDataStateChange(allState);
601
+ onFetchData === null || onFetchData === void 0 ? void 0 : onFetchData({});
602
+ },
603
+ getAllData: () => {
604
+ var _a;
605
+ return ((_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original)) || [];
606
+ },
607
+ getRowData: (rowId) => {
608
+ var _a, _b;
609
+ 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;
610
+ },
611
+ getRowByIndex: (index) => {
612
+ var _a, _b;
613
+ return (_b = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.original;
614
+ },
615
+ updateRow: (rowId, updates) => {
616
+ var _a;
617
+ const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
618
+ ? Object.assign(Object.assign({}, row.original), updates) : row.original);
619
+ setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData || []);
620
+ },
621
+ updateRowByIndex: (index, updates) => {
622
+ var _a;
623
+ const newData = (_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
624
+ if (newData === null || newData === void 0 ? void 0 : newData[index]) {
625
+ newData[index] = Object.assign(Object.assign({}, newData[index]), updates);
626
+ setServerData(newData);
627
+ }
628
+ },
629
+ insertRow: (newRow, index) => {
630
+ var _a;
631
+ const newData = ((_a = table.getRowModel().rows) === null || _a === void 0 ? void 0 : _a.map(row => row.original)) || [];
632
+ if (index !== undefined) {
633
+ newData.splice(index, 0, newRow);
634
+ }
635
+ else {
636
+ newData.push(newRow);
637
+ }
638
+ setServerData(newData || []);
639
+ },
640
+ deleteRow: (rowId) => {
641
+ var _a;
642
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => String(row.original[idKey]) !== rowId);
643
+ setServerData === null || setServerData === void 0 ? void 0 : setServerData((newData === null || newData === void 0 ? void 0 : newData.map(row => row.original)) || []);
644
+ },
645
+ deleteRowByIndex: (index) => {
646
+ var _a;
647
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
648
+ newData.splice(index, 1);
649
+ setServerData(newData);
650
+ },
651
+ deleteSelectedRows: () => {
652
+ var _a;
653
+ const selectedRowIds = Object.keys(table.getState().rowSelection)
654
+ .filter(key => table.getState().rowSelection[key]);
655
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.filter(row => !selectedRowIds.includes(String(row.original[idKey])));
656
+ setServerData((newData === null || newData === void 0 ? void 0 : newData.map(row => row.original)) || []);
657
+ table.resetRowSelection();
658
+ },
659
+ replaceAllData: (newData) => {
660
+ setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
661
+ },
662
+ updateMultipleRows: (updates) => {
663
+ var _a;
664
+ const updateMap = new Map(updates.map(u => [u.rowId, u.data]));
665
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => {
666
+ const rowId = String(row.original[idKey]);
667
+ const updateData = updateMap.get(rowId);
668
+ return updateData ? Object.assign(Object.assign({}, row.original), updateData) : row.original;
669
+ });
670
+ setServerData(newData || []);
671
+ },
672
+ insertMultipleRows: (newRows, startIndex) => {
673
+ var _a;
674
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
675
+ if (startIndex !== undefined) {
676
+ newData.splice(startIndex, 0, ...newRows);
677
+ }
678
+ else {
679
+ newData.push(...newRows);
680
+ }
681
+ setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
682
+ },
683
+ deleteMultipleRows: (rowIds) => {
684
+ var _a, _b;
685
+ const idsToDelete = new Set(rowIds);
686
+ 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);
687
+ setServerData(newData);
688
+ },
689
+ updateField: (rowId, fieldName, value) => {
690
+ var _a;
691
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => String(row.original[idKey]) === rowId
692
+ ? Object.assign(Object.assign({}, row.original), { [fieldName]: value }) : row.original);
693
+ setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
694
+ },
695
+ updateFieldByIndex: (index, fieldName, value) => {
696
+ var _a;
697
+ const newData = (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.map(row => row.original);
698
+ if (newData[index]) {
699
+ newData[index] = Object.assign(Object.assign({}, newData[index]), { [fieldName]: value });
700
+ setServerData === null || setServerData === void 0 ? void 0 : setServerData(newData);
701
+ }
702
+ },
703
+ findRows: (predicate) => {
704
+ var _a, _b;
705
+ 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);
706
+ },
707
+ findRowIndex: (predicate) => {
708
+ var _a;
709
+ return (_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.findIndex(row => predicate(row.original));
710
+ },
711
+ getDataCount: () => {
712
+ var _a;
713
+ return ((_a = (table.getRowModel().rows || [])) === null || _a === void 0 ? void 0 : _a.length) || 0;
714
+ },
715
+ getFilteredDataCount: () => {
716
+ return table.getFilteredRowModel().rows.length;
717
+ },
718
+ },
719
+ layout: {
720
+ resetLayout: () => {
721
+ table.resetColumnSizing();
722
+ table.resetColumnVisibility();
723
+ table.resetSorting();
724
+ table.resetGlobalFilter();
725
+ },
726
+ resetAll: () => {
727
+ table.resetColumnSizing();
728
+ table.resetColumnVisibility();
729
+ table.resetSorting();
730
+ table.resetGlobalFilter();
731
+ table.resetColumnOrder();
732
+ table.resetExpanded();
733
+ table.resetRowSelection();
734
+ table.resetColumnPinning();
735
+ handleColumnFilterStateChange(initialStateConfig.columnFilter || { filters: [], logic: 'AND', pendingFilters: [], pendingLogic: 'AND' });
736
+ if (enablePagination) {
737
+ table.setPagination(initialStateConfig.pagination || { pageIndex: 0, pageSize: 10 });
738
+ }
739
+ if (enableColumnPinning) {
740
+ table.setColumnPinning(initialStateConfig.columnPinning || { left: [], right: [] });
741
+ }
742
+ },
743
+ saveLayout: () => {
744
+ return {
745
+ columnVisibility: table.getState().columnVisibility,
746
+ columnSizing: table.getState().columnSizing,
747
+ columnOrder: table.getState().columnOrder,
748
+ columnPinning: table.getState().columnPinning,
749
+ sorting: table.getState().sorting,
750
+ pagination: table.getState().pagination,
751
+ globalFilter: table.getState().globalFilter,
752
+ columnFilter: table.getState().columnFilter,
753
+ };
754
+ },
755
+ restoreLayout: (layout) => {
756
+ if (layout.columnVisibility) {
757
+ table.setColumnVisibility(layout.columnVisibility);
758
+ }
759
+ if (layout.columnSizing) {
760
+ table.setColumnSizing(layout.columnSizing);
761
+ }
762
+ if (layout.columnOrder) {
763
+ table.setColumnOrder(layout.columnOrder);
764
+ }
765
+ if (layout.columnPinning) {
766
+ table.setColumnPinning(layout.columnPinning);
767
+ }
768
+ if (layout.sorting) {
769
+ table.setSorting(layout.sorting);
770
+ }
771
+ if (layout.pagination && enablePagination) {
772
+ table.setPagination(layout.pagination);
773
+ }
774
+ if (layout.globalFilter !== undefined) {
775
+ table.setGlobalFilter(layout.globalFilter);
776
+ }
777
+ if (layout.columnFilter) {
778
+ handleColumnFilterStateChange(layout.columnFilter);
779
+ }
780
+ },
781
+ },
782
+ state: {
783
+ getTableState: () => {
784
+ return table.getState();
785
+ },
786
+ getCurrentFilters: () => {
787
+ return table.getState().columnFilter;
788
+ },
789
+ getCurrentSorting: () => {
790
+ return table.getState().sorting;
791
+ },
792
+ getCurrentPagination: () => {
793
+ return table.getState().pagination;
794
+ },
795
+ getCurrentSelection: () => {
796
+ return Object.keys(table.getState().rowSelection)
797
+ .filter(key => table.getState().rowSelection[key]);
798
+ },
799
+ },
800
+ export: {
801
+ exportCSV: (...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (options = {}) {
802
+ var _a;
803
+ const { filename = exportFilename, } = options;
804
+ try {
805
+ const controller = new AbortController();
806
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
807
+ if (dataMode === 'server' && onServerExport) {
808
+ const currentFilters = {
809
+ globalFilter: table.getState().globalFilter,
810
+ columnFilter: table.getState().columnFilter,
811
+ sorting: table.getState().sorting,
812
+ pagination: table.getState().pagination,
813
+ };
814
+ yield (0, utils_1.exportServerData)(table, {
815
+ format: 'csv',
816
+ filename,
817
+ fetchData: (filters, selection) => onServerExport(filters, selection),
818
+ currentFilters,
819
+ selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
820
+ onProgress: onExportProgress,
821
+ onComplete: onExportComplete,
822
+ onError: onExportError,
823
+ });
824
+ }
825
+ else {
826
+ yield (0, utils_1.exportClientData)(table, {
827
+ format: 'csv',
828
+ filename,
829
+ onProgress: onExportProgress,
830
+ onComplete: onExportComplete,
831
+ onError: onExportError,
832
+ });
833
+ }
834
+ }
835
+ catch (error) {
836
+ onExportError === null || onExportError === void 0 ? void 0 : onExportError({
837
+ message: error.message || 'Export failed',
838
+ code: 'EXPORT_ERROR',
839
+ });
840
+ }
841
+ finally {
842
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
843
+ }
844
+ }),
845
+ exportExcel: (...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (options = {}) {
846
+ var _a;
847
+ const { filename = exportFilename } = options;
848
+ try {
849
+ const controller = new AbortController();
850
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
851
+ if (dataMode === 'server' && onServerExport) {
852
+ const currentFilters = {
853
+ globalFilter: table.getState().globalFilter,
854
+ columnFilter: table.getState().columnFilter,
855
+ sorting: table.getState().sorting,
856
+ pagination: table.getState().pagination,
857
+ };
858
+ yield (0, utils_1.exportServerData)(table, {
859
+ format: 'excel',
860
+ filename,
861
+ fetchData: (filters, selection) => onServerExport(filters, selection),
862
+ currentFilters,
863
+ selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
864
+ onProgress: onExportProgress,
865
+ onComplete: onExportComplete,
866
+ onError: onExportError,
867
+ });
868
+ }
869
+ else {
870
+ yield (0, utils_1.exportClientData)(table, {
871
+ format: 'excel',
872
+ filename,
873
+ onProgress: onExportProgress,
874
+ onComplete: onExportComplete,
875
+ onError: onExportError,
876
+ });
877
+ }
878
+ }
879
+ catch (error) {
880
+ onExportError === null || onExportError === void 0 ? void 0 : onExportError({
881
+ message: error.message || 'Export failed',
882
+ code: 'EXPORT_ERROR',
883
+ });
884
+ }
885
+ finally {
886
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
887
+ }
888
+ }),
889
+ exportServerData: (options) => tslib_1.__awaiter(this, void 0, void 0, function* () {
890
+ var _a;
891
+ const { format, filename = exportFilename, fetchData = onServerExport, } = options;
892
+ if (!fetchData) {
893
+ onExportError === null || onExportError === void 0 ? void 0 : onExportError({
894
+ message: 'No server export function provided',
895
+ code: 'NO_SERVER_EXPORT',
896
+ });
897
+ return;
898
+ }
899
+ try {
900
+ const controller = new AbortController();
901
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
902
+ const currentFilters = {
903
+ globalFilter: table.getState().globalFilter,
904
+ columnFilter: table.getState().columnFilter,
905
+ sorting: table.getState().sorting,
906
+ pagination: table.getState().pagination,
907
+ };
908
+ yield (0, utils_1.exportServerData)(table, {
909
+ format,
910
+ filename,
911
+ fetchData: (filters, selection) => fetchData(filters, selection),
912
+ currentFilters,
913
+ selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
914
+ onProgress: onExportProgress,
915
+ onComplete: onExportComplete,
916
+ onError: onExportError,
917
+ });
918
+ }
919
+ catch (error) {
920
+ onExportError === null || onExportError === void 0 ? void 0 : onExportError({
921
+ message: error.message || 'Export failed',
922
+ code: 'EXPORT_ERROR',
923
+ });
924
+ }
925
+ finally {
926
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
927
+ }
928
+ }),
929
+ isExporting: () => isExporting || false,
930
+ cancelExport: () => {
931
+ exportController === null || exportController === void 0 ? void 0 : exportController.abort();
932
+ setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
933
+ },
934
+ },
935
+ }), [
936
+ table,
937
+ enhancedColumns,
938
+ handleColumnFilterStateChange,
939
+ idKey,
940
+ onDataStateChange,
941
+ onFetchData,
942
+ enableColumnPinning,
943
+ enablePagination,
944
+ exportFilename,
945
+ onExportProgress,
946
+ onExportComplete,
947
+ onExportError,
948
+ onServerExport,
949
+ exportController,
950
+ setExportController,
951
+ isExporting,
952
+ dataMode,
953
+ selectMode,
954
+ onSelectionChange,
955
+ ]);
395
956
  const LoadingRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'loadingRow', rows_1.LoadingRows);
396
957
  const EmptyRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'emptyRow', rows_1.EmptyDataRow);
397
958
  const renderTableRows = (0, react_1.useCallback)(() => {
@@ -449,30 +1010,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
449
1010
  }
450
1011
  }
451
1012
  }, [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
1013
  const RootSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'root', material_1.Box);
477
1014
  const ToolbarSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'toolbar', toolbar_1.DataTableToolbar);
478
1015
  const BulkActionsSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'bulkActionsToolbar', toolbar_1.BulkActionsToolbar);
@@ -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: [enableGlobalFilter ? (0, jsx_runtime_1.jsx)(TableSearchControlSlot, Object.assign({}, slotProps.searchInput)) : null, 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] }), (0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", spacing: 1, alignItems: "center", children: extraFilter })] })] }) })));
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
- const pagination = table.getState().pagination;
226
- if (onDataStateChange) {
227
- onDataStateChange({ pagination: { pageIndex: 0, pageSize: pagination.pageSize } });
228
- }
229
- if (onFetchData) {
230
- onFetchData({ pagination: { pageIndex: 0, pageSize: pagination.pageSize } });
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 pagination = table.getState().pagination;
235
- if (onDataStateChange) {
236
- onDataStateChange({ pagination: { pageIndex: 0, pageSize: pagination.pageSize } });
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;