Skip to content

Commit

Permalink
Cell width pivot property support
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Feb 26, 2017
1 parent a73a13e commit a868e95
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LightPivotTable",
"author": "ZitRo",
"version": "1.7.4",
"version": "1.7.5",
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
"main": "test/testServer.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion source/css/LightPivot.css
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
}

.lpt .lpt-topHeader th {
min-width: 100px;
min-width: 10px;
text-align: center;
/*border-bottom: none;*/
}
Expand Down
9 changes: 8 additions & 1 deletion source/js/DataController.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ DataController.prototype.modifyRawData = function (data) {
var i = -1;

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

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

};
1 change: 1 addition & 0 deletions source/js/DataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ DataSource.prototype.getCurrentData = function (callback) {
requestData();
});
} else {
_.GLOBAL_CONFIG["pivotProperties"] = {};
requestData();
}

Expand Down
39 changes: 39 additions & 0 deletions source/js/ExcelExport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var ExcelExport = function () {



};

ExcelExport.prototype.exportTableHTML = (function () {
var uri = 'data:application/vnd.ms-excel;base64,'
, 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>'
, base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) };
return function (tableHTML, name) {
var ctx = { worksheet: name || 'Worksheet', table: tableHTML };
console.log(uri + base64(format(template, ctx)));
window.location.href = uri + base64(format(template, ctx))
}
})();

ExcelExport.prototype.exportXLS = function () {

var lpt = document.getElementsByClassName("lpt")[0],
bodyHTML = lpt.getElementsByClassName("lpt-tableBlock")[0]
.getElementsByTagName("table")[0].innerHTML,
topHTML = lpt.getElementsByClassName("lpt-topHeader")[0]
.getElementsByTagName("table")[0].innerHTML.replace(/<tr>/, "<tr><th colspan='2'></th>"),
leftHTML = lpt.getElementsByClassName("lpt-leftHeader")[0]
.getElementsByTagName("thead")[0].innerHTML,
trs = leftHTML.match("<tr>(.*)</tr>")[1].split("</tr><tr>"),
i = 0;

bodyHTML = bodyHTML.replace(/<tr>/g, function () {
return "<tr>" + trs[i++];
});

console.log(topHTML + bodyHTML);

this.exportTableHTML(topHTML + bodyHTML, "test");

};

0 comments on commit a868e95

Please sign in to comment.