beautiful-grid 1.0.12 → 1.0.13
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/cjs/BGrid.js +2 -1
- package/cjs/components/Table.js +36 -1
- package/cjs/utils/exportCsv.js +129 -0
- package/cjs/utils/exportData.js +230 -0
- package/cjs/utils/exportExcel.js +317 -0
- package/cjs/utils/index.js +3 -0
- package/esm/BGrid.js +2 -1
- package/esm/components/Table.js +35 -3
- package/esm/utils/exportCsv.js +97 -0
- package/esm/utils/exportData.js +154 -0
- package/esm/utils/exportExcel.js +246 -0
- package/esm/utils/index.js +3 -0
- package/package.json +1 -1
- package/types/components/Table.d.ts +2 -1
- package/types/types.d.ts +73 -2
- package/types/utils/exportCsv.d.ts +5 -0
- package/types/utils/exportData.d.ts +16 -0
- package/types/utils/exportExcel.d.ts +5 -0
- package/types/utils/index.d.ts +3 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
function makeCrc32Table() {
|
|
2
|
+
const table = new Uint32Array(256);
|
|
3
|
+
for (let i = 0; i < 256; i++) {
|
|
4
|
+
let c = i;
|
|
5
|
+
for (let k = 0; k < 8; k++) {
|
|
6
|
+
c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1);
|
|
7
|
+
}
|
|
8
|
+
table[i] = c;
|
|
9
|
+
}
|
|
10
|
+
return table;
|
|
11
|
+
}
|
|
12
|
+
const crcTable = makeCrc32Table();
|
|
13
|
+
function calculateCrc32(bytes) {
|
|
14
|
+
let crc = 0xffffffff;
|
|
15
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
16
|
+
crc = (crc >>> 8) ^ crcTable[(crc ^ bytes[i]) & 0xff];
|
|
17
|
+
}
|
|
18
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
19
|
+
}
|
|
20
|
+
export function escapeXml(value) {
|
|
21
|
+
return value
|
|
22
|
+
.replace(/&/g, '&')
|
|
23
|
+
.replace(/</g, '<')
|
|
24
|
+
.replace(/>/g, '>')
|
|
25
|
+
.replace(/"/g, '"')
|
|
26
|
+
.replace(/'/g, ''')
|
|
27
|
+
.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, '');
|
|
28
|
+
}
|
|
29
|
+
export function colIndexToExcelColumn(colIndex) {
|
|
30
|
+
let name = '';
|
|
31
|
+
let n = colIndex;
|
|
32
|
+
while (n >= 0) {
|
|
33
|
+
name = String.fromCharCode((n % 26) + 65) + name;
|
|
34
|
+
n = Math.floor(n / 26) - 1;
|
|
35
|
+
}
|
|
36
|
+
return name;
|
|
37
|
+
}
|
|
38
|
+
function createZipArchive(files) {
|
|
39
|
+
const encoder = new TextEncoder();
|
|
40
|
+
const fileEntries = [];
|
|
41
|
+
let offset = 0;
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const nameBytes = encoder.encode(file.name);
|
|
44
|
+
const dataBytes = typeof file.data === 'string' ? encoder.encode(file.data) : file.data;
|
|
45
|
+
const crc = calculateCrc32(dataBytes);
|
|
46
|
+
const localHeader = new Uint8Array(30 + nameBytes.length);
|
|
47
|
+
const dv = new DataView(localHeader.buffer);
|
|
48
|
+
dv.setUint32(0, 0x04034b50, true); // Local file header signature
|
|
49
|
+
dv.setUint16(4, 20, true); // Version needed to extract (2.0)
|
|
50
|
+
dv.setUint16(6, 0x0800, true); // Bit flag: UTF-8 filename (bit 11)
|
|
51
|
+
dv.setUint16(8, 0, true); // Compression method: STORE (0)
|
|
52
|
+
dv.setUint16(10, 0, true); // File last mod time
|
|
53
|
+
dv.setUint16(12, 0, true); // File last mod date
|
|
54
|
+
dv.setUint32(14, crc, true); // CRC-32
|
|
55
|
+
dv.setUint32(18, dataBytes.length, true); // Compressed size
|
|
56
|
+
dv.setUint32(22, dataBytes.length, true); // Uncompressed size
|
|
57
|
+
dv.setUint16(26, nameBytes.length, true); // Filename length
|
|
58
|
+
dv.setUint16(28, 0, true); // Extra field length
|
|
59
|
+
localHeader.set(nameBytes, 30);
|
|
60
|
+
fileEntries.push({
|
|
61
|
+
nameBytes,
|
|
62
|
+
dataBytes,
|
|
63
|
+
crc,
|
|
64
|
+
localHeader,
|
|
65
|
+
offset,
|
|
66
|
+
});
|
|
67
|
+
offset += localHeader.length + dataBytes.length;
|
|
68
|
+
}
|
|
69
|
+
const centralDirEntries = [];
|
|
70
|
+
let centralDirSize = 0;
|
|
71
|
+
for (const entry of fileEntries) {
|
|
72
|
+
const cd = new Uint8Array(46 + entry.nameBytes.length);
|
|
73
|
+
const dv = new DataView(cd.buffer);
|
|
74
|
+
dv.setUint32(0, 0x02014b50, true); // Central file header signature
|
|
75
|
+
dv.setUint16(4, 20, true); // Version made by
|
|
76
|
+
dv.setUint16(6, 20, true); // Version needed to extract
|
|
77
|
+
dv.setUint16(8, 0x0800, true); // Bit flag: UTF-8
|
|
78
|
+
dv.setUint16(10, 0, true); // Compression method: STORE
|
|
79
|
+
dv.setUint16(12, 0, true); // File last mod time
|
|
80
|
+
dv.setUint16(14, 0, true); // File last mod date
|
|
81
|
+
dv.setUint32(16, entry.crc, true); // CRC-32
|
|
82
|
+
dv.setUint32(20, entry.dataBytes.length, true); // Compressed size
|
|
83
|
+
dv.setUint32(24, entry.dataBytes.length, true); // Uncompressed size
|
|
84
|
+
dv.setUint16(28, entry.nameBytes.length, true); // Filename length
|
|
85
|
+
dv.setUint16(30, 0, true); // Extra field length
|
|
86
|
+
dv.setUint16(32, 0, true); // File comment length
|
|
87
|
+
dv.setUint16(34, 0, true); // Disk number start
|
|
88
|
+
dv.setUint16(36, 0, true); // Internal file attributes
|
|
89
|
+
dv.setUint32(38, 0, true); // External file attributes
|
|
90
|
+
dv.setUint32(42, entry.offset, true); // Relative offset of local header
|
|
91
|
+
cd.set(entry.nameBytes, 46);
|
|
92
|
+
centralDirEntries.push(cd);
|
|
93
|
+
centralDirSize += cd.length;
|
|
94
|
+
}
|
|
95
|
+
const eocd = new Uint8Array(22);
|
|
96
|
+
const dvEocd = new DataView(eocd.buffer);
|
|
97
|
+
dvEocd.setUint32(0, 0x06054b50, true); // End of central dir signature
|
|
98
|
+
dvEocd.setUint16(4, 0, true); // Number of this disk
|
|
99
|
+
dvEocd.setUint16(6, 0, true); // Number of disk with start of central directory
|
|
100
|
+
dvEocd.setUint16(8, fileEntries.length, true); // Total entries in this disk
|
|
101
|
+
dvEocd.setUint16(10, fileEntries.length, true); // Total entries
|
|
102
|
+
dvEocd.setUint32(12, centralDirSize, true); // Size of the central directory
|
|
103
|
+
dvEocd.setUint32(16, offset, true); // Offset of start of central directory
|
|
104
|
+
dvEocd.setUint16(20, 0, true); // ZIP file comment length
|
|
105
|
+
const totalLength = offset + centralDirSize + 22;
|
|
106
|
+
const result = new Uint8Array(totalLength);
|
|
107
|
+
let pos = 0;
|
|
108
|
+
for (const entry of fileEntries) {
|
|
109
|
+
result.set(entry.localHeader, pos);
|
|
110
|
+
pos += entry.localHeader.length;
|
|
111
|
+
result.set(entry.dataBytes, pos);
|
|
112
|
+
pos += entry.dataBytes.length;
|
|
113
|
+
}
|
|
114
|
+
for (const cd of centralDirEntries) {
|
|
115
|
+
result.set(cd, pos);
|
|
116
|
+
pos += cd.length;
|
|
117
|
+
}
|
|
118
|
+
result.set(eocd, pos);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
function formatCellValueAsXml(cellValue, cellRef) {
|
|
122
|
+
if (cellValue === null || cellValue === undefined || cellValue === '') {
|
|
123
|
+
return `<c r="${cellRef}"/>`;
|
|
124
|
+
}
|
|
125
|
+
if (typeof cellValue === 'number') {
|
|
126
|
+
if (Number.isFinite(cellValue)) {
|
|
127
|
+
return `<c r="${cellRef}"><v>${cellValue}</v></c>`;
|
|
128
|
+
}
|
|
129
|
+
return `<c r="${cellRef}" t="inlineStr"><is><t>${escapeXml(String(cellValue))}</t></is></c>`;
|
|
130
|
+
}
|
|
131
|
+
if (typeof cellValue === 'boolean') {
|
|
132
|
+
return `<c r="${cellRef}" t="b"><v>${cellValue ? 1 : 0}</v></c>`;
|
|
133
|
+
}
|
|
134
|
+
if (typeof cellValue === 'bigint') {
|
|
135
|
+
return `<c r="${cellRef}" t="inlineStr"><is><t>${cellValue.toString()}</t></is></c>`;
|
|
136
|
+
}
|
|
137
|
+
if (cellValue instanceof Date) {
|
|
138
|
+
const dateStr = Number.isNaN(cellValue.getTime()) ? 'Invalid Date' : cellValue.toISOString();
|
|
139
|
+
return `<c r="${cellRef}" t="inlineStr"><is><t>${escapeXml(dateStr)}</t></is></c>`;
|
|
140
|
+
}
|
|
141
|
+
let text;
|
|
142
|
+
if (typeof cellValue === 'object') {
|
|
143
|
+
try {
|
|
144
|
+
text = JSON.stringify(cellValue);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
text = String(cellValue);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
text = String(cellValue);
|
|
152
|
+
}
|
|
153
|
+
return `<c r="${cellRef}" t="inlineStr"><is><t xml:space="preserve">${escapeXml(text)}</t></is></c>`;
|
|
154
|
+
}
|
|
155
|
+
export function serializeGridExportDataToExcel(data, options) {
|
|
156
|
+
const includeHeader = options?.includeHeader ?? true;
|
|
157
|
+
let rawSheetName = (options?.sheetName || 'Sheet1').trim().replace(/[:\\/?*\[\]]/g, '');
|
|
158
|
+
if (!rawSheetName) {
|
|
159
|
+
rawSheetName = 'Sheet1';
|
|
160
|
+
}
|
|
161
|
+
else if (rawSheetName.length > 31) {
|
|
162
|
+
rawSheetName = rawSheetName.slice(0, 31);
|
|
163
|
+
}
|
|
164
|
+
const sheetRows = [];
|
|
165
|
+
let rowIndex = 1;
|
|
166
|
+
if (includeHeader) {
|
|
167
|
+
const headerCells = data.columns
|
|
168
|
+
.map((col, colIdx) => {
|
|
169
|
+
const cellRef = `${colIndexToExcelColumn(colIdx)}${rowIndex}`;
|
|
170
|
+
return formatCellValueAsXml(col.header, cellRef);
|
|
171
|
+
})
|
|
172
|
+
.join('');
|
|
173
|
+
sheetRows.push(`<row r="${rowIndex}">${headerCells}</row>`);
|
|
174
|
+
rowIndex++;
|
|
175
|
+
}
|
|
176
|
+
for (const row of data.rows) {
|
|
177
|
+
const rowCells = row.cells
|
|
178
|
+
.map((cell, colIdx) => {
|
|
179
|
+
const cellRef = `${colIndexToExcelColumn(colIdx)}${rowIndex}`;
|
|
180
|
+
return formatCellValueAsXml(cell, cellRef);
|
|
181
|
+
})
|
|
182
|
+
.join('');
|
|
183
|
+
sheetRows.push(`<row r="${rowIndex}">${rowCells}</row>`);
|
|
184
|
+
rowIndex++;
|
|
185
|
+
}
|
|
186
|
+
const contentTypesXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
187
|
+
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
|
|
188
|
+
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
|
|
189
|
+
'<Default Extension="xml" ContentType="application/xml"/>' +
|
|
190
|
+
'<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>' +
|
|
191
|
+
'<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>' +
|
|
192
|
+
'</Types>';
|
|
193
|
+
const rootRelsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
194
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
|
|
195
|
+
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>' +
|
|
196
|
+
'</Relationships>';
|
|
197
|
+
const workbookRelsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
198
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
|
|
199
|
+
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>' +
|
|
200
|
+
'</Relationships>';
|
|
201
|
+
const workbookXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
202
|
+
'<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' +
|
|
203
|
+
`<sheets><sheet name="${escapeXml(rawSheetName)}" sheetId="1" r:id="rId1"/></sheets>` +
|
|
204
|
+
'</workbook>';
|
|
205
|
+
const worksheetXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
206
|
+
'<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">' +
|
|
207
|
+
`<sheetData>${sheetRows.join('')}</sheetData>` +
|
|
208
|
+
'</worksheet>';
|
|
209
|
+
return createZipArchive([
|
|
210
|
+
{ name: '[Content_Types].xml', data: contentTypesXml },
|
|
211
|
+
{ name: '_rels/.rels', data: rootRelsXml },
|
|
212
|
+
{ name: 'xl/_rels/workbook.xml.rels', data: workbookRelsXml },
|
|
213
|
+
{ name: 'xl/workbook.xml', data: workbookXml },
|
|
214
|
+
{ name: 'xl/worksheets/sheet1.xml', data: worksheetXml },
|
|
215
|
+
]);
|
|
216
|
+
}
|
|
217
|
+
export function downloadExcel(blobOrBytes, fileName = 'export.xlsx') {
|
|
218
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let resolvedName = (fileName || '').trim();
|
|
222
|
+
if (!resolvedName) {
|
|
223
|
+
resolvedName = 'export.xlsx';
|
|
224
|
+
}
|
|
225
|
+
else if (!resolvedName.toLowerCase().endsWith('.xlsx')) {
|
|
226
|
+
resolvedName += '.xlsx';
|
|
227
|
+
}
|
|
228
|
+
const blob = blobOrBytes instanceof Blob
|
|
229
|
+
? blobOrBytes
|
|
230
|
+
: new Blob([blobOrBytes], {
|
|
231
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
232
|
+
});
|
|
233
|
+
if (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function') {
|
|
234
|
+
const url = URL.createObjectURL(blob);
|
|
235
|
+
const link = document.createElement('a');
|
|
236
|
+
link.href = url;
|
|
237
|
+
link.setAttribute('download', resolvedName);
|
|
238
|
+
link.style.display = 'none';
|
|
239
|
+
document.body.appendChild(link);
|
|
240
|
+
link.click();
|
|
241
|
+
document.body.removeChild(link);
|
|
242
|
+
if (typeof URL.revokeObjectURL === 'function') {
|
|
243
|
+
URL.revokeObjectURL(url);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
package/esm/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Key } from 'react';
|
|
3
|
-
import { BGridCellNavigationOptions, AppModelColumn, BGridColumnGroup, BGridColumnGroupNode, BGridColumnVisibilityState, BGridDataControl, BGridDataItem, BGridDataQuery, BGridPage, BGridProps, BGridRowChecked, BGridSortInfo, BGridSortParam, BGridResolvedScrollbarOptions, BGridResolvedStatusOptions, BGridResolvedPaginationViewOptions } from '../types';
|
|
3
|
+
import { BGridCellNavigationOptions, BGridColumn, AppModelColumn, BGridColumnGroup, BGridColumnGroupNode, BGridColumnVisibilityState, BGridDataControl, BGridDataItem, BGridDataQuery, BGridPage, BGridProps, BGridRowChecked, BGridSortInfo, BGridSortParam, BGridResolvedScrollbarOptions, BGridResolvedStatusOptions, BGridResolvedPaginationViewOptions } from '../types';
|
|
4
4
|
import { type BGridRowHeightMetrics } from '../utils';
|
|
5
5
|
interface Props<T> {
|
|
6
6
|
ref?: BGridProps<T>['ref'];
|
|
@@ -19,6 +19,7 @@ interface Props<T> {
|
|
|
19
19
|
frozenColumnIndex?: number;
|
|
20
20
|
frozenRowCount?: number;
|
|
21
21
|
columns: AppModelColumn<T>[];
|
|
22
|
+
sourceColumns?: BGridColumn<T>[];
|
|
22
23
|
columnsGroup: BGridColumnGroup[];
|
|
23
24
|
columnGroups: BGridColumnGroupNode[];
|
|
24
25
|
onChangeColumns?: BGridProps<T>['onChangeColumns'];
|
package/types/types.d.ts
CHANGED
|
@@ -148,6 +148,15 @@ export interface BGridSearchCellParams<T> {
|
|
|
148
148
|
values: T;
|
|
149
149
|
value: unknown;
|
|
150
150
|
}
|
|
151
|
+
export interface BGridCellExportValueParams<T> {
|
|
152
|
+
column: BGridColumn<T>;
|
|
153
|
+
columnId: string;
|
|
154
|
+
visibleIndex?: number;
|
|
155
|
+
sourceIndex: number;
|
|
156
|
+
item: BGridDataItem<T>;
|
|
157
|
+
values: T;
|
|
158
|
+
value: unknown;
|
|
159
|
+
}
|
|
151
160
|
export interface BGridColumn<T> {
|
|
152
161
|
id?: string;
|
|
153
162
|
key: string | string[];
|
|
@@ -184,6 +193,9 @@ export interface BGridColumn<T> {
|
|
|
184
193
|
aItem: BGridDataItem<T>;
|
|
185
194
|
bItem: BGridDataItem<T>;
|
|
186
195
|
}) => number;
|
|
196
|
+
exportable?: boolean;
|
|
197
|
+
exportHeader?: string | ((column: BGridColumn<T>) => string);
|
|
198
|
+
getExportValue?: (params: BGridCellExportValueParams<T>) => unknown;
|
|
187
199
|
}
|
|
188
200
|
export interface BGridColumnGroup {
|
|
189
201
|
label: ReactNode;
|
|
@@ -657,13 +669,72 @@ export interface BGridScrollToRowOptions {
|
|
|
657
669
|
/** Defaults to nearest: scroll only as far as needed to reveal the row. */
|
|
658
670
|
align?: 'start' | 'center' | 'end' | 'nearest';
|
|
659
671
|
}
|
|
660
|
-
export
|
|
672
|
+
export type BGridExportRowScope = 'displayed' | 'checked' | 'source';
|
|
673
|
+
export type BGridExportColumnScope = 'visible' | 'all' | readonly string[];
|
|
674
|
+
export interface BGridExportColumn<T> {
|
|
675
|
+
columnId: string;
|
|
676
|
+
header: string;
|
|
677
|
+
column: BGridColumn<T>;
|
|
678
|
+
columnIndex: number;
|
|
679
|
+
}
|
|
680
|
+
export interface BGridExportRow<T> {
|
|
681
|
+
visibleIndex?: number;
|
|
682
|
+
sourceIndex: number;
|
|
683
|
+
rowKey?: React.Key;
|
|
684
|
+
item: BGridDataItem<T>;
|
|
685
|
+
values: T;
|
|
686
|
+
cells: unknown[];
|
|
687
|
+
}
|
|
688
|
+
export interface BGridExportData<T> {
|
|
689
|
+
columns: BGridExportColumn<T>[];
|
|
690
|
+
rows: BGridExportRow<T>[];
|
|
691
|
+
}
|
|
692
|
+
export interface BGridExportDataOptions {
|
|
693
|
+
rows?: BGridExportRowScope;
|
|
694
|
+
columns?: BGridExportColumnScope;
|
|
695
|
+
}
|
|
696
|
+
export interface BGridCsvSerializeOptions {
|
|
697
|
+
delimiter?: string;
|
|
698
|
+
newline?: '\n' | '\r\n';
|
|
699
|
+
includeHeader?: boolean;
|
|
700
|
+
bom?: boolean;
|
|
701
|
+
preventFormulaInjection?: boolean;
|
|
702
|
+
}
|
|
703
|
+
export interface BGridCsvExportOptions extends BGridExportDataOptions {
|
|
704
|
+
fileName?: string;
|
|
705
|
+
delimiter?: string;
|
|
706
|
+
newline?: '\n' | '\r\n';
|
|
707
|
+
includeHeader?: boolean;
|
|
708
|
+
bom?: boolean;
|
|
709
|
+
preventFormulaInjection?: boolean;
|
|
710
|
+
}
|
|
711
|
+
export interface BGridExcelSerializeOptions {
|
|
712
|
+
sheetName?: string;
|
|
713
|
+
includeHeader?: boolean;
|
|
714
|
+
}
|
|
715
|
+
export interface BGridExcelExportOptions extends BGridExportDataOptions, BGridExcelSerializeOptions {
|
|
716
|
+
fileName?: string;
|
|
717
|
+
}
|
|
718
|
+
export interface BGridRef<T = any> {
|
|
661
719
|
/**
|
|
662
720
|
* Reveal a zero-based row in the displayed (sorted/filtered) data on the current page.
|
|
663
721
|
* Runs after pending data updates. Invalid indexes and frozen rows are ignored.
|
|
664
722
|
* Preserves horizontal scroll, cell focus and selection; does not load other pages.
|
|
665
723
|
*/
|
|
666
724
|
scrollToRow: (rowIndex: number, options?: BGridScrollToRowOptions) => void;
|
|
725
|
+
/**
|
|
726
|
+
* Extract logical grid data for export without touching the DOM.
|
|
727
|
+
* Supports displayed, checked, or source row scopes, and visible, all, or custom column scopes.
|
|
728
|
+
*/
|
|
729
|
+
getExportData: (options?: BGridExportDataOptions) => BGridExportData<T>;
|
|
730
|
+
/**
|
|
731
|
+
* Serialize grid data and trigger a browser CSV file download.
|
|
732
|
+
*/
|
|
733
|
+
exportCsv: (options?: BGridCsvExportOptions) => void;
|
|
734
|
+
/**
|
|
735
|
+
* Serialize grid data and trigger a browser Excel (.xlsx) file download.
|
|
736
|
+
*/
|
|
737
|
+
exportExcel: (options?: BGridExcelExportOptions) => void;
|
|
667
738
|
}
|
|
668
739
|
export interface BGridToolboxMessages {
|
|
669
740
|
sort?: string;
|
|
@@ -712,7 +783,7 @@ export interface BGridMessages {
|
|
|
712
783
|
toolbox?: BGridToolboxMessages;
|
|
713
784
|
}
|
|
714
785
|
export interface BGridProps<T> {
|
|
715
|
-
ref?: React.Ref<BGridRef
|
|
786
|
+
ref?: React.Ref<BGridRef<T>>;
|
|
716
787
|
width: number;
|
|
717
788
|
height: number;
|
|
718
789
|
headerHeight?: number;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BGridCsvSerializeOptions, BGridExportData } from '../types';
|
|
2
|
+
export declare function formatCsvCellValue(value: unknown, preventFormulaInjection?: boolean): string;
|
|
3
|
+
export declare function escapeCsvCell(cell: string, delimiter?: string): string;
|
|
4
|
+
export declare function serializeGridExportDataToCsv<T>(data: BGridExportData<T>, options?: BGridCsvSerializeOptions): string;
|
|
5
|
+
export declare function downloadCsv(csv: string, fileName?: string): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BGridColumn, BGridDataItem, BGridExportColumn, BGridExportColumnScope, BGridExportData, BGridExportDataOptions, BGridExportRow } from '../types';
|
|
3
|
+
export declare function resolveExportColumns<T>(columns: readonly BGridColumn<T>[], sourceColumns?: readonly BGridColumn<T>[], scope?: BGridExportColumnScope): BGridExportColumn<T>[];
|
|
4
|
+
export interface CreateGridExportDataParams<T> {
|
|
5
|
+
options?: BGridExportDataOptions;
|
|
6
|
+
columns: readonly BGridColumn<T>[];
|
|
7
|
+
sourceColumns?: readonly BGridColumn<T>[];
|
|
8
|
+
data: readonly BGridDataItem<T>[];
|
|
9
|
+
sourceData?: readonly BGridDataItem<T>[];
|
|
10
|
+
sourceIndexByVisibleIndex?: readonly number[];
|
|
11
|
+
visibleIndexBySourceIndex?: ReadonlyMap<number, number>;
|
|
12
|
+
checkedIndexesMap?: ReadonlyMap<number, unknown>;
|
|
13
|
+
rowKey?: React.Key | React.Key[];
|
|
14
|
+
}
|
|
15
|
+
export declare function resolveExportRows<T>(exportColumns: readonly BGridExportColumn<T>[], params: CreateGridExportDataParams<T>): BGridExportRow<T>[];
|
|
16
|
+
export declare function createGridExportData<T>(params: CreateGridExportDataParams<T>): BGridExportData<T>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BGridExcelSerializeOptions, BGridExportData } from '../types';
|
|
2
|
+
export declare function escapeXml(value: string): string;
|
|
3
|
+
export declare function colIndexToExcelColumn(colIndex: number): string;
|
|
4
|
+
export declare function serializeGridExportDataToExcel<T>(data: BGridExportData<T>, options?: BGridExcelSerializeOptions): Uint8Array;
|
|
5
|
+
export declare function downloadExcel(blobOrBytes: Blob | Uint8Array, fileName?: string): void;
|
package/types/utils/index.d.ts
CHANGED