Skip to content

Commit 0dfa980

Browse files
fixed headers, scrolling
1 parent 42ec4d8 commit 0dfa980

2 files changed

Lines changed: 64 additions & 32 deletions

File tree

source/css/LightPivot.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
}
237237

238238
.lpt .tableContainer .lpt-header {
239+
display: table;
239240
position: relative;
240241
float: left;
241242
/*width: 100px;*/
@@ -261,15 +262,30 @@
261262
}
262263

263264
.lpt .tableContainer .lpt-headerValue {
265+
display: table-cell;
264266
font-weight: bold;
265267
border-right: none;
266268
border-bottom: none;
269+
height: 100%;
270+
vertical-align: bottom;
267271
}
268272

273+
/*.lpt .lpt-topHeader th:first-child {*/
274+
/*border-left: none;*/
275+
/*}*/
276+
277+
/*.lpt .lpt-leftHeader tr:first-child th {*/
278+
/*border-top: none;*/
279+
/*}*/
280+
269281
.lpt .tableContainer .lpt-leftHeader th {
270282
border-right: none;
271283
}
272284

273285
.lpt .tableContainer .lpt-topHeader th {
274286
border-bottom: none;
287+
}
288+
289+
.lpt .lpt-leftHeader table {
290+
margin-bottom: 10em;
275291
}

