-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubtotal.html
60 lines (55 loc) · 2.4 KB
/
subtotal.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<title>Subtotal </title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="./dist/pivot.js"></script>
<script type="text/javascript" src="./dist/subtotal.js"></script>
<link rel="stylesheet" type="text/css" href="./dist/pivot.min.css">
<link rel="stylesheet" type="text/css" href="./dist/subtotal.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.3/jquery.ui.touch-punch.min.js"></script>
<script type="text/javascript">
$(function(){
var dataClass = $.pivotUtilities.SubtotalPivotData;
var renderers = $.pivotUtilities.subtotal_renderers;
$.getJSON("./dist/mps.json", function(mps) {
$("#output").pivotUI(mps, {
dataClass: dataClass,
rows: ["Gender", "Province"],
cols: ["Party", "Age"],
renderers: renderers,
rendererName: "Table With Subtotal"
});
});
});
</script>
</head>
<body>
<button onclick="exportTableToExcel('testTable', 'pivot_table')">Export Table Data To Excel File</button>
<div id="output" style="margin: 30px;">
<div id="testTable"></div>
</div>
<script type="text/javascript">
function exportTableToExcel(tableID, filename = ''){
var downloadLink;
var dataType = 'application/vnd.ms-excel';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
filename = filename?filename+'.xls':'excel_data.xls';
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob){
var blob = new Blob(['\ufeff', tableHTML], {
type: dataType
});
navigator.msSaveOrOpenBlob( blob, filename);
}else{
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
downloadLink.download = filename;
downloadLink.click();
}
}
</script>
</body>
</html>