Skip to content

Commit 22ac3f0

Browse files
fixed column headers with missed children returned from MDX2JSON
1 parent 7b10e11 commit 22ac3f0

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

package.json

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

source/js/DataController.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,26 +335,40 @@ DataController.prototype.resetRawData = function () {
335335
}
336336
};
337337

338-
var dim1raw = function (a, c, arr, hor) {
338+
var getMaxLevel = function (c) {
339+
var lev = 0;
340+
for (var i in c) {
341+
if (c[i].children && c[i].children.length) {
342+
lev = Math.max(lev, getMaxLevel(c[i].children));
343+
}
344+
}
345+
return lev + 1;
346+
};
347+
348+
var dim1raw = function (a, c, arr, hor, level, maxLevel) {
349+
350+
var cnum, obj, sameGroup;
339351

340352
if (!arr) {
341353
arr = [];
342354
}
343355

344-
var cnum, obj;
345-
346356
for (var i in c) {
347357
cnum = groupNum;
358+
if (level < maxLevel && !(c[i].children && c[i].children.length)) { // maxLevel is not reached, but no child
359+
c[i].children = [{}];
360+
sameGroup = true; // let the child cells join parent cell
361+
}
348362
if (c[i].children && c[i].children.length) {
349-
groupNum++;
363+
if (!sameGroup) groupNum++; else sameGroup = false;
350364
obj = {
351365
group: cnum,
352366
source: c[i],
353367
isCaption: true,
354368
value: c[i].caption || ""
355369
};
356370
applyHeaderStyle(obj, hor);
357-
dim1raw(a, c[i].children, arr.concat(obj), hor);
371+
dim1raw(a, c[i].children, arr.concat(obj), hor, level?++level:level, maxLevel);
358372
} else {
359373
obj = {
360374
group: groupNum,
@@ -421,8 +435,12 @@ DataController.prototype.resetRawData = function () {
421435
return rawData;
422436
};
423437

424-
if (data.dimensions[0].length) dim0raw(rd0, data.dimensions[0]);
425-
if (data.dimensions[1].length) dim1raw(rd1, data.dimensions[1]);
438+
if (data.dimensions[0].length) {
439+
dim0raw(rd0, data.dimensions[0]);
440+
}
441+
if (data.dimensions[1].length) {
442+
dim1raw(rd1, data.dimensions[1], undefined, undefined, 1, getMaxLevel(data.dimensions[1]));
443+
}
426444
if (rd1[0]) dimCaption = (rd1[0][rd1[0].length - 1] || { source: {} }).source["dimension"];
427445

428446
var xw = (rd0[0] || []).length,

0 commit comments

Comments
 (0)