Skip to content

Commit 29519d0

Browse files
column styles formatting, fixed table height
1 parent 6a900a7 commit 29519d0

File tree

6 files changed

+74
-10
lines changed

6 files changed

+74
-10
lines changed

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
MDX2JSONSource: "http://localhost:57772/SAMPLES", // MDX2JSON server address
9191
basicMDX: typeof req === "object" ? req.basicMDX : req
9292
}
93-
//, caption: "My table" // if set, table basi caption will be replaced by this text
93+
//, caption: "My table" // if set, table basic caption will be replaced by this text
9494
//, DrillDownExpression: "<spec>" // @deprecated drillDown expression split by "^"
9595
//, showSummary: true // show summary by columns
9696
//, formatNumbers: "#,###.##" // @deprecated

source/css/LightPivot.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@
152152

153153
.lpt > .tableContainer > table {
154154
min-width: 100%;
155-
min-height: 100%;
156-
height: 100%;
157155
}
158156

159157
.lpt > .tableContainer td, .lpt > .tableContainer th {

source/js/DataController.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ DataController.prototype.setData = function (data) {
9999
*/
100100
DataController.prototype.resetRawData = function () {
101101

102-
var data, summary, y, x;
102+
var data, summary, y, x,
103+
_ = this;
103104

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

163164
};
164165

166+
var parseColumnFormatting = function (rawData) {
167+
if (!_.controller.CONFIG["pivotProperties"]) return rawData;
168+
var x, y, i, xEnd = rawData[0].length,
169+
colLevels = _.controller.getPivotProperty(["columnLevels"]),
170+
formatColumn = {
171+
// "<spec>": { style: "<style>" }
172+
};
173+
var fillLevels = function (obj) {
174+
if (typeof obj === "undefined") return;
175+
for (var i in obj["childLevels"]) {
176+
if (obj["childLevels"][i]["spec"] && obj["childLevels"][i]["levelStyle"]) {
177+
formatColumn[obj["childLevels"][i]["spec"]] =
178+
{ style: obj["childLevels"][i]["levelStyle"] };
179+
}
180+
fillLevels(obj["childLevels"][i]);
181+
}
182+
};
183+
for (i in colLevels) {
184+
fillLevels(colLevels[i]);
185+
}
186+
for (y = 0; y < rawData.length; y++) {
187+
for (x = 0; x < xEnd; x++) {
188+
if (!rawData[y][x].isCaption) {
189+
xEnd = x; break;
190+
}
191+
if (rawData[y][x].source && rawData[y][x].source["path"]) {
192+
for (i in formatColumn) {
193+
if (rawData[y][x].source["path"].indexOf(i) >= 0) {
194+
for (var yy = y + 1; yy < rawData.length; yy++) {
195+
if (!rawData[yy][x].isCaption) {
196+
rawData[yy][x].style = (rawData[yy][x].style || "")
197+
+ formatColumn[i].style || "";
198+
}
199+
}
200+
break;
201+
}
202+
}
203+
}
204+
}
205+
}
206+
return rawData;
207+
};
208+
165209
if (data.dimensions[0].length) dim0raw(rd0, data.dimensions[0]);
166210
if (data.dimensions[1].length) dim1raw(rd1, data.dimensions[1]);
167211

@@ -228,15 +272,15 @@ DataController.prototype.resetRawData = function () {
228272
}
229273
return sum || "";
230274
})(rawData, xh, rawData.length - 1, i),
231-
style: {
232-
"font-weight": 900
233-
}
275+
style: "font-weight: 900;"
234276
}
235277
}
236278
}
237279
groupNum++;
238280
}
239281

282+
rawData = parseColumnFormatting(rawData);
283+
240284
data.rawData = data._rawDataOrigin = rawData;
241285

242286
return data.rawData;

source/js/DataSource.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ DataSource.prototype.getCurrentData = function (callback) {
125125

126126
var data = ready.pivotData;
127127

128+
_.GLOBAL_CONFIG["pivotProperties"] = ready.pivotData;
129+
128130
if (data["rowAxisOptions"]) {
129131
if (data["rowAxisOptions"]["drilldownSpec"]) {
130132
_.GLOBAL_CONFIG["DrillDownExpression"] =

source/js/LightPivotTable.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ LightPivotTable.prototype.tryDrillThrough = function (filters) {
192192

193193
};
194194

195+
/**
196+
* Crash-safe function to get properties of pivot.
197+
*
198+
* @param {string[]} path
199+
* @returns {*|undefined}
200+
*/
201+
LightPivotTable.prototype.getPivotProperty = function (path) {
202+
if (!this.CONFIG["pivotProperties"]) return undefined;
203+
if (!(path instanceof Array)) path = [];
204+
var obj = this.CONFIG["pivotProperties"]; path = path.reverse();
205+
while (path.length
206+
&& typeof obj !== "undefined") {
207+
obj = obj[path.pop()];
208+
}
209+
return obj;
210+
};
211+
195212
LightPivotTable.prototype.init = function () {
196213

197214
this.refresh();

source/js/PivotView.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,13 @@ PivotView.prototype.renderRawData = function (data) {
500500
if (!data[y][x].value.toString().match(/[0-9],?[0-9]?%/i))
501501
td.className = "formatLeft";
502502
}
503+
//if (data[y][x].style) {
504+
// for (var i in data[y][x].style) {
505+
// td.style[i] = data[y][x].style[i];
506+
// }
507+
//}
503508
if (data[y][x].style) {
504-
for (var i in data[y][x].style) {
505-
td.style[i] = data[y][x].style[i];
506-
}
509+
td.setAttribute("style", data[y][x].style);
507510
}
508511
td.appendChild(span);
509512
tr.appendChild(td);

0 commit comments

Comments
 (0)