@bento-core/table 1.0.0 → 1.0.1-CDS.0
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/dist/ExtendedView.js +11 -5
- package/dist/TableView.js +13 -3
- package/dist/body/ActionBodyCell.js +4 -1
- package/dist/body/CustomTblBody.js +6 -2
- package/dist/body/components/CheckBoxView.js +7 -3
- package/dist/body/components/DeleteCellView.js +6 -2
- package/dist/header/ActionHeaderCell.js +3 -1
- package/dist/header/ColumnGrouping.js +52 -0
- package/dist/header/CustomCell.js +2 -1
- package/dist/header/CustomTblHeader.js +10 -3
- package/dist/header/components/DeleteCellView.js +11 -6
- package/dist/header/components/RemoveAllDialog.js +3 -1
- package/dist/toolbar/DownloadButtonView.js +57 -5
- package/dist/toolbar/ManageColumnView.js +7 -8
- package/dist/util/Dataformat.js +41 -1
- package/dist/util/downloadTable.js +109 -0
- package/package.json +7 -2
- package/src/ExtendedView.js +35 -25
- package/src/TableView.js +10 -0
- package/src/body/ActionBodyCell.js +3 -0
- package/src/body/CustomTblBody.js +5 -1
- package/src/body/components/CheckBoxView.js +23 -9
- package/src/body/components/DeleteCellView.js +28 -16
- package/src/header/ActionHeaderCell.js +2 -0
- package/src/header/ColumnGrouping.js +55 -0
- package/src/header/CustomCell.js +1 -0
- package/src/header/CustomTblHeader.js +5 -0
- package/src/header/components/DeleteCellView.js +41 -26
- package/src/header/components/RemoveAllDialog.js +2 -0
- package/src/toolbar/DownloadButtonView.js +57 -3
- package/src/toolbar/ManageColumnView.js +9 -6
- package/src/util/Dataformat.js +25 -0
- package/src/util/downloadTable.js +74 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { formatBytes, formatColumnValues } from './Dataformat';
|
|
2
|
+
import { actionCellTypes } from './Types';
|
|
3
|
+
|
|
4
|
+
export function createFileName(fileName) {
|
|
5
|
+
const date = new Date();
|
|
6
|
+
const yyyy = date.getFullYear();
|
|
7
|
+
let dd = date.getDate();
|
|
8
|
+
let mm = (date.getMonth() + 1);
|
|
9
|
+
|
|
10
|
+
if (dd < 10) { dd = `0${dd}`; }
|
|
11
|
+
|
|
12
|
+
if (mm < 10) { mm = `0${mm}`; }
|
|
13
|
+
|
|
14
|
+
const todaysDate = `${yyyy}-${mm}-${dd}`;
|
|
15
|
+
|
|
16
|
+
let hours = date.getHours();
|
|
17
|
+
let minutes = date.getMinutes();
|
|
18
|
+
let seconds = date.getSeconds();
|
|
19
|
+
|
|
20
|
+
if (hours < 10) { hours = `0${hours}`; }
|
|
21
|
+
|
|
22
|
+
if (minutes < 10) { minutes = `0${minutes}`; }
|
|
23
|
+
|
|
24
|
+
if (seconds < 10) { seconds = `0${seconds}`; }
|
|
25
|
+
|
|
26
|
+
return `${fileName} ${todaysDate} ${hours}-${minutes}-${seconds}${'.csv'}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function convertToCSV(jsonse, keysToInclude, header) {
|
|
30
|
+
const objArray = jsonse;
|
|
31
|
+
// To Do empty object just print headers
|
|
32
|
+
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
|
|
33
|
+
let str = header.join(',');
|
|
34
|
+
array.map((entry, index) => {
|
|
35
|
+
let line = '';
|
|
36
|
+
keysToInclude.map((keyName) => {
|
|
37
|
+
if (line !== '') line += ',';
|
|
38
|
+
if (keyName === 'file_size') {
|
|
39
|
+
line += entry[keyName] !== null ? `"${formatBytes(entry[keyName])}"` : ' ';
|
|
40
|
+
} else {
|
|
41
|
+
line += entry[keyName] !== null ? `"${entry[keyName]}"` : ' ';
|
|
42
|
+
}
|
|
43
|
+
return line;
|
|
44
|
+
});
|
|
45
|
+
if (index === 0) {
|
|
46
|
+
// str = header.join(',');
|
|
47
|
+
str += `\r\n${line}\r\n`;
|
|
48
|
+
} else {
|
|
49
|
+
str += `${line}\r\n`;
|
|
50
|
+
}
|
|
51
|
+
return str;
|
|
52
|
+
});
|
|
53
|
+
return str;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function downloadJson(tableData, table, downloadFileName) {
|
|
57
|
+
const { columns = [] } = table;
|
|
58
|
+
const filterColumns = columns.filter(({ cellType }) => !actionCellTypes.includes(cellType));
|
|
59
|
+
const formatDataVal = formatColumnValues(filterColumns, tableData);
|
|
60
|
+
const jsonse = JSON.stringify(formatDataVal);
|
|
61
|
+
const keysToInclude = columns.filter(({ dataField }) => dataField)
|
|
62
|
+
.map(({ dataField }) => dataField);
|
|
63
|
+
const headers = columns.filter(({ dataField }) => dataField).map(({ header }) => header);
|
|
64
|
+
const csv = convertToCSV(jsonse, keysToInclude, headers);
|
|
65
|
+
const exportData = new Blob([csv], { type: 'text/csv' });
|
|
66
|
+
const JsonURL = window.URL.createObjectURL(exportData);
|
|
67
|
+
let tempLink = '';
|
|
68
|
+
tempLink = document.createElement('a');
|
|
69
|
+
tempLink.setAttribute('href', JsonURL);
|
|
70
|
+
tempLink.setAttribute('download', createFileName(downloadFileName || ''));
|
|
71
|
+
document.body.appendChild(tempLink);
|
|
72
|
+
tempLink.click();
|
|
73
|
+
document.body.removeChild(tempLink);
|
|
74
|
+
}
|