@ackplus/react-tanstack-data-table 1.0.19-beta-0.6 → 1.0.19-beta-0.7
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 +3 -11
- package/LICENSE +0 -21
- package/README.md +0 -599
- package/index.d.ts.map +0 -1
- package/index.js +0 -42
- package/lib/components/droupdown/menu-dropdown.d.ts.map +0 -1
- package/lib/components/droupdown/menu-dropdown.js +0 -47
- package/lib/components/export-progress-dialog.d.ts.map +0 -1
- package/lib/components/export-progress-dialog.js +0 -30
- package/lib/components/filters/filter-value-input.d.ts.map +0 -1
- package/lib/components/filters/filter-value-input.js +0 -64
- package/lib/components/filters/index.d.ts.map +0 -1
- package/lib/components/filters/index.js +0 -125
- package/lib/components/headers/draggable-header.d.ts.map +0 -1
- package/lib/components/headers/draggable-header.js +0 -226
- package/lib/components/headers/index.d.ts.map +0 -1
- package/lib/components/headers/index.js +0 -5
- package/lib/components/headers/table-header.d.ts.map +0 -1
- package/lib/components/headers/table-header.js +0 -59
- package/lib/components/index.d.ts.map +0 -1
- package/lib/components/index.js +0 -18
- package/lib/components/pagination/data-table-pagination.d.ts.map +0 -1
- package/lib/components/pagination/data-table-pagination.js +0 -24
- package/lib/components/pagination/index.d.ts.map +0 -1
- package/lib/components/pagination/index.js +0 -4
- package/lib/components/rows/data-table-row.d.ts.map +0 -1
- package/lib/components/rows/data-table-row.js +0 -42
- package/lib/components/rows/empty-data-row.d.ts.map +0 -1
- package/lib/components/rows/empty-data-row.js +0 -8
- package/lib/components/rows/index.d.ts.map +0 -1
- package/lib/components/rows/index.js +0 -6
- package/lib/components/rows/loading-rows.d.ts.map +0 -1
- package/lib/components/rows/loading-rows.js +0 -46
- package/lib/components/table/data-table.d.ts.map +0 -1
- package/lib/components/table/data-table.js +0 -663
- package/lib/components/table/data-table.types.d.ts.map +0 -1
- package/lib/components/table/data-table.types.js +0 -6
- package/lib/components/table/index.d.ts.map +0 -1
- package/lib/components/table/index.js +0 -5
- package/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +0 -1
- package/lib/components/toolbar/bulk-actions-toolbar.js +0 -31
- package/lib/components/toolbar/column-custom-filter-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-custom-filter-control.js +0 -149
- package/lib/components/toolbar/column-custum-filter-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-custum-filter-control.js +0 -150
- package/lib/components/toolbar/column-pinning-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-pinning-control.js +0 -103
- package/lib/components/toolbar/column-reset-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-reset-control.js +0 -13
- package/lib/components/toolbar/column-visibility-control.d.ts.map +0 -1
- package/lib/components/toolbar/column-visibility-control.js +0 -27
- package/lib/components/toolbar/data-table-toolbar.d.ts.map +0 -1
- package/lib/components/toolbar/data-table-toolbar.js +0 -23
- package/lib/components/toolbar/index.d.ts.map +0 -1
- package/lib/components/toolbar/index.js +0 -13
- package/lib/components/toolbar/table-export-control.d.ts.map +0 -1
- package/lib/components/toolbar/table-export-control.js +0 -94
- package/lib/components/toolbar/table-search-control.d.ts.map +0 -1
- package/lib/components/toolbar/table-search-control.js +0 -61
- package/lib/components/toolbar/table-size-control.d.ts.map +0 -1
- package/lib/components/toolbar/table-size-control.js +0 -33
- package/lib/contexts/data-table-context.d.ts.map +0 -1
- package/lib/contexts/data-table-context.js +0 -50
- package/lib/examples/advanced-features-example.d.ts.map +0 -1
- package/lib/examples/advanced-features-example.js +0 -282
- package/lib/examples/basic-example.d.ts.map +0 -1
- package/lib/examples/basic-example.js +0 -323
- package/lib/examples/bulk-actions-test.d.ts.map +0 -1
- package/lib/examples/bulk-actions-test.js +0 -47
- package/lib/examples/crud-api-example.d.ts.map +0 -1
- package/lib/examples/crud-api-example.js +0 -321
- package/lib/examples/custom-column-filter-example.d.ts.map +0 -1
- package/lib/examples/custom-column-filter-example.js +0 -60
- package/lib/examples/custom-selection-example.d.ts.map +0 -1
- package/lib/examples/custom-selection-example.js +0 -184
- package/lib/examples/export-callbacks-example.d.ts.map +0 -1
- package/lib/examples/export-callbacks-example.js +0 -155
- package/lib/examples/improved-export-example.d.ts.map +0 -1
- package/lib/examples/improved-export-example.js +0 -153
- package/lib/examples/improved-server-selection-example.d.ts.map +0 -1
- package/lib/examples/improved-server-selection-example.js +0 -118
- package/lib/examples/index.d.ts.map +0 -1
- package/lib/examples/index.js +0 -5
- package/lib/examples/selection-test-example.d.ts.map +0 -1
- package/lib/examples/selection-test-example.js +0 -111
- package/lib/examples/simple-local-example.d.ts.map +0 -1
- package/lib/examples/simple-local-example.js +0 -101
- package/lib/examples/simple-server-selection-example.d.ts.map +0 -1
- package/lib/examples/simple-server-selection-example.js +0 -178
- package/lib/examples/virtualized-example.d.ts.map +0 -1
- package/lib/examples/virtualized-example.js +0 -119
- package/lib/features/custom-column-filter.feature.d.ts.map +0 -1
- package/lib/features/custom-column-filter.feature.js +0 -306
- package/lib/features/custom-selection.feature.d.ts.map +0 -1
- package/lib/features/custom-selection.feature.js +0 -224
- package/lib/features/index.d.ts.map +0 -1
- package/lib/features/index.js +0 -9
- package/lib/hooks/index.d.ts.map +0 -1
- package/lib/hooks/index.js +0 -6
- package/lib/hooks/use-data-table-api.d.ts.map +0 -1
- package/lib/hooks/use-data-table-api.js +0 -673
- package/lib/hooks/use-table-state.d.ts.map +0 -1
- package/lib/hooks/use-table-state.js +0 -74
- package/lib/icons/add-icon.d.ts.map +0 -1
- package/lib/icons/add-icon.js +0 -5
- package/lib/icons/csv-icon.d.ts.map +0 -1
- package/lib/icons/csv-icon.js +0 -5
- package/lib/icons/delete-icon.d.ts.map +0 -1
- package/lib/icons/delete-icon.js +0 -5
- package/lib/icons/excel-icon.d.ts.map +0 -1
- package/lib/icons/excel-icon.js +0 -5
- package/lib/icons/index.d.ts.map +0 -1
- package/lib/icons/index.js +0 -7
- package/lib/icons/unpin-icon.d.ts.map +0 -1
- package/lib/icons/unpin-icon.js +0 -5
- package/lib/icons/view-comfortable-icon.d.ts.map +0 -1
- package/lib/icons/view-comfortable-icon.js +0 -5
- package/lib/icons/view-compact-icon.d.ts.map +0 -1
- package/lib/icons/view-compact-icon.js +0 -5
- package/lib/types/column.types.d.ts.map +0 -1
- package/lib/types/column.types.js +0 -2
- package/lib/types/data-table-api.d.ts.map +0 -1
- package/lib/types/data-table-api.js +0 -1
- package/lib/types/export.types.d.ts.map +0 -1
- package/lib/types/export.types.js +0 -5
- package/lib/types/hooks.types.d.ts.map +0 -1
- package/lib/types/hooks.types.js +0 -1
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/index.js +0 -14
- package/lib/types/slots.types.d.ts.map +0 -1
- package/lib/types/slots.types.js +0 -1
- package/lib/types/table.types.d.ts.map +0 -1
- package/lib/types/table.types.js +0 -1
- package/lib/utils/column-helpers.d.ts.map +0 -1
- package/lib/utils/column-helpers.js +0 -46
- package/lib/utils/debounced-fetch.utils.d.ts.map +0 -1
- package/lib/utils/debounced-fetch.utils.js +0 -51
- package/lib/utils/export-utils.d.ts.map +0 -1
- package/lib/utils/export-utils.js +0 -181
- package/lib/utils/index.d.ts.map +0 -1
- package/lib/utils/index.js +0 -17
- package/lib/utils/selection-helpers.d.ts.map +0 -1
- package/lib/utils/selection-helpers.js +0 -162
- package/lib/utils/slot-helpers.d.ts.map +0 -1
- package/lib/utils/slot-helpers.js +0 -27
- package/lib/utils/special-columns.utils.d.ts.map +0 -1
- package/lib/utils/special-columns.utils.js +0 -77
- package/lib/utils/styling-helpers.d.ts.map +0 -1
- package/lib/utils/styling-helpers.js +0 -97
- package/lib/utils/table-helpers.d.ts.map +0 -1
- package/lib/utils/table-helpers.js +0 -72
- package/lib/utils/value-helpers.d.ts.map +0 -1
- package/lib/utils/value-helpers.js +0 -48
- package/tsconfig.lib.tsbuildinfo +0 -1
|
@@ -1,673 +0,0 @@
|
|
|
1
|
-
import { useImperativeHandle } from 'react';
|
|
2
|
-
import { exportClientData, exportServerData } from '../utils/export-utils';
|
|
3
|
-
export function useDataTableApi(props, ref) {
|
|
4
|
-
const { table, data, idKey, globalFilter, customColumnsFilter, sorting, pagination, columnOrder, columnPinning, enhancedColumns, enablePagination, enableColumnPinning, initialPageIndex, initialPageSize, pageSize,
|
|
5
|
-
// Selection props
|
|
6
|
-
selectMode = 'page', onSelectionChange, handleColumnFilterStateChange, onDataStateChange, onFetchData, onDataChange,
|
|
7
|
-
// Export props
|
|
8
|
-
exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, exportController, setExportController, isExporting, dataMode = 'client', } = props;
|
|
9
|
-
// Note: Custom selection is now handled by TanStack Table CustomSelectionFeature
|
|
10
|
-
useImperativeHandle(ref, () => ({
|
|
11
|
-
table: {
|
|
12
|
-
getTable: () => table,
|
|
13
|
-
},
|
|
14
|
-
// Column Management
|
|
15
|
-
columnVisibility: {
|
|
16
|
-
showColumn: (columnId) => {
|
|
17
|
-
table.getColumn(columnId)?.toggleVisibility(true);
|
|
18
|
-
},
|
|
19
|
-
hideColumn: (columnId) => {
|
|
20
|
-
table.getColumn(columnId)?.toggleVisibility(false);
|
|
21
|
-
},
|
|
22
|
-
toggleColumn: (columnId) => {
|
|
23
|
-
table.getColumn(columnId)?.toggleVisibility();
|
|
24
|
-
},
|
|
25
|
-
showAllColumns: () => {
|
|
26
|
-
table.toggleAllColumnsVisible(true);
|
|
27
|
-
},
|
|
28
|
-
hideAllColumns: () => {
|
|
29
|
-
table.toggleAllColumnsVisible(false);
|
|
30
|
-
},
|
|
31
|
-
resetColumnVisibility: () => {
|
|
32
|
-
table.resetColumnVisibility();
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
// Column Ordering
|
|
36
|
-
columnOrdering: {
|
|
37
|
-
setColumnOrder: (columnOrder) => {
|
|
38
|
-
table.setColumnOrder(columnOrder);
|
|
39
|
-
},
|
|
40
|
-
moveColumn: (columnId, toIndex) => {
|
|
41
|
-
const currentOrder = table.getState().columnOrder || [];
|
|
42
|
-
const currentIndex = currentOrder.indexOf(columnId);
|
|
43
|
-
if (currentIndex === -1)
|
|
44
|
-
return;
|
|
45
|
-
const newOrder = [...currentOrder];
|
|
46
|
-
newOrder.splice(currentIndex, 1);
|
|
47
|
-
newOrder.splice(toIndex, 0, columnId);
|
|
48
|
-
table.setColumnOrder(newOrder);
|
|
49
|
-
},
|
|
50
|
-
resetColumnOrder: () => {
|
|
51
|
-
const initialOrder = enhancedColumns.map((col, index) => {
|
|
52
|
-
if (col.id)
|
|
53
|
-
return col.id;
|
|
54
|
-
const anyCol = col;
|
|
55
|
-
if (anyCol.accessorKey && typeof anyCol.accessorKey === 'string') {
|
|
56
|
-
return anyCol.accessorKey;
|
|
57
|
-
}
|
|
58
|
-
return `column_${index}`;
|
|
59
|
-
});
|
|
60
|
-
table.setColumnOrder(initialOrder);
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
// Column Pinning
|
|
64
|
-
columnPinning: {
|
|
65
|
-
pinColumnLeft: (columnId) => {
|
|
66
|
-
const currentPinning = table.getState().columnPinning;
|
|
67
|
-
const newPinning = { ...currentPinning };
|
|
68
|
-
// Remove from right if exists
|
|
69
|
-
newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
|
|
70
|
-
// Add to left if not exists
|
|
71
|
-
newPinning.left = [...(newPinning.left || []).filter(id => id !== columnId), columnId];
|
|
72
|
-
table.setColumnPinning(newPinning);
|
|
73
|
-
},
|
|
74
|
-
pinColumnRight: (columnId) => {
|
|
75
|
-
const currentPinning = table.getState().columnPinning;
|
|
76
|
-
const newPinning = { ...currentPinning };
|
|
77
|
-
// Remove from left if exists
|
|
78
|
-
newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
|
|
79
|
-
// Add to right if not exists
|
|
80
|
-
newPinning.right = [...(newPinning.right || []).filter(id => id !== columnId), columnId];
|
|
81
|
-
table.setColumnPinning(newPinning);
|
|
82
|
-
},
|
|
83
|
-
unpinColumn: (columnId) => {
|
|
84
|
-
const currentPinning = table.getState().columnPinning;
|
|
85
|
-
const newPinning = {
|
|
86
|
-
left: (currentPinning.left || []).filter(id => id !== columnId),
|
|
87
|
-
right: (currentPinning.right || []).filter(id => id !== columnId),
|
|
88
|
-
};
|
|
89
|
-
table.setColumnPinning(newPinning);
|
|
90
|
-
},
|
|
91
|
-
setPinning: (pinning) => {
|
|
92
|
-
table.setColumnPinning(pinning);
|
|
93
|
-
},
|
|
94
|
-
resetColumnPinning: () => {
|
|
95
|
-
table.setColumnPinning(table.initialState.columnPinning);
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
// Column Resizing
|
|
99
|
-
columnResizing: {
|
|
100
|
-
resizeColumn: (columnId, width) => {
|
|
101
|
-
// Use table's setColumnSizing method
|
|
102
|
-
const currentSizing = table.getState().columnSizing;
|
|
103
|
-
table.setColumnSizing({
|
|
104
|
-
...currentSizing,
|
|
105
|
-
[columnId]: width,
|
|
106
|
-
});
|
|
107
|
-
},
|
|
108
|
-
autoSizeColumn: (columnId) => {
|
|
109
|
-
// TanStack doesn't have built-in auto-size, so reset to default
|
|
110
|
-
table.getColumn(columnId)?.resetSize();
|
|
111
|
-
},
|
|
112
|
-
autoSizeAllColumns: () => {
|
|
113
|
-
table.resetColumnSizing();
|
|
114
|
-
},
|
|
115
|
-
resetColumnSizing: () => {
|
|
116
|
-
table.resetColumnSizing();
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
// Filtering
|
|
120
|
-
filtering: {
|
|
121
|
-
setGlobalFilter: (filter) => {
|
|
122
|
-
table.setGlobalFilter(filter);
|
|
123
|
-
},
|
|
124
|
-
clearGlobalFilter: () => {
|
|
125
|
-
table.setGlobalFilter('');
|
|
126
|
-
},
|
|
127
|
-
setCustomColumnFilters: (filters) => {
|
|
128
|
-
handleColumnFilterStateChange(filters);
|
|
129
|
-
},
|
|
130
|
-
addColumnFilter: (columnId, operator, value) => {
|
|
131
|
-
const newFilter = {
|
|
132
|
-
id: `filter_${Date.now()}`,
|
|
133
|
-
columnId,
|
|
134
|
-
operator,
|
|
135
|
-
value,
|
|
136
|
-
};
|
|
137
|
-
const currentFilters = customColumnsFilter.filters || [];
|
|
138
|
-
const newFilters = [...currentFilters, newFilter];
|
|
139
|
-
handleColumnFilterStateChange({
|
|
140
|
-
filters: newFilters,
|
|
141
|
-
logic: customColumnsFilter.logic,
|
|
142
|
-
pendingFilters: customColumnsFilter.pendingFilters || [],
|
|
143
|
-
pendingLogic: customColumnsFilter.pendingLogic || 'AND',
|
|
144
|
-
});
|
|
145
|
-
},
|
|
146
|
-
removeColumnFilter: (filterId) => {
|
|
147
|
-
const currentFilters = customColumnsFilter.filters || [];
|
|
148
|
-
const newFilters = currentFilters.filter((f) => f.id !== filterId);
|
|
149
|
-
handleColumnFilterStateChange({
|
|
150
|
-
filters: newFilters,
|
|
151
|
-
logic: customColumnsFilter.logic,
|
|
152
|
-
pendingFilters: customColumnsFilter.pendingFilters || [],
|
|
153
|
-
pendingLogic: customColumnsFilter.pendingLogic || 'AND',
|
|
154
|
-
});
|
|
155
|
-
},
|
|
156
|
-
clearAllFilters: () => {
|
|
157
|
-
table.setGlobalFilter('');
|
|
158
|
-
handleColumnFilterStateChange({
|
|
159
|
-
filters: [],
|
|
160
|
-
logic: 'AND',
|
|
161
|
-
pendingFilters: [],
|
|
162
|
-
pendingLogic: 'AND',
|
|
163
|
-
});
|
|
164
|
-
},
|
|
165
|
-
resetFilters: () => {
|
|
166
|
-
table.resetGlobalFilter();
|
|
167
|
-
handleColumnFilterStateChange({
|
|
168
|
-
filters: [],
|
|
169
|
-
logic: 'AND',
|
|
170
|
-
pendingFilters: [],
|
|
171
|
-
pendingLogic: 'AND',
|
|
172
|
-
});
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
// Sorting
|
|
176
|
-
sorting: {
|
|
177
|
-
setSorting: (sortingState) => {
|
|
178
|
-
table.setSorting(sortingState);
|
|
179
|
-
},
|
|
180
|
-
sortColumn: (columnId, direction) => {
|
|
181
|
-
const column = table.getColumn(columnId);
|
|
182
|
-
if (!column)
|
|
183
|
-
return;
|
|
184
|
-
if (direction === false) {
|
|
185
|
-
column.clearSorting();
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
column.toggleSorting(direction === 'desc');
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
clearSorting: () => {
|
|
192
|
-
table.resetSorting();
|
|
193
|
-
},
|
|
194
|
-
resetSorting: () => {
|
|
195
|
-
table.resetSorting();
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
// Pagination
|
|
199
|
-
pagination: {
|
|
200
|
-
goToPage: (pageIndex) => {
|
|
201
|
-
table.setPageIndex(pageIndex);
|
|
202
|
-
},
|
|
203
|
-
nextPage: () => {
|
|
204
|
-
table.nextPage();
|
|
205
|
-
},
|
|
206
|
-
previousPage: () => {
|
|
207
|
-
table.previousPage();
|
|
208
|
-
},
|
|
209
|
-
setPageSize: (pageSize) => {
|
|
210
|
-
table.setPageSize(pageSize);
|
|
211
|
-
},
|
|
212
|
-
goToFirstPage: () => {
|
|
213
|
-
table.setPageIndex(0);
|
|
214
|
-
},
|
|
215
|
-
goToLastPage: () => {
|
|
216
|
-
const pageCount = table.getPageCount();
|
|
217
|
-
if (pageCount > 0) {
|
|
218
|
-
table.setPageIndex(pageCount - 1);
|
|
219
|
-
}
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
// Selection methods now use TanStack Table CustomSelectionFeature
|
|
223
|
-
// Access via table methods: table.selectRow(), table.getIsRowSelected(), etc.
|
|
224
|
-
selection: {
|
|
225
|
-
selectRow: (rowId) => table.selectRow?.(rowId),
|
|
226
|
-
deselectRow: (rowId) => table.deselectRow?.(rowId),
|
|
227
|
-
toggleRowSelection: (rowId) => table.toggleRowSelected?.(rowId),
|
|
228
|
-
selectAll: () => table.selectAll?.(),
|
|
229
|
-
deselectAll: () => table.deselectAll?.(),
|
|
230
|
-
toggleSelectAll: () => table.toggleAllRowsSelected?.(),
|
|
231
|
-
getSelectionState: () => table.getSelectionState?.() || { ids: [], type: 'include' },
|
|
232
|
-
getSelectedRows: () => table.getSelectedRows(),
|
|
233
|
-
getSelectedCount: () => table.getSelectedCount(),
|
|
234
|
-
isRowSelected: (rowId) => table.getIsRowSelected(rowId) || false,
|
|
235
|
-
},
|
|
236
|
-
// Data Management
|
|
237
|
-
data: {
|
|
238
|
-
refresh: () => {
|
|
239
|
-
// Call external data state change handler to trigger refresh
|
|
240
|
-
const currentFilters = {
|
|
241
|
-
globalFilter,
|
|
242
|
-
customColumnsFilter: customColumnsFilter,
|
|
243
|
-
sorting,
|
|
244
|
-
pagination,
|
|
245
|
-
};
|
|
246
|
-
if (onDataStateChange) {
|
|
247
|
-
const currentState = {
|
|
248
|
-
...currentFilters,
|
|
249
|
-
columnOrder,
|
|
250
|
-
columnPinning,
|
|
251
|
-
};
|
|
252
|
-
onDataStateChange(currentState);
|
|
253
|
-
}
|
|
254
|
-
if (onFetchData) {
|
|
255
|
-
onFetchData(currentFilters);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
reload: () => {
|
|
259
|
-
// Same as refresh for now
|
|
260
|
-
const currentFilters = {
|
|
261
|
-
globalFilter,
|
|
262
|
-
customColumnsFilter: customColumnsFilter,
|
|
263
|
-
sorting,
|
|
264
|
-
pagination,
|
|
265
|
-
};
|
|
266
|
-
if (onDataStateChange) {
|
|
267
|
-
const currentState = {
|
|
268
|
-
...currentFilters,
|
|
269
|
-
columnOrder,
|
|
270
|
-
columnPinning,
|
|
271
|
-
};
|
|
272
|
-
onDataStateChange({ ...currentState });
|
|
273
|
-
}
|
|
274
|
-
if (onFetchData) {
|
|
275
|
-
onFetchData({ ...currentFilters });
|
|
276
|
-
}
|
|
277
|
-
},
|
|
278
|
-
// Data CRUD operations
|
|
279
|
-
getAllData: () => {
|
|
280
|
-
return [...data];
|
|
281
|
-
},
|
|
282
|
-
getRowData: (rowId) => {
|
|
283
|
-
return data.find(row => String(row[idKey]) === rowId);
|
|
284
|
-
},
|
|
285
|
-
getRowByIndex: (index) => {
|
|
286
|
-
return data[index];
|
|
287
|
-
},
|
|
288
|
-
updateRow: (rowId, updates) => {
|
|
289
|
-
const newData = data.map(row => String(row[idKey]) === rowId
|
|
290
|
-
? {
|
|
291
|
-
...row,
|
|
292
|
-
...updates,
|
|
293
|
-
}
|
|
294
|
-
: row);
|
|
295
|
-
onDataChange?.(newData);
|
|
296
|
-
},
|
|
297
|
-
updateRowByIndex: (index, updates) => {
|
|
298
|
-
const newData = [...data];
|
|
299
|
-
if (newData[index]) {
|
|
300
|
-
newData[index] = {
|
|
301
|
-
...newData[index],
|
|
302
|
-
...updates,
|
|
303
|
-
};
|
|
304
|
-
onDataChange?.(newData);
|
|
305
|
-
}
|
|
306
|
-
},
|
|
307
|
-
insertRow: (newRow, index) => {
|
|
308
|
-
const newData = [...data];
|
|
309
|
-
if (index !== undefined) {
|
|
310
|
-
newData.splice(index, 0, newRow);
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
newData.push(newRow);
|
|
314
|
-
}
|
|
315
|
-
onDataChange?.(newData);
|
|
316
|
-
},
|
|
317
|
-
deleteRow: (rowId) => {
|
|
318
|
-
const newData = data.filter(row => String(row[idKey]) !== rowId);
|
|
319
|
-
onDataChange?.(newData);
|
|
320
|
-
},
|
|
321
|
-
deleteRowByIndex: (index) => {
|
|
322
|
-
const newData = [...data];
|
|
323
|
-
newData.splice(index, 1);
|
|
324
|
-
onDataChange?.(newData);
|
|
325
|
-
},
|
|
326
|
-
deleteSelectedRows: () => {
|
|
327
|
-
const selectedRowIds = Object.keys(table.getState().rowSelection)
|
|
328
|
-
.filter(key => table.getState().rowSelection[key]);
|
|
329
|
-
const newData = data.filter(row => !selectedRowIds.includes(String(row[idKey])));
|
|
330
|
-
onDataChange?.(newData);
|
|
331
|
-
// Clear selection after deletion
|
|
332
|
-
table.resetRowSelection();
|
|
333
|
-
},
|
|
334
|
-
replaceAllData: (newData) => {
|
|
335
|
-
onDataChange?.(newData);
|
|
336
|
-
},
|
|
337
|
-
// Bulk operations
|
|
338
|
-
updateMultipleRows: (updates) => {
|
|
339
|
-
const updateMap = new Map(updates.map(u => [u.rowId, u.data]));
|
|
340
|
-
const newData = data.map(row => {
|
|
341
|
-
const rowId = String(row[idKey]);
|
|
342
|
-
const updateData = updateMap.get(rowId);
|
|
343
|
-
return updateData ? {
|
|
344
|
-
...row,
|
|
345
|
-
...updateData,
|
|
346
|
-
} : row;
|
|
347
|
-
});
|
|
348
|
-
onDataChange?.(newData);
|
|
349
|
-
},
|
|
350
|
-
insertMultipleRows: (newRows, startIndex) => {
|
|
351
|
-
const newData = [...data];
|
|
352
|
-
if (startIndex !== undefined) {
|
|
353
|
-
newData.splice(startIndex, 0, ...newRows);
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
newData.push(...newRows);
|
|
357
|
-
}
|
|
358
|
-
onDataChange?.(newData);
|
|
359
|
-
},
|
|
360
|
-
deleteMultipleRows: (rowIds) => {
|
|
361
|
-
const idsToDelete = new Set(rowIds);
|
|
362
|
-
const newData = data.filter(row => !idsToDelete.has(String(row[idKey])));
|
|
363
|
-
onDataChange?.(newData);
|
|
364
|
-
},
|
|
365
|
-
// Field-specific updates
|
|
366
|
-
updateField: (rowId, fieldName, value) => {
|
|
367
|
-
const newData = data.map(row => String(row[idKey]) === rowId
|
|
368
|
-
? {
|
|
369
|
-
...row,
|
|
370
|
-
[fieldName]: value,
|
|
371
|
-
}
|
|
372
|
-
: row);
|
|
373
|
-
onDataChange?.(newData);
|
|
374
|
-
},
|
|
375
|
-
updateFieldByIndex: (index, fieldName, value) => {
|
|
376
|
-
const newData = [...data];
|
|
377
|
-
if (newData[index]) {
|
|
378
|
-
newData[index] = {
|
|
379
|
-
...newData[index],
|
|
380
|
-
[fieldName]: value,
|
|
381
|
-
};
|
|
382
|
-
onDataChange?.(newData);
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
// Data queries
|
|
386
|
-
findRows: (predicate) => {
|
|
387
|
-
return data.filter(predicate);
|
|
388
|
-
},
|
|
389
|
-
findRowIndex: (predicate) => {
|
|
390
|
-
return data.findIndex(predicate);
|
|
391
|
-
},
|
|
392
|
-
getDataCount: () => {
|
|
393
|
-
return data.length;
|
|
394
|
-
},
|
|
395
|
-
getFilteredDataCount: () => {
|
|
396
|
-
return table.getFilteredRowModel().rows.length;
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
// Layout Management
|
|
400
|
-
layout: {
|
|
401
|
-
resetLayout: () => {
|
|
402
|
-
table.resetColumnSizing();
|
|
403
|
-
table.resetColumnVisibility();
|
|
404
|
-
table.resetSorting();
|
|
405
|
-
table.resetGlobalFilter();
|
|
406
|
-
},
|
|
407
|
-
resetAll: () => {
|
|
408
|
-
// Reset everything to initial state
|
|
409
|
-
table.resetColumnSizing();
|
|
410
|
-
table.resetColumnVisibility();
|
|
411
|
-
table.resetSorting();
|
|
412
|
-
table.resetGlobalFilter();
|
|
413
|
-
table.resetColumnOrder();
|
|
414
|
-
table.resetExpanded();
|
|
415
|
-
table.resetRowSelection();
|
|
416
|
-
table.resetColumnPinning();
|
|
417
|
-
handleColumnFilterStateChange({
|
|
418
|
-
filters: [],
|
|
419
|
-
logic: 'AND',
|
|
420
|
-
pendingFilters: [],
|
|
421
|
-
pendingLogic: 'AND',
|
|
422
|
-
});
|
|
423
|
-
if (enablePagination) {
|
|
424
|
-
table.setPageIndex(initialPageIndex);
|
|
425
|
-
table.setPageSize(initialPageSize || pageSize);
|
|
426
|
-
}
|
|
427
|
-
if (enableColumnPinning) {
|
|
428
|
-
table.setColumnPinning({
|
|
429
|
-
left: [],
|
|
430
|
-
right: [],
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
},
|
|
434
|
-
saveLayout: () => {
|
|
435
|
-
return {
|
|
436
|
-
columnVisibility: table.getState().columnVisibility,
|
|
437
|
-
columnSizing: table.getState().columnSizing,
|
|
438
|
-
columnOrder: table.getState().columnOrder,
|
|
439
|
-
columnPinning: table.getState().columnPinning,
|
|
440
|
-
sorting: table.getState().sorting,
|
|
441
|
-
pagination: table.getState().pagination,
|
|
442
|
-
globalFilter: table.getState().globalFilter,
|
|
443
|
-
customColumnsFilter: customColumnsFilter,
|
|
444
|
-
};
|
|
445
|
-
},
|
|
446
|
-
restoreLayout: (layout) => {
|
|
447
|
-
if (layout.columnVisibility) {
|
|
448
|
-
table.setColumnVisibility(layout.columnVisibility);
|
|
449
|
-
}
|
|
450
|
-
if (layout.columnSizing) {
|
|
451
|
-
table.setColumnSizing(layout.columnSizing);
|
|
452
|
-
}
|
|
453
|
-
if (layout.columnOrder) {
|
|
454
|
-
table.setColumnOrder(layout.columnOrder);
|
|
455
|
-
}
|
|
456
|
-
if (layout.columnPinning) {
|
|
457
|
-
table.setColumnPinning(layout.columnPinning);
|
|
458
|
-
}
|
|
459
|
-
if (layout.sorting) {
|
|
460
|
-
table.setSorting(layout.sorting);
|
|
461
|
-
}
|
|
462
|
-
if (layout.pagination && enablePagination) {
|
|
463
|
-
table.setPagination(layout.pagination);
|
|
464
|
-
}
|
|
465
|
-
if (layout.globalFilter !== undefined) {
|
|
466
|
-
table.setGlobalFilter(layout.globalFilter);
|
|
467
|
-
}
|
|
468
|
-
if (layout.customColumnsFilter) {
|
|
469
|
-
handleColumnFilterStateChange(layout.customColumnsFilter);
|
|
470
|
-
}
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
// Table State
|
|
474
|
-
state: {
|
|
475
|
-
getTableState: () => {
|
|
476
|
-
return table.getState();
|
|
477
|
-
},
|
|
478
|
-
getCurrentFilters: () => {
|
|
479
|
-
return customColumnsFilter;
|
|
480
|
-
},
|
|
481
|
-
getCurrentSorting: () => {
|
|
482
|
-
return table.getState().sorting;
|
|
483
|
-
},
|
|
484
|
-
getCurrentPagination: () => {
|
|
485
|
-
return table.getState().pagination;
|
|
486
|
-
},
|
|
487
|
-
getCurrentSelection: () => {
|
|
488
|
-
return Object.keys(table.getState().rowSelection)
|
|
489
|
-
.filter(key => table.getState().rowSelection[key]);
|
|
490
|
-
},
|
|
491
|
-
},
|
|
492
|
-
// Simplified Export
|
|
493
|
-
export: {
|
|
494
|
-
exportCSV: async (options = {}) => {
|
|
495
|
-
const { filename = exportFilename, } = options;
|
|
496
|
-
try {
|
|
497
|
-
// Create abort controller for this export
|
|
498
|
-
const controller = new AbortController();
|
|
499
|
-
setExportController?.(controller);
|
|
500
|
-
if (dataMode === 'server' && onServerExport) {
|
|
501
|
-
// Server export with selection data
|
|
502
|
-
const currentFilters = {
|
|
503
|
-
globalFilter,
|
|
504
|
-
customColumnsFilter,
|
|
505
|
-
sorting,
|
|
506
|
-
pagination,
|
|
507
|
-
columnOrder,
|
|
508
|
-
columnPinning,
|
|
509
|
-
};
|
|
510
|
-
await exportServerData(table, {
|
|
511
|
-
format: 'csv',
|
|
512
|
-
filename,
|
|
513
|
-
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
514
|
-
currentFilters,
|
|
515
|
-
selection: table.getSelectionState?.(),
|
|
516
|
-
onProgress: onExportProgress,
|
|
517
|
-
onComplete: onExportComplete,
|
|
518
|
-
onError: onExportError,
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
// Client export - auto-detect selected rows if not specified
|
|
523
|
-
await exportClientData(table, {
|
|
524
|
-
format: 'csv',
|
|
525
|
-
filename,
|
|
526
|
-
onProgress: onExportProgress,
|
|
527
|
-
onComplete: onExportComplete,
|
|
528
|
-
onError: onExportError,
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
catch (error) {
|
|
533
|
-
onExportError?.({
|
|
534
|
-
message: error.message || 'Export failed',
|
|
535
|
-
code: 'EXPORT_ERROR',
|
|
536
|
-
});
|
|
537
|
-
}
|
|
538
|
-
finally {
|
|
539
|
-
setExportController?.(null);
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
|
-
exportExcel: async (options = {}) => {
|
|
543
|
-
const { filename = exportFilename } = options;
|
|
544
|
-
try {
|
|
545
|
-
// Create abort controller for this export
|
|
546
|
-
const controller = new AbortController();
|
|
547
|
-
setExportController?.(controller);
|
|
548
|
-
if (dataMode === 'server' && onServerExport) {
|
|
549
|
-
// Server export with selection data
|
|
550
|
-
const currentFilters = {
|
|
551
|
-
globalFilter,
|
|
552
|
-
customColumnsFilter,
|
|
553
|
-
sorting,
|
|
554
|
-
pagination,
|
|
555
|
-
columnOrder,
|
|
556
|
-
columnPinning,
|
|
557
|
-
};
|
|
558
|
-
await exportServerData(table, {
|
|
559
|
-
format: 'excel',
|
|
560
|
-
filename,
|
|
561
|
-
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
562
|
-
currentFilters,
|
|
563
|
-
selection: table.getSelectionState?.(),
|
|
564
|
-
onProgress: onExportProgress,
|
|
565
|
-
onComplete: onExportComplete,
|
|
566
|
-
onError: onExportError,
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
else {
|
|
570
|
-
// Client export - auto-detect selected rows if not specified
|
|
571
|
-
await exportClientData(table, {
|
|
572
|
-
format: 'excel',
|
|
573
|
-
filename,
|
|
574
|
-
onProgress: onExportProgress,
|
|
575
|
-
onComplete: onExportComplete,
|
|
576
|
-
onError: onExportError,
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
catch (error) {
|
|
581
|
-
onExportError?.({
|
|
582
|
-
message: error.message || 'Export failed',
|
|
583
|
-
code: 'EXPORT_ERROR',
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
finally {
|
|
587
|
-
setExportController?.(null);
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
exportServerData: async (options) => {
|
|
591
|
-
const { format, filename = exportFilename, fetchData = onServerExport, } = options;
|
|
592
|
-
if (!fetchData) {
|
|
593
|
-
onExportError?.({
|
|
594
|
-
message: 'No server export function provided',
|
|
595
|
-
code: 'NO_SERVER_EXPORT',
|
|
596
|
-
});
|
|
597
|
-
return;
|
|
598
|
-
}
|
|
599
|
-
try {
|
|
600
|
-
// Create abort controller for this export
|
|
601
|
-
const controller = new AbortController();
|
|
602
|
-
setExportController?.(controller);
|
|
603
|
-
const currentFilters = {
|
|
604
|
-
globalFilter,
|
|
605
|
-
customColumnsFilter,
|
|
606
|
-
sorting,
|
|
607
|
-
pagination,
|
|
608
|
-
columnOrder,
|
|
609
|
-
columnPinning,
|
|
610
|
-
};
|
|
611
|
-
await exportServerData(table, {
|
|
612
|
-
format,
|
|
613
|
-
filename,
|
|
614
|
-
fetchData: (filters, selection) => fetchData(filters, selection),
|
|
615
|
-
currentFilters,
|
|
616
|
-
selection: table.getSelectionState?.(),
|
|
617
|
-
onProgress: onExportProgress,
|
|
618
|
-
onComplete: onExportComplete,
|
|
619
|
-
onError: onExportError,
|
|
620
|
-
});
|
|
621
|
-
}
|
|
622
|
-
catch (error) {
|
|
623
|
-
onExportError?.({
|
|
624
|
-
message: error.message || 'Export failed',
|
|
625
|
-
code: 'EXPORT_ERROR',
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
finally {
|
|
629
|
-
setExportController?.(null);
|
|
630
|
-
}
|
|
631
|
-
},
|
|
632
|
-
// Export state
|
|
633
|
-
isExporting: () => isExporting || false,
|
|
634
|
-
cancelExport: () => {
|
|
635
|
-
exportController?.abort();
|
|
636
|
-
setExportController?.(null);
|
|
637
|
-
},
|
|
638
|
-
},
|
|
639
|
-
}), [
|
|
640
|
-
table,
|
|
641
|
-
enhancedColumns,
|
|
642
|
-
handleColumnFilterStateChange,
|
|
643
|
-
customColumnsFilter,
|
|
644
|
-
data,
|
|
645
|
-
idKey,
|
|
646
|
-
onDataStateChange,
|
|
647
|
-
onFetchData,
|
|
648
|
-
globalFilter,
|
|
649
|
-
sorting,
|
|
650
|
-
pagination,
|
|
651
|
-
columnOrder,
|
|
652
|
-
columnPinning,
|
|
653
|
-
onDataChange,
|
|
654
|
-
enableColumnPinning,
|
|
655
|
-
enablePagination,
|
|
656
|
-
initialPageIndex,
|
|
657
|
-
initialPageSize,
|
|
658
|
-
pageSize,
|
|
659
|
-
// Export dependencies
|
|
660
|
-
exportFilename,
|
|
661
|
-
onExportProgress,
|
|
662
|
-
onExportComplete,
|
|
663
|
-
onExportError,
|
|
664
|
-
onServerExport,
|
|
665
|
-
exportController,
|
|
666
|
-
setExportController,
|
|
667
|
-
isExporting,
|
|
668
|
-
dataMode,
|
|
669
|
-
selectMode,
|
|
670
|
-
onSelectionChange,
|
|
671
|
-
// Note: custom selection removed from dependency array
|
|
672
|
-
]);
|
|
673
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-table-state.d.ts","sourceRoot":"","sources":["../../../src/lib/hooks/use-table-state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACH,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EAClB,MAAM,uBAAuB,CAAC;AAK/B,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAGjG;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB;;;;;;;;;;;EAkF/D"}
|