-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (44 loc) · 1.69 KB
/
index.js
File metadata and controls
46 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var pivotTableObj = new ej.pivotview.PivotView({
dataSourceSettings: {
columns: [{ name: 'Date', caption: 'Date' }, { name: 'Product' }],
dataSource: pivotData,
expandAll: false,
enableSorting: true,
filters: [],
drilledMembers: [{ name: 'Country', items: ['France'] }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
rows: [{ name: 'Country' }, { name: 'State' }],
values: [{ name: 'Amount', caption: 'Sold Amount' }, { name: 'Quantity', caption: 'Quantity' }]
},
showToolbar: true,
toolbarTemplate: '#template',
height: 350,
dataBound: function ondataBound() {
const dataSource = JSON.parse(pivotTableObj.getPersistData()).dataSourceSettings;
const a = document.getElementById('save');
const mime_type = 'application/octet-stream';
a.setAttribute('download', 'pivot.JSON');
a.href = 'data:' + mime_type + ';base64,' + btoa(JSON.stringify(dataSource) || '');
document.getElementById('files').addEventListener('change', readBlob, false);
}
});
function readBlob() {
const files = document.getElementById('files').files;
const file = files[0];
let start = 0, stop = 0;
if (file && file.size) {
stop = file.size - 1;
}
const reader = new FileReader();
reader.onloadend = function(evt) {
if (evt.target.readyState == FileReader.DONE) {
pivotTableObj.dataSourceSettings = JSON.parse(evt.target.result);
}
};
if (file) {
const blob = file.slice(start, stop + 1);
reader.readAsBinaryString(blob);
}
document.getElementById('files').value = '';
}
pivotTableObj.appendTo('#PivotTable');