@ackplus/react-tanstack-data-table 1.0.19-beta-0.7 → 1.0.19-beta-0.8
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/README.md +599 -0
- package/package.json +1 -1
- package/src/index.d.ts +19 -0
- package/src/index.js +31 -0
- package/src/lib/components/droupdown/menu-dropdown.d.ts +17 -0
- package/src/lib/components/droupdown/menu-dropdown.js +52 -0
- package/src/lib/components/filters/filter-value-input.d.ts +9 -0
- package/src/lib/components/filters/filter-value-input.js +58 -0
- package/src/lib/components/filters/index.d.ts +23 -0
- package/src/lib/components/filters/index.js +129 -0
- package/src/lib/components/headers/draggable-header.d.ts +12 -0
- package/src/lib/components/headers/draggable-header.js +212 -0
- package/src/lib/components/headers/index.d.ts +2 -0
- package/src/lib/components/headers/index.js +5 -0
- package/src/lib/components/headers/table-header.d.ts +10 -0
- package/src/lib/components/headers/table-header.js +48 -0
- package/src/lib/components/index.d.ts +7 -0
- package/src/lib/components/index.js +10 -0
- package/src/lib/components/pagination/data-table-pagination.d.ts +11 -0
- package/src/lib/components/pagination/data-table-pagination.js +25 -0
- package/src/lib/components/pagination/index.d.ts +1 -0
- package/src/lib/components/pagination/index.js +4 -0
- package/src/lib/components/rows/data-table-row.d.ts +13 -0
- package/src/lib/components/rows/data-table-row.js +31 -0
- package/src/lib/components/rows/empty-data-row.d.ts +6 -0
- package/src/lib/components/rows/empty-data-row.js +11 -0
- package/src/lib/components/rows/index.d.ts +3 -0
- package/src/lib/components/rows/index.js +6 -0
- package/src/lib/components/rows/loading-rows.d.ts +5 -0
- package/src/lib/components/rows/loading-rows.js +49 -0
- package/src/lib/components/table/data-table.d.ts +3 -0
- package/src/lib/components/table/data-table.js +492 -0
- package/src/lib/components/table/data-table.types.d.ts +114 -0
- package/src/lib/components/table/data-table.types.js +2 -0
- package/src/lib/components/table/index.d.ts +2 -0
- package/src/lib/components/table/index.js +5 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.d.ts +9 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.js +25 -0
- package/src/lib/components/toolbar/column-custom-filter-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-custom-filter-control.js +137 -0
- package/src/lib/components/toolbar/column-pinning-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-pinning-control.js +105 -0
- package/src/lib/components/toolbar/column-reset-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-reset-control.js +16 -0
- package/src/lib/components/toolbar/column-visibility-control.d.ts +1 -0
- package/src/lib/components/toolbar/column-visibility-control.js +31 -0
- package/src/lib/components/toolbar/data-table-toolbar.d.ts +14 -0
- package/src/lib/components/toolbar/data-table-toolbar.js +26 -0
- package/src/lib/components/toolbar/index.d.ts +8 -0
- package/src/lib/components/toolbar/index.js +17 -0
- package/src/lib/components/toolbar/table-export-control.d.ts +25 -0
- package/src/lib/components/toolbar/table-export-control.js +93 -0
- package/src/lib/components/toolbar/table-search-control.d.ts +1 -0
- package/src/lib/components/toolbar/table-search-control.js +61 -0
- package/src/lib/components/toolbar/table-size-control.d.ts +1 -0
- package/src/lib/components/toolbar/table-size-control.js +36 -0
- package/src/lib/contexts/data-table-context.d.ts +43 -0
- package/src/lib/contexts/data-table-context.js +54 -0
- package/src/lib/examples/advanced-features-example.d.ts +1 -0
- package/src/lib/examples/advanced-features-example.js +264 -0
- package/src/lib/examples/bulk-actions-test.d.ts +1 -0
- package/src/lib/examples/bulk-actions-test.js +44 -0
- package/src/lib/examples/custom-column-filter-example.d.ts +1 -0
- package/src/lib/examples/custom-column-filter-example.js +60 -0
- package/src/lib/examples/index.d.ts +5 -0
- package/src/lib/examples/index.js +13 -0
- package/src/lib/examples/selection-test-example.d.ts +1 -0
- package/src/lib/examples/selection-test-example.js +101 -0
- package/src/lib/examples/simple-local-example.d.ts +1 -0
- package/src/lib/examples/simple-local-example.js +97 -0
- package/src/lib/features/custom-column-filter.feature.d.ts +45 -0
- package/src/lib/features/custom-column-filter.feature.js +247 -0
- package/src/lib/features/custom-selection.feature.d.ts +46 -0
- package/src/lib/features/custom-selection.feature.js +172 -0
- package/src/lib/features/index.d.ts +2 -0
- package/src/lib/features/index.js +8 -0
- package/src/lib/hooks/index.d.ts +1 -0
- package/src/lib/hooks/index.js +4 -0
- package/src/lib/hooks/use-data-table-api.d.ts +56 -0
- package/src/lib/hooks/use-data-table-api.js +616 -0
- package/src/lib/icons/add-icon.d.ts +2 -0
- package/src/lib/icons/add-icon.js +8 -0
- package/src/lib/icons/csv-icon.d.ts +2 -0
- package/src/lib/icons/csv-icon.js +8 -0
- package/src/lib/icons/delete-icon.d.ts +2 -0
- package/src/lib/icons/delete-icon.js +8 -0
- package/src/lib/icons/excel-icon.d.ts +2 -0
- package/src/lib/icons/excel-icon.js +8 -0
- package/src/lib/icons/index.d.ts +7 -0
- package/src/lib/icons/index.js +17 -0
- package/src/lib/icons/unpin-icon.d.ts +2 -0
- package/src/lib/icons/unpin-icon.js +8 -0
- package/src/lib/icons/view-comfortable-icon.d.ts +2 -0
- package/src/lib/icons/view-comfortable-icon.js +8 -0
- package/src/lib/icons/view-compact-icon.d.ts +2 -0
- package/src/lib/icons/view-compact-icon.js +8 -0
- package/src/lib/types/column.types.d.ts +29 -0
- package/src/lib/types/column.types.js +5 -0
- package/src/lib/types/data-table-api.d.ts +134 -0
- package/src/lib/types/data-table-api.js +2 -0
- package/src/lib/types/export.types.d.ts +99 -0
- package/src/lib/types/export.types.js +2 -0
- package/src/lib/types/index.d.ts +6 -0
- package/src/lib/types/index.js +8 -0
- package/src/lib/types/slots.types.d.ts +272 -0
- package/src/lib/types/slots.types.js +2 -0
- package/src/lib/types/table.types.d.ts +63 -0
- package/src/lib/types/table.types.js +2 -0
- package/src/lib/utils/column-helpers.d.ts +7 -0
- package/src/lib/utils/column-helpers.js +43 -0
- package/src/lib/utils/debounced-fetch.utils.d.ts +11 -0
- package/src/lib/utils/debounced-fetch.utils.js +49 -0
- package/src/lib/utils/export-utils.d.ts +30 -0
- package/src/lib/utils/export-utils.js +152 -0
- package/src/lib/utils/index.d.ts +7 -0
- package/src/lib/utils/index.js +10 -0
- package/src/lib/utils/slot-helpers.d.ts +9 -0
- package/src/lib/utils/slot-helpers.js +21 -0
- package/src/lib/utils/special-columns.utils.d.ts +6 -0
- package/src/lib/utils/special-columns.utils.js +52 -0
- package/src/lib/utils/styling-helpers.d.ts +36 -0
- package/src/lib/utils/styling-helpers.js +61 -0
- package/src/lib/utils/table-helpers.d.ts +9 -0
- package/src/lib/utils/table-helpers.js +57 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDataTableApi = useDataTableApi;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const export_utils_1 = require("../utils/export-utils");
|
|
7
|
+
function useDataTableApi(props, ref) {
|
|
8
|
+
const { table, data, idKey, globalFilter, customColumnsFilter, sorting, pagination, columnOrder, columnPinning, enhancedColumns, enablePagination, enableColumnPinning, initialPageIndex, initialPageSize, pageSize, selectMode = 'page', onSelectionChange, handleColumnFilterStateChange, onDataStateChange, onFetchData, onDataChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, exportController, setExportController, isExporting, dataMode = 'client', } = props;
|
|
9
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
10
|
+
table: {
|
|
11
|
+
getTable: () => table,
|
|
12
|
+
},
|
|
13
|
+
columnVisibility: {
|
|
14
|
+
showColumn: (columnId) => {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility(true);
|
|
17
|
+
},
|
|
18
|
+
hideColumn: (columnId) => {
|
|
19
|
+
var _a;
|
|
20
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility(false);
|
|
21
|
+
},
|
|
22
|
+
toggleColumn: (columnId) => {
|
|
23
|
+
var _a;
|
|
24
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.toggleVisibility();
|
|
25
|
+
},
|
|
26
|
+
showAllColumns: () => {
|
|
27
|
+
table.toggleAllColumnsVisible(true);
|
|
28
|
+
},
|
|
29
|
+
hideAllColumns: () => {
|
|
30
|
+
table.toggleAllColumnsVisible(false);
|
|
31
|
+
},
|
|
32
|
+
resetColumnVisibility: () => {
|
|
33
|
+
table.resetColumnVisibility();
|
|
34
|
+
},
|
|
35
|
+
},
|
|
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
|
+
columnPinning: {
|
|
64
|
+
pinColumnLeft: (columnId) => {
|
|
65
|
+
const currentPinning = table.getState().columnPinning;
|
|
66
|
+
const newPinning = Object.assign({}, currentPinning);
|
|
67
|
+
newPinning.right = (newPinning.right || []).filter(id => id !== columnId);
|
|
68
|
+
newPinning.left = [...(newPinning.left || []).filter(id => id !== columnId), columnId];
|
|
69
|
+
table.setColumnPinning(newPinning);
|
|
70
|
+
},
|
|
71
|
+
pinColumnRight: (columnId) => {
|
|
72
|
+
const currentPinning = table.getState().columnPinning;
|
|
73
|
+
const newPinning = Object.assign({}, currentPinning);
|
|
74
|
+
newPinning.left = (newPinning.left || []).filter(id => id !== columnId);
|
|
75
|
+
newPinning.right = [...(newPinning.right || []).filter(id => id !== columnId), columnId];
|
|
76
|
+
table.setColumnPinning(newPinning);
|
|
77
|
+
},
|
|
78
|
+
unpinColumn: (columnId) => {
|
|
79
|
+
const currentPinning = table.getState().columnPinning;
|
|
80
|
+
const newPinning = {
|
|
81
|
+
left: (currentPinning.left || []).filter(id => id !== columnId),
|
|
82
|
+
right: (currentPinning.right || []).filter(id => id !== columnId),
|
|
83
|
+
};
|
|
84
|
+
table.setColumnPinning(newPinning);
|
|
85
|
+
},
|
|
86
|
+
setPinning: (pinning) => {
|
|
87
|
+
table.setColumnPinning(pinning);
|
|
88
|
+
},
|
|
89
|
+
resetColumnPinning: () => {
|
|
90
|
+
table.setColumnPinning(table.initialState.columnPinning);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
columnResizing: {
|
|
94
|
+
resizeColumn: (columnId, width) => {
|
|
95
|
+
const currentSizing = table.getState().columnSizing;
|
|
96
|
+
table.setColumnSizing(Object.assign(Object.assign({}, currentSizing), { [columnId]: width }));
|
|
97
|
+
},
|
|
98
|
+
autoSizeColumn: (columnId) => {
|
|
99
|
+
var _a;
|
|
100
|
+
(_a = table.getColumn(columnId)) === null || _a === void 0 ? void 0 : _a.resetSize();
|
|
101
|
+
},
|
|
102
|
+
autoSizeAllColumns: () => {
|
|
103
|
+
table.resetColumnSizing();
|
|
104
|
+
},
|
|
105
|
+
resetColumnSizing: () => {
|
|
106
|
+
table.resetColumnSizing();
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
filtering: {
|
|
110
|
+
setGlobalFilter: (filter) => {
|
|
111
|
+
table.setGlobalFilter(filter);
|
|
112
|
+
},
|
|
113
|
+
clearGlobalFilter: () => {
|
|
114
|
+
table.setGlobalFilter('');
|
|
115
|
+
},
|
|
116
|
+
setCustomColumnFilters: (filters) => {
|
|
117
|
+
handleColumnFilterStateChange(filters);
|
|
118
|
+
},
|
|
119
|
+
addColumnFilter: (columnId, operator, value) => {
|
|
120
|
+
const newFilter = {
|
|
121
|
+
id: `filter_${Date.now()}`,
|
|
122
|
+
columnId,
|
|
123
|
+
operator,
|
|
124
|
+
value,
|
|
125
|
+
};
|
|
126
|
+
const currentFilters = customColumnsFilter.filters || [];
|
|
127
|
+
const newFilters = [...currentFilters, newFilter];
|
|
128
|
+
handleColumnFilterStateChange({
|
|
129
|
+
filters: newFilters,
|
|
130
|
+
logic: customColumnsFilter.logic,
|
|
131
|
+
pendingFilters: customColumnsFilter.pendingFilters || [],
|
|
132
|
+
pendingLogic: customColumnsFilter.pendingLogic || 'AND',
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
removeColumnFilter: (filterId) => {
|
|
136
|
+
const currentFilters = customColumnsFilter.filters || [];
|
|
137
|
+
const newFilters = currentFilters.filter((f) => f.id !== filterId);
|
|
138
|
+
handleColumnFilterStateChange({
|
|
139
|
+
filters: newFilters,
|
|
140
|
+
logic: customColumnsFilter.logic,
|
|
141
|
+
pendingFilters: customColumnsFilter.pendingFilters || [],
|
|
142
|
+
pendingLogic: customColumnsFilter.pendingLogic || 'AND',
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
clearAllFilters: () => {
|
|
146
|
+
table.setGlobalFilter('');
|
|
147
|
+
handleColumnFilterStateChange({
|
|
148
|
+
filters: [],
|
|
149
|
+
logic: 'AND',
|
|
150
|
+
pendingFilters: [],
|
|
151
|
+
pendingLogic: 'AND',
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
resetFilters: () => {
|
|
155
|
+
table.resetGlobalFilter();
|
|
156
|
+
handleColumnFilterStateChange({
|
|
157
|
+
filters: [],
|
|
158
|
+
logic: 'AND',
|
|
159
|
+
pendingFilters: [],
|
|
160
|
+
pendingLogic: 'AND',
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
sorting: {
|
|
165
|
+
setSorting: (sortingState) => {
|
|
166
|
+
table.setSorting(sortingState);
|
|
167
|
+
},
|
|
168
|
+
sortColumn: (columnId, direction) => {
|
|
169
|
+
const column = table.getColumn(columnId);
|
|
170
|
+
if (!column)
|
|
171
|
+
return;
|
|
172
|
+
if (direction === false) {
|
|
173
|
+
column.clearSorting();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
column.toggleSorting(direction === 'desc');
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
clearSorting: () => {
|
|
180
|
+
table.resetSorting();
|
|
181
|
+
},
|
|
182
|
+
resetSorting: () => {
|
|
183
|
+
table.resetSorting();
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
pagination: {
|
|
187
|
+
goToPage: (pageIndex) => {
|
|
188
|
+
table.setPageIndex(pageIndex);
|
|
189
|
+
},
|
|
190
|
+
nextPage: () => {
|
|
191
|
+
table.nextPage();
|
|
192
|
+
},
|
|
193
|
+
previousPage: () => {
|
|
194
|
+
table.previousPage();
|
|
195
|
+
},
|
|
196
|
+
setPageSize: (pageSize) => {
|
|
197
|
+
table.setPageSize(pageSize);
|
|
198
|
+
},
|
|
199
|
+
goToFirstPage: () => {
|
|
200
|
+
table.setPageIndex(0);
|
|
201
|
+
},
|
|
202
|
+
goToLastPage: () => {
|
|
203
|
+
const pageCount = table.getPageCount();
|
|
204
|
+
if (pageCount > 0) {
|
|
205
|
+
table.setPageIndex(pageCount - 1);
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
selection: {
|
|
210
|
+
selectRow: (rowId) => { var _a; return (_a = table.selectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
211
|
+
deselectRow: (rowId) => { var _a; return (_a = table.deselectRow) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
212
|
+
toggleRowSelection: (rowId) => { var _a; return (_a = table.toggleRowSelected) === null || _a === void 0 ? void 0 : _a.call(table, rowId); },
|
|
213
|
+
selectAll: () => { var _a; return (_a = table.selectAll) === null || _a === void 0 ? void 0 : _a.call(table); },
|
|
214
|
+
deselectAll: () => { var _a; return (_a = table.deselectAll) === null || _a === void 0 ? void 0 : _a.call(table); },
|
|
215
|
+
toggleSelectAll: () => { var _a; return (_a = table.toggleAllRowsSelected) === null || _a === void 0 ? void 0 : _a.call(table); },
|
|
216
|
+
getSelectionState: () => { var _a; return ((_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table)) || { ids: [], type: 'include' }; },
|
|
217
|
+
getSelectedRows: () => table.getSelectedRows(),
|
|
218
|
+
getSelectedCount: () => table.getSelectedCount(),
|
|
219
|
+
isRowSelected: (rowId) => table.getIsRowSelected(rowId) || false,
|
|
220
|
+
},
|
|
221
|
+
data: {
|
|
222
|
+
refresh: () => {
|
|
223
|
+
const currentFilters = {
|
|
224
|
+
globalFilter,
|
|
225
|
+
customColumnsFilter: customColumnsFilter,
|
|
226
|
+
sorting,
|
|
227
|
+
pagination,
|
|
228
|
+
};
|
|
229
|
+
if (onDataStateChange) {
|
|
230
|
+
const currentState = Object.assign(Object.assign({}, currentFilters), { columnOrder,
|
|
231
|
+
columnPinning });
|
|
232
|
+
onDataStateChange(currentState);
|
|
233
|
+
}
|
|
234
|
+
if (onFetchData) {
|
|
235
|
+
onFetchData(currentFilters);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
reload: () => {
|
|
239
|
+
const currentFilters = {
|
|
240
|
+
globalFilter,
|
|
241
|
+
customColumnsFilter: customColumnsFilter,
|
|
242
|
+
sorting,
|
|
243
|
+
pagination,
|
|
244
|
+
};
|
|
245
|
+
if (onDataStateChange) {
|
|
246
|
+
const currentState = Object.assign(Object.assign({}, currentFilters), { columnOrder,
|
|
247
|
+
columnPinning });
|
|
248
|
+
onDataStateChange(Object.assign({}, currentState));
|
|
249
|
+
}
|
|
250
|
+
if (onFetchData) {
|
|
251
|
+
onFetchData(Object.assign({}, currentFilters));
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
getAllData: () => {
|
|
255
|
+
return [...data];
|
|
256
|
+
},
|
|
257
|
+
getRowData: (rowId) => {
|
|
258
|
+
return data.find(row => String(row[idKey]) === rowId);
|
|
259
|
+
},
|
|
260
|
+
getRowByIndex: (index) => {
|
|
261
|
+
return data[index];
|
|
262
|
+
},
|
|
263
|
+
updateRow: (rowId, updates) => {
|
|
264
|
+
const newData = data.map(row => String(row[idKey]) === rowId
|
|
265
|
+
? Object.assign(Object.assign({}, row), updates) : row);
|
|
266
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
267
|
+
},
|
|
268
|
+
updateRowByIndex: (index, updates) => {
|
|
269
|
+
const newData = [...data];
|
|
270
|
+
if (newData[index]) {
|
|
271
|
+
newData[index] = Object.assign(Object.assign({}, newData[index]), updates);
|
|
272
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
insertRow: (newRow, index) => {
|
|
276
|
+
const newData = [...data];
|
|
277
|
+
if (index !== undefined) {
|
|
278
|
+
newData.splice(index, 0, newRow);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
newData.push(newRow);
|
|
282
|
+
}
|
|
283
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
284
|
+
},
|
|
285
|
+
deleteRow: (rowId) => {
|
|
286
|
+
const newData = data.filter(row => String(row[idKey]) !== rowId);
|
|
287
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
288
|
+
},
|
|
289
|
+
deleteRowByIndex: (index) => {
|
|
290
|
+
const newData = [...data];
|
|
291
|
+
newData.splice(index, 1);
|
|
292
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
293
|
+
},
|
|
294
|
+
deleteSelectedRows: () => {
|
|
295
|
+
const selectedRowIds = Object.keys(table.getState().rowSelection)
|
|
296
|
+
.filter(key => table.getState().rowSelection[key]);
|
|
297
|
+
const newData = data.filter(row => !selectedRowIds.includes(String(row[idKey])));
|
|
298
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
299
|
+
table.resetRowSelection();
|
|
300
|
+
},
|
|
301
|
+
replaceAllData: (newData) => {
|
|
302
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
303
|
+
},
|
|
304
|
+
updateMultipleRows: (updates) => {
|
|
305
|
+
const updateMap = new Map(updates.map(u => [u.rowId, u.data]));
|
|
306
|
+
const newData = data.map(row => {
|
|
307
|
+
const rowId = String(row[idKey]);
|
|
308
|
+
const updateData = updateMap.get(rowId);
|
|
309
|
+
return updateData ? Object.assign(Object.assign({}, row), updateData) : row;
|
|
310
|
+
});
|
|
311
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
312
|
+
},
|
|
313
|
+
insertMultipleRows: (newRows, startIndex) => {
|
|
314
|
+
const newData = [...data];
|
|
315
|
+
if (startIndex !== undefined) {
|
|
316
|
+
newData.splice(startIndex, 0, ...newRows);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
newData.push(...newRows);
|
|
320
|
+
}
|
|
321
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
322
|
+
},
|
|
323
|
+
deleteMultipleRows: (rowIds) => {
|
|
324
|
+
const idsToDelete = new Set(rowIds);
|
|
325
|
+
const newData = data.filter(row => !idsToDelete.has(String(row[idKey])));
|
|
326
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
327
|
+
},
|
|
328
|
+
updateField: (rowId, fieldName, value) => {
|
|
329
|
+
const newData = data.map(row => String(row[idKey]) === rowId
|
|
330
|
+
? Object.assign(Object.assign({}, row), { [fieldName]: value }) : row);
|
|
331
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
332
|
+
},
|
|
333
|
+
updateFieldByIndex: (index, fieldName, value) => {
|
|
334
|
+
const newData = [...data];
|
|
335
|
+
if (newData[index]) {
|
|
336
|
+
newData[index] = Object.assign(Object.assign({}, newData[index]), { [fieldName]: value });
|
|
337
|
+
onDataChange === null || onDataChange === void 0 ? void 0 : onDataChange(newData);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
findRows: (predicate) => {
|
|
341
|
+
return data.filter(predicate);
|
|
342
|
+
},
|
|
343
|
+
findRowIndex: (predicate) => {
|
|
344
|
+
return data.findIndex(predicate);
|
|
345
|
+
},
|
|
346
|
+
getDataCount: () => {
|
|
347
|
+
return data.length;
|
|
348
|
+
},
|
|
349
|
+
getFilteredDataCount: () => {
|
|
350
|
+
return table.getFilteredRowModel().rows.length;
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
layout: {
|
|
354
|
+
resetLayout: () => {
|
|
355
|
+
table.resetColumnSizing();
|
|
356
|
+
table.resetColumnVisibility();
|
|
357
|
+
table.resetSorting();
|
|
358
|
+
table.resetGlobalFilter();
|
|
359
|
+
},
|
|
360
|
+
resetAll: () => {
|
|
361
|
+
table.resetColumnSizing();
|
|
362
|
+
table.resetColumnVisibility();
|
|
363
|
+
table.resetSorting();
|
|
364
|
+
table.resetGlobalFilter();
|
|
365
|
+
table.resetColumnOrder();
|
|
366
|
+
table.resetExpanded();
|
|
367
|
+
table.resetRowSelection();
|
|
368
|
+
table.resetColumnPinning();
|
|
369
|
+
handleColumnFilterStateChange({
|
|
370
|
+
filters: [],
|
|
371
|
+
logic: 'AND',
|
|
372
|
+
pendingFilters: [],
|
|
373
|
+
pendingLogic: 'AND',
|
|
374
|
+
});
|
|
375
|
+
if (enablePagination) {
|
|
376
|
+
table.setPageIndex(initialPageIndex);
|
|
377
|
+
table.setPageSize(initialPageSize || pageSize);
|
|
378
|
+
}
|
|
379
|
+
if (enableColumnPinning) {
|
|
380
|
+
table.setColumnPinning({
|
|
381
|
+
left: [],
|
|
382
|
+
right: [],
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
saveLayout: () => {
|
|
387
|
+
return {
|
|
388
|
+
columnVisibility: table.getState().columnVisibility,
|
|
389
|
+
columnSizing: table.getState().columnSizing,
|
|
390
|
+
columnOrder: table.getState().columnOrder,
|
|
391
|
+
columnPinning: table.getState().columnPinning,
|
|
392
|
+
sorting: table.getState().sorting,
|
|
393
|
+
pagination: table.getState().pagination,
|
|
394
|
+
globalFilter: table.getState().globalFilter,
|
|
395
|
+
customColumnsFilter: customColumnsFilter,
|
|
396
|
+
};
|
|
397
|
+
},
|
|
398
|
+
restoreLayout: (layout) => {
|
|
399
|
+
if (layout.columnVisibility) {
|
|
400
|
+
table.setColumnVisibility(layout.columnVisibility);
|
|
401
|
+
}
|
|
402
|
+
if (layout.columnSizing) {
|
|
403
|
+
table.setColumnSizing(layout.columnSizing);
|
|
404
|
+
}
|
|
405
|
+
if (layout.columnOrder) {
|
|
406
|
+
table.setColumnOrder(layout.columnOrder);
|
|
407
|
+
}
|
|
408
|
+
if (layout.columnPinning) {
|
|
409
|
+
table.setColumnPinning(layout.columnPinning);
|
|
410
|
+
}
|
|
411
|
+
if (layout.sorting) {
|
|
412
|
+
table.setSorting(layout.sorting);
|
|
413
|
+
}
|
|
414
|
+
if (layout.pagination && enablePagination) {
|
|
415
|
+
table.setPagination(layout.pagination);
|
|
416
|
+
}
|
|
417
|
+
if (layout.globalFilter !== undefined) {
|
|
418
|
+
table.setGlobalFilter(layout.globalFilter);
|
|
419
|
+
}
|
|
420
|
+
if (layout.customColumnsFilter) {
|
|
421
|
+
handleColumnFilterStateChange(layout.customColumnsFilter);
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
state: {
|
|
426
|
+
getTableState: () => {
|
|
427
|
+
return table.getState();
|
|
428
|
+
},
|
|
429
|
+
getCurrentFilters: () => {
|
|
430
|
+
return customColumnsFilter;
|
|
431
|
+
},
|
|
432
|
+
getCurrentSorting: () => {
|
|
433
|
+
return table.getState().sorting;
|
|
434
|
+
},
|
|
435
|
+
getCurrentPagination: () => {
|
|
436
|
+
return table.getState().pagination;
|
|
437
|
+
},
|
|
438
|
+
getCurrentSelection: () => {
|
|
439
|
+
return Object.keys(table.getState().rowSelection)
|
|
440
|
+
.filter(key => table.getState().rowSelection[key]);
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
export: {
|
|
444
|
+
exportCSV: (...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (options = {}) {
|
|
445
|
+
var _a;
|
|
446
|
+
const { filename = exportFilename, } = options;
|
|
447
|
+
try {
|
|
448
|
+
const controller = new AbortController();
|
|
449
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
450
|
+
if (dataMode === 'server' && onServerExport) {
|
|
451
|
+
const currentFilters = {
|
|
452
|
+
globalFilter,
|
|
453
|
+
customColumnsFilter,
|
|
454
|
+
sorting,
|
|
455
|
+
pagination,
|
|
456
|
+
columnOrder,
|
|
457
|
+
columnPinning,
|
|
458
|
+
};
|
|
459
|
+
yield (0, export_utils_1.exportServerData)(table, {
|
|
460
|
+
format: 'csv',
|
|
461
|
+
filename,
|
|
462
|
+
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
463
|
+
currentFilters,
|
|
464
|
+
selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
|
|
465
|
+
onProgress: onExportProgress,
|
|
466
|
+
onComplete: onExportComplete,
|
|
467
|
+
onError: onExportError,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
yield (0, export_utils_1.exportClientData)(table, {
|
|
472
|
+
format: 'csv',
|
|
473
|
+
filename,
|
|
474
|
+
onProgress: onExportProgress,
|
|
475
|
+
onComplete: onExportComplete,
|
|
476
|
+
onError: onExportError,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
catch (error) {
|
|
481
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
482
|
+
message: error.message || 'Export failed',
|
|
483
|
+
code: 'EXPORT_ERROR',
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
finally {
|
|
487
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
488
|
+
}
|
|
489
|
+
}),
|
|
490
|
+
exportExcel: (...args_1) => tslib_1.__awaiter(this, [...args_1], void 0, function* (options = {}) {
|
|
491
|
+
var _a;
|
|
492
|
+
const { filename = exportFilename } = options;
|
|
493
|
+
try {
|
|
494
|
+
const controller = new AbortController();
|
|
495
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
496
|
+
if (dataMode === 'server' && onServerExport) {
|
|
497
|
+
const currentFilters = {
|
|
498
|
+
globalFilter,
|
|
499
|
+
customColumnsFilter,
|
|
500
|
+
sorting,
|
|
501
|
+
pagination,
|
|
502
|
+
columnOrder,
|
|
503
|
+
columnPinning,
|
|
504
|
+
};
|
|
505
|
+
yield (0, export_utils_1.exportServerData)(table, {
|
|
506
|
+
format: 'excel',
|
|
507
|
+
filename,
|
|
508
|
+
fetchData: (filters, selection) => onServerExport(filters, selection),
|
|
509
|
+
currentFilters,
|
|
510
|
+
selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
|
|
511
|
+
onProgress: onExportProgress,
|
|
512
|
+
onComplete: onExportComplete,
|
|
513
|
+
onError: onExportError,
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
else {
|
|
517
|
+
yield (0, export_utils_1.exportClientData)(table, {
|
|
518
|
+
format: 'excel',
|
|
519
|
+
filename,
|
|
520
|
+
onProgress: onExportProgress,
|
|
521
|
+
onComplete: onExportComplete,
|
|
522
|
+
onError: onExportError,
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
catch (error) {
|
|
527
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
528
|
+
message: error.message || 'Export failed',
|
|
529
|
+
code: 'EXPORT_ERROR',
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
finally {
|
|
533
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
534
|
+
}
|
|
535
|
+
}),
|
|
536
|
+
exportServerData: (options) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
537
|
+
var _a;
|
|
538
|
+
const { format, filename = exportFilename, fetchData = onServerExport, } = options;
|
|
539
|
+
if (!fetchData) {
|
|
540
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
541
|
+
message: 'No server export function provided',
|
|
542
|
+
code: 'NO_SERVER_EXPORT',
|
|
543
|
+
});
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
try {
|
|
547
|
+
const controller = new AbortController();
|
|
548
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(controller);
|
|
549
|
+
const currentFilters = {
|
|
550
|
+
globalFilter,
|
|
551
|
+
customColumnsFilter,
|
|
552
|
+
sorting,
|
|
553
|
+
pagination,
|
|
554
|
+
columnOrder,
|
|
555
|
+
columnPinning,
|
|
556
|
+
};
|
|
557
|
+
yield (0, export_utils_1.exportServerData)(table, {
|
|
558
|
+
format,
|
|
559
|
+
filename,
|
|
560
|
+
fetchData: (filters, selection) => fetchData(filters, selection),
|
|
561
|
+
currentFilters,
|
|
562
|
+
selection: (_a = table.getSelectionState) === null || _a === void 0 ? void 0 : _a.call(table),
|
|
563
|
+
onProgress: onExportProgress,
|
|
564
|
+
onComplete: onExportComplete,
|
|
565
|
+
onError: onExportError,
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
catch (error) {
|
|
569
|
+
onExportError === null || onExportError === void 0 ? void 0 : onExportError({
|
|
570
|
+
message: error.message || 'Export failed',
|
|
571
|
+
code: 'EXPORT_ERROR',
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
finally {
|
|
575
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
576
|
+
}
|
|
577
|
+
}),
|
|
578
|
+
isExporting: () => isExporting || false,
|
|
579
|
+
cancelExport: () => {
|
|
580
|
+
exportController === null || exportController === void 0 ? void 0 : exportController.abort();
|
|
581
|
+
setExportController === null || setExportController === void 0 ? void 0 : setExportController(null);
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
}), [
|
|
585
|
+
table,
|
|
586
|
+
enhancedColumns,
|
|
587
|
+
handleColumnFilterStateChange,
|
|
588
|
+
customColumnsFilter,
|
|
589
|
+
data,
|
|
590
|
+
idKey,
|
|
591
|
+
onDataStateChange,
|
|
592
|
+
onFetchData,
|
|
593
|
+
globalFilter,
|
|
594
|
+
sorting,
|
|
595
|
+
pagination,
|
|
596
|
+
columnOrder,
|
|
597
|
+
columnPinning,
|
|
598
|
+
onDataChange,
|
|
599
|
+
enableColumnPinning,
|
|
600
|
+
enablePagination,
|
|
601
|
+
initialPageIndex,
|
|
602
|
+
initialPageSize,
|
|
603
|
+
pageSize,
|
|
604
|
+
exportFilename,
|
|
605
|
+
onExportProgress,
|
|
606
|
+
onExportComplete,
|
|
607
|
+
onExportError,
|
|
608
|
+
onServerExport,
|
|
609
|
+
exportController,
|
|
610
|
+
setExportController,
|
|
611
|
+
isExporting,
|
|
612
|
+
dataMode,
|
|
613
|
+
selectMode,
|
|
614
|
+
onSelectionChange,
|
|
615
|
+
]);
|
|
616
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AddIcon = AddIcon;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
function AddIcon(props) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.SvgIcon, Object.assign({}, props, { viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("path", { d: "M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" }), (0, jsx_runtime_1.jsx)("circle", { cx: "12", cy: "12", r: "9", fill: "none", stroke: "currentColor", strokeWidth: "0.5", opacity: "0.3" })] })));
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CsvIcon = CsvIcon;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
function CsvIcon(props) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.SvgIcon, Object.assign({}, props, { viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("path", { d: "M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" }), (0, jsx_runtime_1.jsx)("path", { d: "M7,12.5A0.5,0.5 0 0,1 7.5,12H8.5A0.5,0.5 0 0,1 9,12.5V13.5A0.5,0.5 0 0,1 8.5,14H7.5A0.5,0.5 0 0,1 7,13.5M10.5,12.5A0.5,0.5 0 0,1 11,12H12A0.5,0.5 0 0,1 12.5,12.5V13.5A0.5,0.5 0 0,1 12,14H11A0.5,0.5 0 0,1 10.5,13.5M14,12.5A0.5,0.5 0 0,1 14.5,12H15.5A0.5,0.5 0 0,1 16,12.5V13.5A0.5,0.5 0 0,1 15.5,14H14.5A0.5,0.5 0 0,1 14,13.5" })] })));
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteIcon = DeleteIcon;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
function DeleteIcon(props) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.SvgIcon, Object.assign({}, props, { viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("path", { d: "M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" }), (0, jsx_runtime_1.jsx)("rect", { x: "9", y: "8", width: "2", height: "9", fill: "currentColor", opacity: "0.6" }), (0, jsx_runtime_1.jsx)("rect", { x: "13", y: "8", width: "2", height: "9", fill: "currentColor", opacity: "0.6" })] })));
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExcelIcon = ExcelIcon;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
function ExcelIcon(props) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.SvgIcon, Object.assign({}, props, { viewBox: "0 0 24 24", children: [(0, jsx_runtime_1.jsx)("path", { d: "M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" }), (0, jsx_runtime_1.jsx)("path", { d: "M11.5,15L9.75,12.5L11.5,10H10L8.75,11.5L7.5,10H6L7.75,12.5L6,15H7.5L8.75,13.5L10,15H11.5M15,10V12H17V10H15M15,14V16H17V14H15Z" })] })));
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { UnpinIcon } from './unpin-icon';
|
|
2
|
+
export { AddIcon } from './add-icon';
|
|
3
|
+
export { DeleteIcon } from './delete-icon';
|
|
4
|
+
export { ViewCompactIcon } from './view-compact-icon';
|
|
5
|
+
export { ViewComfortableIcon } from './view-comfortable-icon';
|
|
6
|
+
export { CsvIcon } from './csv-icon';
|
|
7
|
+
export { ExcelIcon } from './excel-icon';
|