Skip to content

Commit a868e95

Browse files
Cell width pivot property support
1 parent a73a13e commit a868e95

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.7.4",
4+
"version": "1.7.5",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

source/css/LightPivot.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
}
259259

260260
.lpt .lpt-topHeader th {
261-
min-width: 100px;
261+
min-width: 10px;
262262
text-align: center;
263263
/*border-bottom: none;*/
264264
}

source/js/DataController.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ DataController.prototype.modifyRawData = function (data) {
774774
var i = -1;
775775

776776
if (this.controller.CONFIG.showRowNumbers && !data.info.leftHeaderColumnsNumber) { // listing
777-
if (data.rawData[0] && data.rawData[0][0].special) { // just update indexes
777+
if (data.rawData[0] && data.rawData[0][0].special) { // just update indices
778778
data.rawData.forEach(function (row) {
779779
row[0].value = ++i === 0 ? "#" : i;
780780
row[0].isCaption = i === 0;
@@ -795,4 +795,11 @@ DataController.prototype.modifyRawData = function (data) {
795795
}
796796
}
797797

798+
var y = data.info.topHeaderRowsNumber - 1;
799+
for (i = data.info.leftHeaderColumnsNumber; i < data.rawData[y].length; i++) {
800+
data.rawData[y][i].style = "min-width:"
801+
+ (this.controller.CONFIG.pivotProperties["cellWidth"] || 100) + "px;"
802+
+ (data.rawData[y][i].style ? data.rawData[y][i].style : "");
803+
}
804+
798805
};

source/js/DataSource.js

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ DataSource.prototype.getCurrentData = function (callback) {
276276
requestData();
277277
});
278278
} else {
279+
_.GLOBAL_CONFIG["pivotProperties"] = {};
279280
requestData();
280281
}
281282

source/js/ExcelExport.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var ExcelExport = function () {
2+
3+
4+
5+
};
6+
7+
ExcelExport.prototype.exportTableHTML = (function () {
8+
var uri = 'data:application/vnd.ms-excel;base64,'
9+
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
10+
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
11+
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) };
12+
return function (tableHTML, name) {
13+
var ctx = { worksheet: name || 'Worksheet', table: tableHTML };
14+
console.log(uri + base64(format(template, ctx)));
15+
window.location.href = uri + base64(format(template, ctx))
16+
}
17+
})();
18+
19+
ExcelExport.prototype.exportXLS = function () {
20+
21+
var lpt = document.getElementsByClassName("lpt")[0],
22+
bodyHTML = lpt.getElementsByClassName("lpt-tableBlock")[0]
23+
.getElementsByTagName("table")[0].innerHTML,
24+
topHTML = lpt.getElementsByClassName("lpt-topHeader")[0]
25+
.getElementsByTagName("table")[0].innerHTML.replace(/<tr>/, "<tr><th colspan='2'></th>"),
26+
leftHTML = lpt.getElementsByClassName("lpt-leftHeader")[0]
27+
.getElementsByTagName("thead")[0].innerHTML,
28+
trs = leftHTML.match("<tr>(.*)</tr>")[1].split("</tr><tr>"),
29+
i = 0;
30+
31+
bodyHTML = bodyHTML.replace(/<tr>/g, function () {
32+
return "<tr>" + trs[i++];
33+
});
34+
35+
console.log(topHTML + bodyHTML);
36+
37+
this.exportTableHTML(topHTML + bodyHTML, "test");
38+
39+
};

0 commit comments

Comments
 (0)