Skip to content

Commit 201184c

Browse files
sorting by columns
1 parent 62196bc commit 201184c

2 files changed

Lines changed: 58 additions & 17 deletions

File tree

source/css/LightPivot.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
}
227227
.lpt .lpt-headerValue.back:before {
228228
content: "< ";
229-
font-weight: 900;
229+
font-weight: bold;
230230
}
231231

232232
/* new */
@@ -278,6 +278,11 @@
278278
background: #FFF7D7;
279279
}
280280

281+
.lpt .lpt-topHeader tr:last-child th:hover {
282+
cursor: pointer;
283+
background: #FFF7D7;
284+
}
285+
281286
.lpt .lpt-tableBlock {
282287
position: relative;
283288
overflow: auto;

source/js/PivotView.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ PivotView.prototype.renderRawData = function (data) {
493493
return;
494494
}
495495

496-
this.removeMessage();
497-
498496
var _ = this,
499497
CLICK_EVENT = this.controller.CONFIG["triggerEvent"] || "click",
500498
renderedGroups = {}, // keys of rendered groups; key = group, value = { x, y, element }
@@ -516,32 +514,70 @@ PivotView.prototype.renderRawData = function (data) {
516514
mainTBody = document.createElement("tbody"),
517515
x, y, tr = null, th, td;
518516

517+
// clean previous content
518+
this.removeMessage();
519+
while (container.firstChild) { container.removeChild(container.firstChild); }
520+
519521
var renderHeader = function (xFrom, xTo, yFrom, yTo, targetElement) {
520-
var vertical = targetElement === LHTHead;
522+
523+
var vertical = targetElement === LHTHead,
524+
rendered, separatelyGrouped;
525+
521526
for (y = yFrom; y < yTo; y++) {
522527
for (x = xFrom; x < xTo; x++) {
523-
if (renderedGroups.hasOwnProperty(rawData[y][x].group)) { // recalculate c/r 'span
524-
renderedGroups[rawData[y][x].group].element.colSpan =
525-
x - renderedGroups[rawData[y][x].group].x + 1;
526-
renderedGroups[rawData[y][x].group].element.rowSpan =
527-
y - renderedGroups[rawData[y][x].group].y + 1;
528-
} else { // create element
528+
529+
separatelyGrouped = true;
530+
531+
// setup th
532+
if (rendered = renderedGroups.hasOwnProperty(rawData[y][x].group)) {
533+
//console.log("Already rendered group " + rawData[y][x].group,
534+
// renderedGroups[rawData[y][x].group].element,
535+
// "modifying col/row 'span", "rendered on ("
536+
// + renderedGroups[rawData[y][x].group].x + ";"
537+
// + renderedGroups[rawData[y][x].group].y + "), now on (" +
538+
// + x + "; " + y + ")");
539+
// recalculate c/r 'span
540+
if (x > 0 && rawData[y][x - 1].group === rawData[y][x].group) {
541+
separatelyGrouped = false;
542+
renderedGroups[rawData[y][x].group].element.colSpan =
543+
x - renderedGroups[rawData[y][x].group].x + 1;
544+
}
545+
if (y > 0 && rawData[y - 1][x].group === rawData[y][x].group) {
546+
separatelyGrouped = false;
547+
renderedGroups[rawData[y][x].group].element.rowSpan =
548+
y - renderedGroups[rawData[y][x].group].y + 1;
549+
}
550+
th = renderedGroups[rawData[y][x].group].element;
551+
}
552+
553+
if (!rendered || separatelyGrouped) { // create element
529554
if (!tr) tr = document.createElement("tr");
530555
tr.appendChild(th = document.createElement("th"));
531556
th.textContent = rawData[y][x].value;
532-
if (vertical && x === xTo - 1) {
533-
th.addEventListener(CLICK_EVENT, (function (index, data) {
534-
return function () {
535-
_._rowClickHandler.call(_, index, data);
536-
};
537-
})(y, rawData[y][x]));
538-
}
539557
if (rawData[y][x].group) renderedGroups[rawData[y][x].group] = {
540558
x: x,
541559
y: y,
542560
element: th
543561
};
544562
}
563+
564+
// add listeners
565+
if (vertical && x === xTo - 1) {
566+
th.addEventListener(CLICK_EVENT, (function (index, data) {
567+
return function () {
568+
_._rowClickHandler.call(_, index, data);
569+
};
570+
})(y, rawData[y][x]));
571+
}
572+
if (!vertical && y === yTo - 1 && !th["_hasSortingListener"]) {
573+
th["_hasSortingListener"] = false;
574+
th.addEventListener(CLICK_EVENT, (function (i) {
575+
return function () {
576+
_._columnClickHandler.call(_, i);
577+
};
578+
})(x - info.leftHeaderColumnsNumber));
579+
}
580+
545581
}
546582
if (tr) targetElement.appendChild(tr);
547583
tr = null;

0 commit comments

Comments
 (0)