source/js/PivotView.js

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -413,33 +413,65 @@ PivotView.prototype.formatNumber = function (mask, value) {
413413
*/
414414
PivotView.prototype.recalculateSizes = function (container) {
415415

416+
var containerParent = container.parentNode;
417+
416418
try {
417419

418420
var header = container.getElementsByClassName("lpt-headerValue")[0],
419421
headerContainer = container.getElementsByClassName("lpt-header")[0],
420422
topHeader = container.getElementsByClassName("lpt-topHeader")[0],
423+
tTableHead = topHeader.getElementsByTagName("thead")[0],
421424
topTableTr = topHeader.getElementsByTagName("tr")
422425
[topHeader.getElementsByTagName("tr").length - 1],
423426
leftHeader = container.getElementsByClassName("lpt-leftHeader")[0],
427+
lTableHead = leftHeader.getElementsByTagName("thead")[0],
424428
tableBlock = container.getElementsByClassName("lpt-tableBlock")[0],
425429
tableTr = tableBlock.getElementsByTagName("tr")[0],
426430
headerW = leftHeader.offsetWidth,
427431
headerH = topHeader.offsetHeight,
428-
tableBlockParent;
432+
containerHeight = container.offsetHeight,
433+
mainHeaderWidth = headerContainer.offsetWidth,
434+
addExtraTopHeaderCell = tTableHead.offsetWidth > topHeader.offsetWidth,
435+
addExtraLeftHeaderCell = lTableHead.offsetHeight > containerHeight - headerH,
436+
cell, cellWidths = [], i;
437+
438+
console.log( lTableHead.offsetHeight, leftHeader.offsetHeight);
429439

430440
headerContainer.style.width = headerW + "px";
441+
for (i in topTableTr.childNodes) {
442+
if (tableTr.childNodes[i].tagName !== "TD") continue;
443+
cellWidths.push(topTableTr.childNodes[i].offsetWidth);
444+
}
445+
446+
container.parentNode.removeChild(container); // detach
431447
topHeader.style.marginLeft = headerW + "px";
432448
tableBlock.style.marginLeft = headerW + "px";
433-
leftHeader.style.height = container.offsetHeight - headerH + "px";
434-
tableBlock.style.height = container.offsetHeight - headerH + "px";
449+
leftHeader.style.height = containerHeight - headerH + "px";
450+
if (mainHeaderWidth > headerW) leftHeader.style.width = mainHeaderWidth + "px";
451+
tableBlock.style.height = containerHeight - headerH + "px";
452+
headerContainer.style.height = headerH + "px";
453+
454+
if (addExtraTopHeaderCell) {
455+
tTableHead.childNodes[0].appendChild(cell = document.createElement("th"));
456+
cell.rowSpan = tTableHead.childNodes.length;
457+
cell.style.paddingLeft = headerW + "px"; // lucky random
458+
}
459+
460+
console.log(addExtraLeftHeaderCell);
461+
if (addExtraLeftHeaderCell) {
462+
lTableHead.appendChild(
463+
document.createElement("tr").appendChild(cell = document.createElement("th"))
464+
);
465+
cell.colSpan = lTableHead.childNodes.length;
466+
cell.style.paddingTop = headerH + "px"; // lucky random
467+
}
435468

436-
tableBlockParent = tableBlock.parentNode;
437-
tableBlockParent.removeChild(tableBlock);
438-
for (var i in tableTr.childNodes) {
469+
for (i in tableTr.childNodes) {
439470
if (tableTr.childNodes[i].tagName !== "TD") continue;
440-
tableTr.childNodes[i].style.width = topTableTr.childNodes[i].offsetWidth + "px";
471+
tableTr.childNodes[i].style.width = cellWidths[i] + "px";
441472
}
442-
tableBlockParent.appendChild(tableBlock);
473+
474+
containerParent.appendChild(container); // attach
443475

444476
} catch (e) {
445477
console.error("Error when fixing sizes. Please, contact the developer.", "ERROR:", e);
@@ -482,10 +514,11 @@ PivotView.prototype.renderRawData = function (data) {
482514
LHTable = document.createElement("table"),
483515
LHTHead = document.createElement("thead"),
484516
mainTable = document.createElement("table"),
485-
mainTbody = document.createElement("tbody"),
517+
mainTBody = document.createElement("tbody"),
486518
x, y, tr = null, th, td;
487519

488520
var renderHeader = function (xFrom, xTo, yFrom, yTo, targetElement) {
521+
var vertical = targetElement === LHTable;
489522
for (y = yFrom; y < yTo; y++) {
490523
for (x = xFrom; x < xTo; x++) {
491524
if (renderedGroups.hasOwnProperty(rawData[y][x].group)) { // recalculate c/r 'span
@@ -539,30 +572,13 @@ PivotView.prototype.renderRawData = function (data) {
539572
tr.appendChild(td = document.createElement("td"));
540573
td.textContent = rawData[y][x].value || "";
541574
}
542-
mainTbody.appendChild(tr);
575+
mainTBody.appendChild(tr);
543576
}
544577

545-
//for (y = 0; y < info.topHeaderRowsNumber; y++) {
546-
// for (x = info.leftHeaderColumnsNumber; x < rawData[y].length; x++) {
547-
// if (renderedGroups.hasOwnProperty(rawData[y][x].group)) { // recalculate col/row 'span
548-
// renderedGroups[rawData[y][x].group].element.colSpan =
549-
// x - renderedGroups[rawData[y][x].group].x;
550-
// renderedGroups[rawData[y][x].group].element.rowSpan =
551-
// y - renderedGroups[rawData[y][x].group].y;
552-
// } else { // create element
553-
// if (!tr) tr = document.createElement("tr");
554-
// tr.appendChild(th = document.createElement("th"));
555-
// th.textContent = rawData[y][x].value;
556-
// if (rawData[y][x].group) renderedGroups[rawData[y][x].group] = {
557-
// x: x,
558-
// y: y,
559-
// element: th
560-
// };
561-
// }
562-
// }
563-
// if (tr) THTHead.appendChild(tr);
564-
// tr = null;
565-
//}
578+
tableBlock.addEventListener("scroll", function () {
579+
topHeader.scrollLeft = tableBlock.scrollLeft;
580+
leftHeader.scrollTop = tableBlock.scrollTop;
581+
});
566582

567583
tableBlock.className = "lpt-tableBlock";
568584
leftHeader.className = "lpt-leftHeader";
@@ -571,7 +587,7 @@ PivotView.prototype.renderRawData = function (data) {
571587
pivotTopSection.className = "lpt-topSection";
572588
pivotBottomSection.className = "lpt-bottomSection";
573589
header.className = "lpt-headerValue";
574-
mainTable.appendChild(mainTbody);
590+
mainTable.appendChild(mainTBody);
575591
tableBlock.appendChild(mainTable);
576592
LHTable.appendChild(LHTHead);
577593
leftHeader.appendChild(LHTable);

0 commit comments

Comments
 (0)