Skip to content

Commit ce17352

Browse files
fixing totals option add, styles fixes
1 parent 9748193 commit ce17352

File tree

7 files changed

+86
-39
lines changed

7 files changed

+86
-39
lines changed

example/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
//, triggerEvent: "touchstart" // all "click" events will be replaced by this event
110110
//, caption: "My table" // if set, table basic caption will be replaced by this text
111111
, showSummary: true // show summary by columns
112+
//, attachTotals: true // display totals attached to table top header
112113
//, enableHeadersScrolling: true // enable scrolling both for table and headers
113114
//, loadingMessageHTML: "LOADING DATA..." // HTML displaying during data load
114115
//, conditionalFormattingOn: true // enable conditional formatting rules

export/LightPivotTable-DeepSeePortlet.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<Class name="DeepSee.LightPivotTable">
1313
<Super>%DeepSee.Component.Portlet.abstractPortlet</Super>
14-
<TimeChanged>63574,76552.664444</TimeChanged>
14+
<TimeChanged>63575,60589.683103</TimeChanged>
1515
<TimeCreated>63515,61322.546099</TimeCreated>
1616

1717
<Parameter name="INCLUDEFILES">
@@ -34,6 +34,10 @@
3434
<Type>%Boolean</Type>
3535
</Property>
3636

37+
<Property name="FixTotals">
38+
<Type>%Boolean</Type>
39+
</Property>
40+
3741
<Method name="%OnGetPortletName">
3842
<ClassMethod>1</ClassMethod>
3943
<ReturnType>%String</ReturnType>
@@ -59,6 +63,7 @@
5963
set pInfo($I(pInfo)) = $LB("ShowSummary", 1, "%Boolean", $$$Text("Show summary", "%DeepSee"), "Show summary row")
6064
set pInfo($I(pInfo)) = $LB("ExportCSV", 1, "%Boolean", $$$Text("Export to CSV", "%DeepSee"), "Show export to CSV format button")
6165
set pInfo($I(pInfo)) = $LB("Pagination", 0, "%Integer", $$$Text("Pagination", "%DeepSee"), "Enable pagination")
66+
set pInfo($I(pInfo)) = $LB("FixTotals", 0, "%Boolean", $$$Text("Fix totals", "%DeepSee"), "Fix totals in header")
6267
6368
quit $$$OK
6469
]]></Implementation>
@@ -232,6 +237,7 @@
232237
if (controller && controller["data"] && !setup.caption) setup.caption = controller["data"]["defaultCaption"] || "";
233238
if (info["drillDownDataSource"]) setup["drillDownTarget"] = info["drillDownDataSource"];
234239
setup["showSummary"] = !!parseInt(container.getAttribute("show-summary"));
240+
setup["attachTotals"] = !!parseInt(container.getAttribute("fixTotals"));
235241
if (parseInt(container.getAttribute("pagination"))) {
236242
setup["pagination"] = parseInt(container.getAttribute("pagination"))
237243
}
@@ -331,7 +337,7 @@
331337
}
332338
333339
&html<
334-
<div pagination="#(..Pagination)#" export-csv="#(..ExportCSV)#" data-source="#(..DataSource)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;">
340+
<div fixTotals="#(..FixTotals)#" pagination="#(..Pagination)#" export-csv="#(..ExportCSV)#" data-source="#(..DataSource)#" show-summary="#(..ShowSummary)#" class="lpt-container" style="position: absolute; left: 0; bottom: 0; width: 100%; height: 100%;">
335341
336342
</div>
337343
>

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.0.0-beta.4",
4+
"version": "1.0.0-beta.5",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var setup = { // Object that contain settings. Any setting may be missed.
5757
[ , triggerEvent: "touchstart" ] // all "click" events will be replaced by this event
5858
[ , caption: "My table" ] // if set, table basic caption will be replaced by this text
5959
[ , showSummary: true ] // show summary by columns
60+
[ , attachTotals: true ] // display totals attached to table top header
6061
[ , conditionalFormattingOn: true ] // pass false to turn off conditional formatting
6162
[ , loadingMessageHTML: "LOADING DATA..." ] // HTML displaying during data load
6263
[ , enableHeadersScrolling: false ] // enable scrolling both for table and headers. Useful for mobile devices.

source/css/LightPivot.css

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@
4848
transition: left .5s ease;
4949
}
5050

