forked from clarketm/TableExport
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrowspan-colspan.html
More file actions
222 lines (192 loc) · 8.29 KB
/
Copy pathrowspan-colspan.html
File metadata and controls
222 lines (192 loc) · 8.29 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ExportButtons</title>
<link href="../dist/css/tableexport.min.css" rel="stylesheet">
<link href="./examples.css" rel="stylesheet">
</head>
<body>
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-TL44T9" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<iframe src="./default.html" frameborder="0" width="100%" scrolling="no" onload="this.height=screen.height/3;"></iframe>
<main>
<h1>ExportButtons
<code class="small">exportButtons: false</code>
</h1>
<div>
<button id="customXLSButton">I am a BIG custom XLS button</button>
</div>
<table id="export-buttons-table">
<tbody>
<tr>
<td>[0, 0]</td>
<td>[1, 0]</td>
<td>[2, 0]</td>
<td>[3, 0]</td>
</tr>
<tr>
<td class="tableexport-empty">[0, 1]</td>
<td>[1, 1]</td>
<td>[2, 1]</td>
<td>[3, 1]</td>
</tr>
<tr>
<td>[0, 2]</td>
<td class="tableexport-ignore">[1, 2]</td>
<td colspan="2">[2, 2]</td>
<!--<td>[3, 2]</td>-->
</tr>
</tbody>
</table>
<!--<table id="export-buttons-table">-->
<!--<!–<thead>–>-->
<!--<!–<tr>–>-->
<!--<!–<th>A</th>–>-->
<!--<!–<th>B</th>–>-->
<!--<!–<th>C</th>–>-->
<!--<!–<th>D</th>–>-->
<!--<!–<th>E</th>–>-->
<!--<!–<th>F</th>–>-->
<!--<!–<th>G</th>–>-->
<!--<!–<th>H</th>–>-->
<!--<!–</tr>–>-->
<!--<!–</thead>–>-->
<!--<tbody>-->
<!--<tr>-->
<!--<td rowspan="2">-->
<!--2016-11-15-->
<!--</td>-->
<!--<td>会员卡</td>-->
<!--<td rowspan="3">办卡</td>-->
<!--<td rowspan="2">两年卡</td>-->
<!--<td rowspan="6">12345678901</td>-->
<!--<td rowspan="3" colspan="3">刷卡支付</td>-->
<!--<!–<td rowspan="2">刷卡支付</td>–>-->
<!--<!–<td>李欢</td>–>-->
<!--<!–<td class="te-number">1000</td>–>-->
<!--</tr>-->
<!--<tr>-->
<!--<td>现金</td>-->
<!--<!–<td>1980</td>–>-->
<!--<!–<td>1980</td>–>-->
<!--</tr>-->
<!--<tr>-->
<!--<td rowspan="1">2016-11-15</td>-->
<!--<td rowspan="1">会员卡</td>-->
<!--<td rowspan="1">两年卡</td>-->
<!--<!–<td rowspan="1">Treating myself</td>–>-->
<!--<!–<td rowspan="1">13858060001</td>–>-->
<!--<!–<td>刷卡支付</td>–>-->
<!--</tr>-->
<!--<tr>-->
<!--<td rowspan="1">2016-11-15</td>-->
<!--<!–<td class="tableexport-empty" rowspan="1">2016-11-15</td>–>-->
<!--<td rowspan="1">会员卡</td>-->
<!--<td rowspan="1">两年卡</td>-->
<!--<td rowspan="1">Treating myself</td>-->
<!--<td rowspan="1">13858060001</td>-->
<!--<td>刷卡支付</td>-->
<!--<td class="te-number">10</td>-->
<!--</tr>-->
<!--<tr>-->
<!--<td>1</td>-->
<!--<td>2</td>-->
<!--<td>3</td>-->
<!--<td>4</td>-->
<!--<td>5</td>-->
<!--<td>6</td>-->
<!--<td>7</td>-->
<!--</tr>-->
<!--</tbody>-->
<!--<!–<tfoot>–>-->
<!--<!–<tr>–>-->
<!--<!–<td class="disabled"></td>–>-->
<!--<!–<td class="disabled"></td>–>-->
<!--<!–<td te-ref="abc"><input type="text" name="address"></td>–>-->
<!--<!–<th>$441,210</th>–>-->
<!--<!–</tr>–>-->
<!--<!–</tfoot>–>-->
<!--</table>-->
<br>
<div class="info">
Your own custom export button can be easily created by simply capturing the <i>TableExport</i> instance.
<ol>
<li>First, save the TableExport <b>instance</b> to a variable.</li>
<li>Second, call <code>getExportData()</code> on the instance from <b>step 1</b>. The return value will be
an object literal with keys corresponding to the table selector(s) <code>id</code> attribute (or a
unique <i>uuid</i> generated by TableExport if an <code>id</code> is not provided).
</li>
<li>Lastly, call <code>export2file(data, mimeType, filename, fileExtension)</code>. The arguments correspond
to the keys of the Object returned from <b>step 2</b> above.
</li>
</ol>
First, in a variable
</div>
<br>
<div class="info code">
<pre>
var ExportButtons = document.getElementById('export-buttons-table');
var instance = new TableExport(ExportButtons, {
formats: ['xls'],
exportButtons: false
});
// // "id" of selector // format
var exportData = instance.getExportData()['export-buttons-table']['xls'];
var XLSbutton = document.getElementById('customXLSButton');
XLSbutton.addEventListener('click', function (e) {
// // data // mime // name // extension
instance.export2file(exportData.data, exportData.mimeType, exportData.filename, exportData.fileExtension);
});
</pre>
</div>
<br>
<div class="info">Additionally, the raw binary data (and byte length) can be retrieved using the <code>getBinaryData</code> prototype method.
<div class="info code nested">
<pre>
// get raw binary data (i.e. filesize)
var bytes = TableExport.prototype.getBinaryData(exportData.data, exportData.fileExtension);
var byteLength = bytes.byteLength;
</pre>
</div>
</div>
</main>
<script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../bower_components/js-xlsx/dist/xlsx.core.min.js"></script>
<script type="text/javascript" src="../bower_components/blobjs/Blob.min.js"></script>
<script type="text/javascript" src="../bower_components/file-saverjs/FileSaver.min.js"></script>
<!--<script type="text/javascript" src="../dist/js/tableexport.min.js"></script>-->
<script type="text/javascript" src="../src/stable/js/tableexport.js"></script>
<script type="text/javascript" src="../assets/js/analytics.js"></script>
<script>
var ExportButtons = document.getElementById('export-buttons-table');
var instance = new TableExport(ExportButtons, {
formats: ['xlsx'],
ignoreRows: [1],
ignoreCols: [1],
exportButtons: false
});
// **** jQuery **************************
// $(ExportButtons).tableExport({
// formats: ['xls'],
// exportButtons: false
// });
// **************************************
// // "id" of selector // format
// var exportData = instance.getExportData()['export-buttons-table'][instance.CONSTANTS.FORMAT.XLSX];
var exportData = instance.getExportData()['export-buttons-table']['xlsx'];
// get raw binary data (i.e. filesize)
var bytes = TableExport.prototype.getBinaryData(exportData.data, exportData.fileExtension).byteLength;
// console.log(exportData);
function extractInputData(data) {
// data[4][2].t = instance.CONSTANTS.TYPE.STRING;
// data[4][2].v = document.querySelector('[name=address]').value;
return data;
}
var XLSbutton = document.getElementById('customXLSButton');
XLSbutton.addEventListener('click', function (e) {
// // data // mime // name // extension
instance.export2file(extractInputData(exportData.data), exportData.mimeType, exportData.filename, exportData.fileExtension);
});
</script>
</body>
</html>