Skip to content

Commit

Permalink
column styles formatting, fixed table height
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Dec 11, 2014
1 parent 6a900a7 commit 29519d0
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
basicMDX: typeof req === "object" ? req.basicMDX : req
}
//, caption: "My table" // if set, table basi caption will be replaced by this text
//, caption: "My table" // if set, table basic caption will be replaced by this text
//, DrillDownExpression: "<spec>" // @deprecated drillDown expression split by "^"
//, showSummary: true // show summary by columns
//, formatNumbers: "#,###.##" // @deprecated
Expand Down
2 changes: 0 additions & 2 deletions source/css/LightPivot.css
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@

.lpt > .tableContainer > table {
min-width: 100%;
min-height: 100%;
height: 100%;
}

.lpt > .tableContainer td, .lpt > .tableContainer th {
Expand Down
52 changes: 48 additions & 4 deletions source/js/DataController.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ DataController.prototype.setData = function (data) {
*/
DataController.prototype.resetRawData = function () {

var data, summary, y, x;
var data, summary, y, x,
_ = this;

if (!(data = this._dataStack[this._dataStack.length - 1].data)) {
console.error("Unable to create raw data for given data set.");
Expand Down Expand Up @@ -162,6 +163,49 @@ DataController.prototype.resetRawData = function () {

};

var parseColumnFormatting = function (rawData) {
if (!_.controller.CONFIG["pivotProperties"]) return rawData;
var x, y, i, xEnd = rawData[0].length,
colLevels = _.controller.getPivotProperty(["columnLevels"]),
formatColumn = {
// "<spec>": { style: "<style>" }
};
var fillLevels = function (obj) {
if (typeof obj === "undefined") return;
for (var i in obj["childLevels"]) {
if (obj["childLevels"][i]["spec"] && obj["childLevels"][i]["levelStyle"]) {
formatColumn[obj["childLevels"][i]["spec"]] =
{ style: obj["childLevels"][i]["levelStyle"] };
}
fillLevels(obj["childLevels"][i]);
}
};
for (i in colLevels) {
fillLevels(colLevels[i]);
}
for (y = 0; y < rawData.length; y++) {
for (x = 0; x < xEnd; x++) {
if (!rawData[y][x].isCaption) {
xEnd = x; break;
}
if (rawData[y][x].source && rawData[y][x].source["path"]) {
for (i in formatColumn) {
if (rawData[y][x].source["path"].indexOf(i) >= 0) {
for (var yy = y + 1; yy < rawData.length; yy++) {
if (!rawData[yy][x].isCaption) {
rawData[yy][x].style = (rawData[yy][x].style || "")
+ formatColumn[i].style || "";
}
}
break;
}
}
}
}
}
return rawData;
};

if (data.dimensions[0].length) dim0raw(rd0, data.dimensions[0]);
if (data.dimensions[1].length) dim1raw(rd1, data.dimensions[1]);

Expand Down Expand Up @@ -228,15 +272,15 @@ DataController.prototype.resetRawData = function () {
}
return sum || "";
})(rawData, xh, rawData.length - 1, i),
style: {
"font-weight": 900
}
style: "font-weight: 900;"
}
}
}
groupNum++;
}

rawData = parseColumnFormatting(rawData);

data.rawData = data._rawDataOrigin = rawData;

return data.rawData;
Expand Down
2 changes: 2 additions & 0 deletions source/js/DataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ DataSource.prototype.getCurrentData = function (callback) {

var data = ready.pivotData;

_.GLOBAL_CONFIG["pivotProperties"] = ready.pivotData;

if (data["rowAxisOptions"]) {
if (data["rowAxisOptions"]["drilldownSpec"]) {
_.GLOBAL_CONFIG["DrillDownExpression"] =
Expand Down
17 changes: 17 additions & 0 deletions source/js/LightPivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ LightPivotTable.prototype.tryDrillThrough = function (filters) {

};

/**
* Crash-safe function to get properties of pivot.
*
* @param {string[]} path
* @returns {*|undefined}
*/
LightPivotTable.prototype.getPivotProperty = function (path) {
if (!this.CONFIG["pivotProperties"]) return undefined;
if (!(path instanceof Array)) path = [];
var obj = this.CONFIG["pivotProperties"]; path = path.reverse();
while (path.length
&& typeof obj !== "undefined") {
obj = obj[path.pop()];
}
return obj;
};

LightPivotTable.prototype.init = function () {

this.refresh();
Expand Down
9 changes: 6 additions & 3 deletions source/js/PivotView.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,13 @@ PivotView.prototype.renderRawData = function (data) {
if (!data[y][x].value.toString().match(/[0-9],?[0-9]?%/i))
td.className = "formatLeft";
}
//if (data[y][x].style) {
// for (var i in data[y][x].style) {
// td.style[i] = data[y][x].style[i];
// }
//}
if (data[y][x].style) {
for (var i in data[y][x].style) {
td.style[i] = data[y][x].style[i];
}
td.setAttribute("style", data[y][x].style);
}
td.appendChild(span);
tr.appendChild(td);
Expand Down

0 comments on commit 29519d0

Please sign in to comment.