51-
.lpt tr:hover td {
51+
.lpt .lpt-tableBlock tr:hover td {
5252
box-shadow: inset 0 0 30px #FFF7D7;
5353
}
5454

55-
.lpt table td:hover {
56-
box-shadow: inset 0 0 20px #FEA;
55+
.lpt .lpt-tableBlock table td:hover {
56+
box-shadow: inset 0 0 30px #FEA;
5757
}
5858

5959
/* DeepSee theme */
@@ -91,7 +91,7 @@
9191
box-sizing: border-box;
9292
}
9393

94-
.lpt td {
94+
.lpt .lpt-tableBlock td {
9595
text-align: right;
9696
text-overflow: ellipsis;
9797
overflow: hidden;
@@ -140,10 +140,10 @@
140140
background: #FFF7D7;
141141
}
142142

143-
.lpt .lpt-topHeader tr:last-child th:hover {
144-
cursor: pointer;
145-
background: #FFF7D7;
146-
}
143+
/*.lpt .lpt-topHeader tr:last-child th:hover {*/
144+
/*cursor: pointer;*/
145+
/*background: #FFF7D7;*/
146+
/*}*/
147147

148148
.lpt .lpt-tableBlock {
149149
position: relative;
@@ -367,6 +367,11 @@
367367
background-color: #F0F0F0;
368368
}
369369

370+
.lpt-clickable:hover {
371+
cursor: pointer;
372+
background: #FFF7D7;
373+
}
374+
370375
.lpt .lpt-extraCell {
371376
padding: 0 !important;
372377
}

source/js/DataController.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ DataController.prototype.resetRawData = function () {
411411
var xw = (rd0[0] || []).length,
412412
yh = rd1.length || data.info.rowCount || 0,
413413
xh = rd0.length || data.info.colCount || 0,
414-
yw = (rd1[0] || []).length;
414+
yw = (rd1[0] || []).length,
415+
attachTotals = !!this.controller.CONFIG["attachTotals"];
415416

416417
// render columns, rows and data
417418
for (y = 0; y < xh + yh; y++) {
@@ -470,7 +471,7 @@ DataController.prototype.resetRawData = function () {
470471
data.info.SUMMARY_SHOWN = true;
471472
this.SUMMARY_SHOWN = true;
472473
this._dataStack[this._dataStack.length - 1].SUMMARY_SHOWN = true;
473-
rawData.push(summary = []);
474+
summary = [];
474475
x = rawData.length - 2;
475476
for (var i in rawData[x]) {
476477
if (rawData[x][i].isCaption) {
@@ -493,6 +494,12 @@ DataController.prototype.resetRawData = function () {
493494
}
494495
}
495496
groupNum++;
497+
if (attachTotals) {
498+
rawData.splice(data.info.topHeaderRowsNumber, 0, summary);
499+
data.info.topHeaderRowsNumber++;
500+
} else {
501+
rawData.push(summary);
502+
}
496503
}
497504

498505
rawData = parseColumnFormatting(rawData);
@@ -521,25 +528,27 @@ DataController.prototype._trigger = function () {
521528
*/
522529
DataController.prototype.sortByColumn = function (columnIndex) {
523530

524-
var data = this._dataStack[this._dataStack.length - 1].data;
531+
var data = this._dataStack[this._dataStack.length - 1].data,
532+
totalsAttached = this.SUMMARY_SHOWN
533+
&& this.controller.CONFIG["attachTotals"] ? 1 : 0;
525534

526535
if (this.SORT_STATE.column !== columnIndex) {
527536
order = this.SORT_STATE.order = 0;
528537
}
529538

530539
var newRawData = data._rawDataOrigin.slice(
531540
data.info.topHeaderRowsNumber,
532-
data._rawDataOrigin.length - (this.SUMMARY_SHOWN ? 1 : 0)
541+
data._rawDataOrigin.length - (this.SUMMARY_SHOWN && !totalsAttached ? 1 : 0)
533542
),
534543
xIndex = data.info.leftHeaderColumnsNumber + columnIndex,
535544
order = this.SORT_STATE.order === -1 ? 1 : this.SORT_STATE.order === 1 ? 0 : -1;
536545

537546
this.SORT_STATE.order = order;
538547
this.SORT_STATE.column = columnIndex;
539548

540-
for (var i in data.rawData[data.info.topHeaderRowsNumber - 1]) {
541-
if (data.rawData[data.info.topHeaderRowsNumber - 1][i].className) {
542-
delete data.rawData[data.info.topHeaderRowsNumber - 1][i].className;
549+
for (var i in data.rawData[data.info.topHeaderRowsNumber - totalsAttached - 1]) {
550+
if (data.rawData[data.info.topHeaderRowsNumber - totalsAttached - 1][i].className) {
551+
delete data.rawData[data.info.topHeaderRowsNumber - totalsAttached - 1][i].className;
543552
}
544553
}
545554

@@ -559,8 +568,12 @@ DataController.prototype.sortByColumn = function (columnIndex) {
559568

560569
data.rawData = data._rawDataOrigin.slice(0, data.info.topHeaderRowsNumber)
561570
.concat(newRawData)
562-
.concat(this.SUMMARY_SHOWN ? [data._rawDataOrigin[data._rawDataOrigin.length - 1]] : []);
563-
data.rawData[data.info.topHeaderRowsNumber - 1][data.info.leftHeaderColumnsNumber + columnIndex]
571+
.concat(this.SUMMARY_SHOWN && !totalsAttached
572+
? [data._rawDataOrigin[data._rawDataOrigin.length - 1]]
573+
: []
574+
);
575+
data.rawData[data.info.topHeaderRowsNumber - totalsAttached - 1]
576+
[data.info.leftHeaderColumnsNumber + columnIndex]
564577
.className = order === 0 ? "" : order === 1 ? "lpt-sortDesc" : "lpt-sortAsc";
565578

566579

source/js/PivotView.js

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,13 @@ PivotView.prototype._drillThroughClickHandler = function (event) {
289289
PivotView.prototype._cellClickHandler = function (cell, x, y, event, drillThroughHandler) {
290290

291291
var data = this.controller.dataController.getData(),
292-
f = [], f1, f2, callbackRes = true;
292+
f = [], f1, f2, callbackRes = true,
293+
ATTACH_TOTALS = this.controller.CONFIG["showSummary"]
294+
&& this.controller.CONFIG["attachTotals"] ? 1 : 0;
293295

294296
try {
295297
f1 = data.rawData[y][data.info.leftHeaderColumnsNumber - 1].source.path;
296-
f2 = data.rawData[data.info.topHeaderRowsNumber - 1][x].source.path;
298+
f2 = data.rawData[data.info.topHeaderRowsNumber - 1 - ATTACH_TOTALS][x].source.path;
297299
} catch (e) {
298300
console.warn("Unable to get filters for cell (%d, %d)", x, y);
299301
}
@@ -600,6 +602,8 @@ PivotView.prototype.renderRawData = function (data) {
600602

601603
var _ = this,
602604
CLICK_EVENT = this.controller.CONFIG["triggerEvent"] || "click",
605+
ATTACH_TOTALS = this.controller.CONFIG["showSummary"]
606+
&& this.controller.CONFIG["attachTotals"] ? 1 : 0,
603607
renderedGroups = {}, // keys of rendered groups; key = group, value = { x, y, element }
604608
rawData = data["rawData"],
605609
info = data["info"],
@@ -626,6 +630,19 @@ PivotView.prototype.renderRawData = function (data) {
626630
i, x, y, tr = null, th, td, primaryColumns = [], primaryRows = [], ratio, cellStyle,
627631
tempI, tempJ;
628632

633+
var formatContent = function (value, element, format) {
634+
if (!isFinite(value)) {
635+
element.className += " formatLeft";
636+
element.textContent = value || "";
637+
} else { // number
638+
if (format) {
639+
element.textContent = value ? _.numeral(value).format(format) : "";
640+
} else {
641+
element.textContent = value || "";
642+
}
643+
}
644+
};
645+
629646
// clean previous content
630647
this.removeMessage();
631648
while (container.firstChild) { container.removeChild(container.firstChild); }
@@ -657,7 +674,9 @@ PivotView.prototype.renderRawData = function (data) {
657674

658675
if (!rendered || separatelyGrouped) { // create element
659676
if (!tr) tr = document.createElement("tr");
660-
tr.appendChild(th = document.createElement("th"));
677+
tr.appendChild(
678+
th = document.createElement(rawData[y][x].isCaption ? "th" : "td")
679+
);
661680
th.textContent = rawData[y][x].value || " ";
662681
if (rawData[y][x].style) th.setAttribute("style", rawData[y][x].style);
663682
if (rawData[y][x].className) th.className = rawData[y][x].className;
@@ -666,6 +685,11 @@ PivotView.prototype.renderRawData = function (data) {
666685
y: y,
667686
element: th
668687
};
688+
if (!rawData[y][x].isCaption) formatContent(
689+
rawData[y][x].value,
690+
th,
691+
columnProps[x - info.leftHeaderColumnsNumber].format
692+
);
669693
}
670694

671695
// add listeners
@@ -677,14 +701,18 @@ PivotView.prototype.renderRawData = function (data) {
677701
};
678702
})(y, rawData[y][x]));
679703
}
680-
if (!vertical && y === yTo - 1 && !th["_hasSortingListener"]) {
681-
th["_hasSortingListener"] = false;
682-
primaryColumns.push(th);
704+
if (!vertical && y === yTo - 1 - ATTACH_TOTALS && !th["_hasSortingListener"]) {
705+
th["_hasSortingListener"] = false; // why false?
683706
th.addEventListener(CLICK_EVENT, (function (i) {
684707
return function () {
685708
_._columnClickHandler.call(_, i);
686709
};
687710
})(x - info.leftHeaderColumnsNumber));
711+
th.className = (th.className || "") + " lpt-clickable";
712+
}
713+
if (!vertical && y === yTo - 1) {
714+
//th["_hasSortingListener"] = false; // why false?
715+
primaryColumns.push(th);
688716
}
689717

690718
}
@@ -732,24 +760,17 @@ PivotView.prototype.renderRawData = function (data) {
732760
);
733761

734762
// render table
735-
for (y = tempI/*info.topHeaderRowsNumber*/; y < tempJ/*rawData.length*/; y++) {
763+
for (y = tempI; y < tempJ; y++) {
736764
tr = document.createElement("tr");
737765
for (x = info.leftHeaderColumnsNumber; x < rawData[0].length; x++) {
738766

739767
cellStyle = "";
740768
tr.appendChild(td = document.createElement("td"));
741-
if (!isFinite(rawData[y][x].value)) {
742-
td.className += " formatLeft";
743-
td.textContent = rawData[y][x].value || "";
744-
} else { // number
745-
if (columnProps[x - info.leftHeaderColumnsNumber].format) {
746-
td.textContent = rawData[y][x].value ? this.numeral(rawData[y][x].value).format(
747-
columnProps[x - info.leftHeaderColumnsNumber].format
748-
) : "";
749-
} else {
750-
td.textContent = rawData[y][x].value || "";
751-
}
752-
}
769+
formatContent(
770+
rawData[y][x].value,
771+
td,
772+
columnProps[x - info.leftHeaderColumnsNumber].format
773+
);
753774
if (
754775
colorScale
755776
&& !(info.SUMMARY_SHOWN && rawData.length - 1 === y) // exclude totals formatting

0 commit comments

Comments
 (0)