Skip to content

Commit 3c15380

Browse files
scrolling for table headers option (for mobile devices)
1 parent 3beff2b commit 3c15380

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

example/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
//, triggerEvent: "touchstart" // all "click" events will be replaced by this event
105105
//, caption: "My table" // if set, table basic caption will be replaced by this text
106106
, showSummary: true // show summary by columns
107+
, enableHeadersScrolling: true // enable scrolling both for table and headers
107108
//, conditionalFormattingOn: true // enable conditional formatting rules
108109
//, drillDownTarget: "<dashboard name>" // undocumented, deepSee only
109110
};

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ var setup = { // Object that contain settings. Any setting may be missed.
5656
[ , caption: "My table" // if set, table basic caption will be replaced by this text ]
5757
[ , showSummary: true // show summary by columns ]
5858
[ , conditionalFormattingOn: true // pass false to turn off conditional formatting ]
59+
[ , enableHeadersScrolling: false // enable scrolling both for table and headers. Useful for mobile devices. ]
5960
[ , drillDownTarget: "<dashboard name>" // deepSee only - dashboard to open ]
6061
},
6162
lp = new LightPivotTable(setup);

source/css/LightPivot.css

+16-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@
174174
/*border-bottom: none;*/
175175
}
176176

177-
.lpt .lpt-leftHeader table {
178-
margin-bottom: 10em;
179-
}
177+
/*.lpt .lpt-leftHeader table {*/
178+
/*margin-bottom: 10em;*/
179+
/*}*/
180180

181181
/* lpt-dataWait */
182182
.lpt .lpt-hoverMessage {
@@ -189,4 +189,17 @@
189189
-moz-transition: opacity 1s ease;
190190
-o-transition: opacity 1s ease;
191191
transition: opacity 1s ease;
192+
}
193+
194+
.lpt-scrollable-y {
195+
overflow-y: auto !important;
196+
}
197+
.lpt-scrollable-x {
198+
overflow-x: auto !important;
199+
}
200+
.lpt-scrollable-x::-webkit-scrollbar {
201+
display: none;
202+
}
203+
.lpt-scrollable-y::-webkit-scrollbar {
204+
display: none;
192205
}

source/js/PivotView.js

+31-12
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,9 @@ PivotView.prototype.recalculateSizes = function (container) {
369369
containerHeight = container.offsetHeight,
370370
mainHeaderWidth = headerContainer.offsetWidth,
371371
hasVerticalScrollBar = tableBlock.scrollHeight > containerHeight - headerH,
372-
addExtraTopHeaderCell = tTableHead.offsetWidth > topHeader.offsetWidth,
373-
addExtraLeftHeaderCell = lTableHead.offsetHeight > containerHeight - headerH,
372+
//addExtraTopHeaderCell = tTableHead.offsetWidth > topHeader.offsetWidth,
373+
addExtraLeftHeaderCell = lTableHead.offsetHeight > containerHeight - headerH
374+
&& this.SCROLLBAR_WIDTH > 0,
374375
cell, tr, cellWidths = [], columnHeights = [], i;
375376

376377
headerContainer.style.width = headerW + "px";
@@ -403,12 +404,12 @@ PivotView.prototype.recalculateSizes = function (container) {
403404
tableBlock.style.height = containerHeight - headerH + "px";
404405
headerContainer.style.height = headerH + "px";
405406

406-
if (addExtraTopHeaderCell) {
407-
tTableHead.childNodes[0].appendChild(cell = document.createElement("th"));
408-
cell.rowSpan = tTableHead.childNodes.length;
409-
cell.style.paddingLeft = headerW + "px"; // lucky random
410-
cell["_extraCell"] = true;
411-
}
407+
//if (false && addExtraTopHeaderCell) {
408+
// tTableHead.childNodes[0].appendChild(cell = document.createElement("td"));
409+
// cell.rowSpan = tTableHead.childNodes.length;
410+
// cell.style.width = this.SCROLLBAR_WIDTH + "px"; // lucky random
411+
// cell["_extraCell"] = true;
412+
//}
412413

413414
if (addExtraLeftHeaderCell) {
414415
tr = document.createElement("tr");
@@ -421,10 +422,12 @@ PivotView.prototype.recalculateSizes = function (container) {
421422
if (cell["__i"] > 5) _["_"]();
422423
});
423424
tr["_extraTr"] = true;
424-
leftHeader.className = "lpt-leftHeader bordered";
425+
leftHeader.className = leftHeader.className.replace(/\sbordered/, "")
426+
+ " bordered";
425427
cell.colSpan = lTableHead.childNodes.length;
426-
cell.textContent = "_"; // cheating
427-
cell.style.lineHeight = headerH + "px"; // lucky random
428+
cell.style.height = this.SCROLLBAR_WIDTH + "px";
429+
//cell.textContent = "_"; // cheating
430+
//cell.style.lineHeight = headerH + "px"; // lucky random
428431
}
429432

430433
for (i in tableTr.childNodes) {
@@ -629,13 +632,29 @@ PivotView.prototype.renderRawData = function (data) {
629632
}
630633

631634
tableBlock.addEventListener("scroll", function () {
635+
if (tableBlock._ISE) { tableBlock._ISE = false; return; }
632636
topHeader.scrollLeft = tableBlock.scrollLeft;
633637
leftHeader.scrollTop = tableBlock.scrollTop;
638+
topHeader._ISE = true; leftHeader._ISE = true; // ignore scroll event
634639
});
635640

636-
tableBlock.className = "lpt-tableBlock";
637641
leftHeader.className = "lpt-leftHeader";
638642
topHeader.className = "lpt-topHeader";
643+
if (this.controller.CONFIG.enableHeadersScrolling) {
644+
leftHeader.className = leftHeader.className + " lpt-scrollable-y";
645+
topHeader.className = topHeader.className + " lpt-scrollable-x";
646+
leftHeader.addEventListener("scroll", function () {
647+
if (leftHeader._ISE) { leftHeader._ISE = false; return; }
648+
tableBlock.scrollTop = leftHeader.scrollTop;
649+
tableBlock._ISE = true;
650+
});
651+
topHeader.addEventListener("scroll", function () {
652+
if (topHeader._ISE) { topHeader._ISE = false; return; }
653+
tableBlock.scrollLeft = topHeader.scrollLeft;
654+
tableBlock._ISE = true;
655+
});
656+
}
657+
tableBlock.className = "lpt-tableBlock";
639658
pivotHeader.className = "lpt-header";
640659
pivotTopSection.className = "lpt-topSection";
641660
pivotBottomSection.className = "lpt-bottomSection";

0 commit comments

Comments
 (0)