@ackplus/react-tanstack-data-table 1.0.19-beta-0.9 → 1.0.19-beta-0.12
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 +4 -4
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +3 -1
- package/src/lib/components/table/data-table.d.ts +2 -1
- package/src/lib/components/table/data-table.js +141 -121
- package/src/lib/components/table/data-table.types.d.ts +9 -9
- package/src/lib/components/toolbar/bulk-actions-toolbar.d.ts +1 -1
- package/src/lib/components/toolbar/column-filter-control.d.ts +1 -0
- package/src/lib/components/toolbar/{column-custom-filter-control.js → column-filter-control.js} +22 -20
- package/src/lib/components/toolbar/data-table-toolbar.js +2 -2
- package/src/lib/components/toolbar/index.d.ts +1 -0
- package/src/lib/components/toolbar/index.js +3 -1
- package/src/lib/components/toolbar/table-export-control.d.ts +4 -4
- package/src/lib/components/toolbar/table-export-control.js +18 -6
- package/src/lib/contexts/data-table-context.d.ts +8 -8
- package/src/lib/contexts/data-table-context.js +5 -5
- package/src/lib/examples/index.d.ts +1 -0
- package/src/lib/examples/index.js +3 -1
- package/src/lib/examples/server-side-fetching-example.d.ts +1 -0
- package/src/lib/examples/server-side-fetching-example.js +250 -0
- package/src/lib/examples/server-side-test.d.ts +1 -0
- package/src/lib/examples/server-side-test.js +9 -0
- package/src/lib/features/{custom-column-filter.feature.d.ts → column-filter.feature.d.ts} +14 -14
- package/src/lib/features/{custom-column-filter.feature.js → column-filter.feature.js} +51 -26
- package/src/lib/features/index.d.ts +2 -2
- package/src/lib/features/index.js +6 -6
- package/src/lib/features/{custom-selection.feature.d.ts → selection.feature.d.ts} +8 -8
- package/src/lib/features/{custom-selection.feature.js → selection.feature.js} +22 -10
- package/src/lib/hooks/use-data-table-api.d.ts +6 -6
- package/src/lib/hooks/use-data-table-api.js +20 -20
- package/src/lib/types/data-table-api.d.ts +4 -4
- package/src/lib/types/table.types.d.ts +4 -4
- package/src/lib/utils/column-helpers.d.ts +1 -2
- package/src/lib/utils/column-helpers.js +3 -2
- package/src/lib/utils/export-utils.d.ts +4 -4
- package/src/lib/utils/export-utils.js +47 -24
- package/src/lib/components/toolbar/column-custom-filter-control.d.ts +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Table } from '@tanstack/react-table';
|
|
2
|
-
import { SelectionState } from '../features
|
|
2
|
+
import { SelectionState } from '../features';
|
|
3
3
|
export interface ExportOptions {
|
|
4
4
|
format: 'csv' | 'excel';
|
|
5
5
|
filename: string;
|
|
6
6
|
onProgress?: (progress: {
|
|
7
|
-
processedRows
|
|
8
|
-
totalRows
|
|
9
|
-
percentage
|
|
7
|
+
processedRows?: number;
|
|
8
|
+
totalRows?: number;
|
|
9
|
+
percentage?: number;
|
|
10
10
|
}) => void;
|
|
11
11
|
onComplete?: (result: {
|
|
12
12
|
success: boolean;
|
|
@@ -19,9 +19,11 @@ function exportClientData(table, options) {
|
|
|
19
19
|
});
|
|
20
20
|
const rowData = {};
|
|
21
21
|
row.getVisibleCells().forEach(cell => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const columnDef = cell.column.columnDef;
|
|
23
|
+
if (columnDef.hideInExport === true) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const header = typeof columnDef.header === 'string' ? columnDef.header : cell.column.id;
|
|
25
27
|
rowData[header] = cell.getValue() || '';
|
|
26
28
|
});
|
|
27
29
|
return rowData;
|
|
@@ -46,32 +48,53 @@ function exportServerData(table, options) {
|
|
|
46
48
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
47
49
|
const { format, filename, fetchData, currentFilters, selection, onProgress, onComplete, onError } = options;
|
|
48
50
|
try {
|
|
49
|
-
onProgress === null || onProgress === void 0 ? void 0 : onProgress({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
percentage: 0,
|
|
53
|
-
});
|
|
54
|
-
const { data } = yield fetchData(currentFilters, selection);
|
|
55
|
-
if (!data || !Array.isArray(data)) {
|
|
51
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress({});
|
|
52
|
+
const initialResponse = yield fetchData(Object.assign(Object.assign({}, currentFilters), { pagination: { pageIndex: 0, pageSize: 1 } }), selection);
|
|
53
|
+
if (!initialResponse || !initialResponse.data || !Array.isArray(initialResponse.data)) {
|
|
56
54
|
throw new Error('Invalid data received from server');
|
|
57
55
|
}
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
56
|
+
const totalRows = initialResponse.total || initialResponse.data.length;
|
|
57
|
+
const CHUNK_SIZE = 1000;
|
|
58
|
+
const needsChunking = totalRows > CHUNK_SIZE;
|
|
59
|
+
let allData = [];
|
|
60
|
+
if (needsChunking) {
|
|
61
|
+
const totalPages = Math.ceil(totalRows / CHUNK_SIZE);
|
|
62
|
+
for (let page = 1; page <= totalPages; page++) {
|
|
63
|
+
const chunkFilters = Object.assign(Object.assign({}, currentFilters), { pagination: {
|
|
64
|
+
pageIndex: page - 1,
|
|
65
|
+
pageSize: CHUNK_SIZE,
|
|
66
|
+
} });
|
|
67
|
+
const chunkResponse = yield fetchData(chunkFilters, selection);
|
|
68
|
+
if (!chunkResponse || !chunkResponse.data || !Array.isArray(chunkResponse.data)) {
|
|
69
|
+
throw new Error(`Failed to fetch chunk ${page}`);
|
|
70
|
+
}
|
|
71
|
+
allData = [...allData, ...chunkResponse.data];
|
|
72
|
+
if (page < totalPages) {
|
|
73
|
+
yield new Promise(resolve => setTimeout(resolve, 100));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
allData = initialResponse.data;
|
|
79
|
+
}
|
|
80
|
+
const visibleColumns = table.getVisibleLeafColumns().filter(col => {
|
|
81
|
+
const columnDef = col.columnDef;
|
|
82
|
+
return col.getIsVisible() && columnDef.hideInExport !== true;
|
|
83
|
+
});
|
|
84
|
+
const exportData = [];
|
|
85
|
+
for (let index = 0; index < allData.length; index++) {
|
|
86
|
+
const rowData = allData[index];
|
|
65
87
|
const exportRow = {};
|
|
66
88
|
visibleColumns.forEach(column => {
|
|
89
|
+
var _a;
|
|
67
90
|
const columnId = column.id;
|
|
68
|
-
const
|
|
69
|
-
|
|
91
|
+
const columnDef = column.columnDef;
|
|
92
|
+
const header = typeof columnDef.header === 'string'
|
|
93
|
+
? columnDef.header
|
|
70
94
|
: columnId;
|
|
71
95
|
let value = rowData[columnId];
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
value = columnDef.accessorFn(rowData);
|
|
96
|
+
if (column.accessorFn && typeof column.accessorFn === 'function') {
|
|
97
|
+
value = ((_a = (column.accessorFn(rowData, index) || '')) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
75
98
|
}
|
|
76
99
|
if (value === null || value === undefined) {
|
|
77
100
|
value = '';
|
|
@@ -84,8 +107,8 @@ function exportServerData(table, options) {
|
|
|
84
107
|
}
|
|
85
108
|
exportRow[header] = value;
|
|
86
109
|
});
|
|
87
|
-
|
|
88
|
-
}
|
|
110
|
+
exportData.push(exportRow);
|
|
111
|
+
}
|
|
89
112
|
yield exportToFile(exportData, format, filename);
|
|
90
113
|
onComplete === null || onComplete === void 0 ? void 0 : onComplete({
|
|
91
114
|
success: true,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function ColumnCustomFilterControl(): import("react/jsx-runtime").JSX.Element;
|