Skip to content

Commit 6b1efeb

Browse files
column resize feature, IE row sizes fix (experimental), other size fixes
1 parent 2ccf1db commit 6b1efeb

File tree

8 files changed

+124
-19
lines changed

8 files changed

+124
-19
lines changed

example/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
106106
//, cellDrillThrough: function ({Object { event: {event}, filters: {string[]} }}) {}
107107
}
108-
, pagination: 40 // Enables pagination. Pass a number of lines to show by page.
108+
, pagination: 40 // Maximum rows number on one page (default: 200, turn off: 0)
109109
//, hideButtons: true // hides "back" and "drillThrough" buttons
110110
//, triggerEvent: "touchstart" // all "click" events will be replaced by this event
111111
//, caption: "My table" // if set, table basic caption will be replaced by this text
@@ -118,6 +118,7 @@
118118
//, drillDownTarget: "<dashboard name>" // undocumented, deepSee only
119119
//, listingColumnMinWidth: 200 // minimal width of column in listing
120120
//, maxHeaderWidth: 100 // maximum width of header
121+
//, columnResizing: true // make columns resizable (default: true)
121122
};
122123

123124
if (req.DrillDownExpression) { // set custom DrillDown on variant 10

export/LightPivotTable-DeepSeePortlet.xml

Lines changed: 9 additions & 3 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>63578,5953.829232</TimeChanged>
14+
<TimeChanged>63578,68626.779569</TimeChanged>
1515
<TimeCreated>63515,61322.546099</TimeCreated>
1616

1717
<Parameter name="INCLUDEFILES">
@@ -46,6 +46,10 @@
4646
<Type>%Integer</Type>
4747
</Property>
4848

49+
<Property name="ColumnResizing">
50+
<Type>%Boolean</Type>
51+
</Property>
52+
4953
<Method name="%OnGetPortletName">
5054
<ClassMethod>1</ClassMethod>
5155
<ReturnType>%String</ReturnType>
@@ -70,10 +74,11 @@
7074
set pInfo($I(pInfo)) = $LB("DataSource", "/" _ $NAMESPACE, "%String", $$$Text("MDX2JSON source", "%DeepSee"), "Set the URL of MDX2JSON source. Example: ""/SAMPLES""")
7175
set pInfo($I(pInfo)) = $LB("ShowSummary", 1, "%Boolean", $$$Text("Show summary", "%DeepSee"), "Show summary row")
7276
set pInfo($I(pInfo)) = $LB("ExportCSV", 1, "%Boolean", $$$Text("Export to CSV", "%DeepSee"), "Show export to CSV format button")
73-
set pInfo($I(pInfo)) = $LB("Pagination", 0, "%Integer", $$$Text("Pagination", "%DeepSee"), "Enable pagination")
77+
set pInfo($I(pInfo)) = $LB("Pagination", 200, "%Integer", $$$Text("Pagination", "%DeepSee"), "Enable pagination")
7478
set pInfo($I(pInfo)) = $LB("FixTotals", 0, "%Boolean", $$$Text("Fix totals", "%DeepSee"), "Fix totals in header")
7579
set pInfo($I(pInfo)) = $LB("ListingColumnMinWidth", 0, "%Integer", $$$Text("Min cell width for listing", "%DeepSee"), "Minimal column width in listing")
7680
set pInfo($I(pInfo)) = $LB("MaxHeaderWidth", 0, "%Integer", $$$Text("Max column width", "%DeepSee"), "Maximal column width for headers")
81+
set pInfo($I(pInfo)) = $LB("ColumnResizing", 1, "%Boolean", $$$Text("Column resizing", "%DeepSee"), "Allow resizing columns with cursor")
7782
7883
quit $$$OK
7984
]]></Implementation>
@@ -248,6 +253,7 @@
248253
if (info["drillDownDataSource"]) setup["drillDownTarget"] = info["drillDownDataSource"];
249254
setup["showSummary"] = !!parseInt(container.getAttribute("show-summary"));
250255
setup["attachTotals"] = !!parseInt(container.getAttribute("fixTotals"));
256+
setup["columnResizing"] = !!parseInt(container.getAttribute("columnResizing"));
251257
if (parseInt(container.getAttribute("pagination"))) {
252258
setup["pagination"] = parseInt(container.getAttribute("pagination"))
253259
}
@@ -382,7 +388,7 @@
382388
}
383389
384390
&html<
385-
<div session="#(%session.CSPSessionCookie)#" maxHeaderWidth="#(..MaxHeaderWidth)#" listingColumnMinWidth="#(..ListingColumnMinWidth)#" 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%;">
391+
<div columnResizing="#(..ColumnResizing)#" session="#(%session.CSPSessionCookie)#" maxHeaderWidth="#(..MaxHeaderWidth)#" listingColumnMinWidth="#(..ListingColumnMinWidth)#" 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%;">
386392
387393
</div>
388394
>

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

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var setup = { // Object that contain settings. Any setting may be missed.
5252
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
5353
, cellDrillThrough: function ({Object { event: {event}, filters: {string[]}, cellData: {object} }}) {}
5454
} ]
55-
[ , pagination: 30 ] // Enables pagination. Pass a number of lines to show by page.
55+
[ , pagination: 30 ] // Maximum rows number on one page (default: 200, turn off: 0)
5656
[ , hideButtons: true ] // hides "back" and "drillThrough" buttons
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
@@ -65,6 +65,7 @@ var setup = { // Object that contain settings. Any setting may be missed.
6565
[ , drillDownTarget: "<dashboard name>" ] // deepSee only - dashboard to open
6666
[ , listingColumnMinWidth: 200 ] // minimal width of column in listing
6767
[ , maxHeaderWidth: 100 ] // maximum width of header
68+
[ , columnResizing: true ] // make columns resizable (default: true)
6869
},
6970
lp = new LightPivotTable(setup);
7071

source/css/LightPivot.css

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@
217217
}
218218

219219
.lpt-sortDesc:before {
220-
content: " ";
220+
content: "\25bc ";
221221
}
222222

223223
.lpt-sortAsc:before {
224-
content: " ";
224+
content: "\25b2 ";
225225
}
226226

227227
/*.lpt .lpt-leftHeader table {*/
@@ -375,4 +375,19 @@
375375

376376
.lpt .lpt-extraCell {
377377
padding: 0 !important;
378+
}
379+
380+
.lpt-resizableColumn {
381+
position: relative;
382+
}
383+
384+
.lpt-resizableColumn:after {
385+
display: block;
386+
position: absolute;
387+
content: "";
388+
right: -5px;
389+
top: 0;
390+
width: 10px;
391+
cursor: col-resize !important;
392+
height: 100%;
378393
}

source/js/DataController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ DataController.prototype.resetRawData = function () {
445445
}
446446

447447
data.info.topHeaderRowsNumber = xh;
448+
data.info.SUMMARY_SHOWN = false;
448449
data.info.leftHeaderColumnsNumber = yw;
449450
this.SUMMARY_SHOWN = false;
450451
this._dataStack[this._dataStack.length - 1].SUMMARY_SHOWN = false;
@@ -576,7 +577,6 @@ DataController.prototype.sortByColumn = function (columnIndex) {
576577
[data.info.leftHeaderColumnsNumber + columnIndex]
577578
.className = order === 0 ? "" : order === 1 ? "lpt-sortDesc" : "lpt-sortAsc";
578579

579-
580580
this._trigger();
581581

582582
};

source/js/LightPivotTable.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ LightPivotTable.prototype.getPivotProperty = function (path) {
295295
* @param config
296296
*/
297297
LightPivotTable.prototype.normalizeConfiguration = function (config) {
298+
if (typeof config["columnResizing"] === "undefined") config.columnResizing = true;
299+
if (typeof config["pagination"] === "undefined") config.pagination = 200;
298300
if (!config["triggers"]) config.triggers = {};
299301
if (!config["dataSource"]) config.dataSource = {};
300302
};

source/js/PivotView.js

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ var PivotView = function (controller, container) {
3333
y: 0
3434
};
3535

36+
/**
37+
* @type {number[]}
38+
*/
39+
this.FIXED_COLUMN_SIZES = [];
40+
3641
this.PAGINATION_BLOCK_HEIGHT = 20;
3742
this.ANIMATION_TIMEOUT = 500;
3843

@@ -130,7 +135,10 @@ PivotView.prototype.pushTable = function (opts) {
130135
tableElement = document.createElement("div");
131136

132137
tableElement.className = "tableContainer";
133-
if (this.tablesStack.length) tableElement.style.left = "100%";
138+
if (this.tablesStack.length) {
139+
this.tablesStack[this.tablesStack.length - 1].FIXED_COLUMN_SIZES = this.FIXED_COLUMN_SIZES;
140+
tableElement.style.left = "100%";
141+
}
134142

135143
this.tablesStack.push({
136144
element: tableElement,
@@ -143,6 +151,7 @@ PivotView.prototype.pushTable = function (opts) {
143151
}
144152
});
145153

154+
this.FIXED_COLUMN_SIZES = [];
146155
this.elements.base.appendChild(tableElement);
147156
this.elements.tableContainer = tableElement;
148157
this.pagination = pg;
@@ -155,11 +164,16 @@ PivotView.prototype.pushTable = function (opts) {
155164

156165
PivotView.prototype.popTable = function () {
157166

167+
var currentTable;
168+
158169
if (this.tablesStack.length < 2) return;
159170

171+
this.FIXED_COLUMN_SIZES = [];
160172
this._updateTablesPosition(1);
161173
var garbage = this.tablesStack.pop();
162-
this.pagination = this.tablesStack[this.tablesStack.length - 1].pagination;
174+
175+
this.pagination = (currentTable = this.tablesStack[this.tablesStack.length - 1]).pagination;
176+
if (currentTable.FIXED_COLUMN_SIZES) this.FIXED_COLUMN_SIZES = currentTable.FIXED_COLUMN_SIZES;
163177

164178
setTimeout(function () {
165179
garbage.element.parentNode.removeChild(garbage.element);
@@ -446,6 +460,7 @@ PivotView.prototype.recalculateSizes = function (container) {
446460

447461
var _ = this,
448462
CLICK_EVENT = this.controller.CONFIG["triggerEvent"] || "click",
463+
IE_EXTRA_SIZE = window.navigator.userAgent.indexOf("MSIE ") > -1 ? 1/3 : 0,
449464
header = container.getElementsByClassName("lpt-headerValue")[0];
450465

451466
if (!header) { return; } // pivot not ready - nothing to fix
@@ -546,7 +561,9 @@ PivotView.prototype.recalculateSizes = function (container) {
546561
if (pTableHead.childNodes[i].tagName !== "TR") continue;
547562
if (pTableHead.childNodes[i].firstChild) {
548563
pTableHead.childNodes[i].firstChild.style.height =
549-
(columnHeights[i] || columnHeights[i - 1] || DEFAULT_CELL_HEIGHT) + "px";
564+
(columnHeights[i] || columnHeights[i - 1] || DEFAULT_CELL_HEIGHT)
565+
+ IE_EXTRA_SIZE
566+
+ "px";
550567
}
551568
}
552569

@@ -596,15 +613,16 @@ PivotView.prototype.renderRawData = function (data) {
596613
}
597614

598615
var _ = this,
599-
CLICK_EVENT = this.controller.CONFIG["triggerEvent"] || "click",
600-
ATTACH_TOTALS = this.controller.CONFIG["showSummary"]
601-
&& this.controller.CONFIG["attachTotals"] ? 1 : 0,
602-
renderedGroups = {}, // keys of rendered groups; key = group, value = { x, y, element }
603616
rawData = data["rawData"],
604617
info = data["info"],
605618
columnProps = data["columnProps"],
606619
colorScale =
607620
data["conditionalFormatting"] ? data["conditionalFormatting"]["colorScale"] : undefined,
621+
622+
CLICK_EVENT = this.controller.CONFIG["triggerEvent"] || "click",
623+
ATTACH_TOTALS = info.SUMMARY_SHOWN && this.controller.CONFIG["attachTotals"] ? 1 : 0,
624+
COLUMN_RESIZE_ON = !!this.controller.CONFIG.columnResizing,
625+
608626
container = this.elements.tableContainer,
609627
pivotTopSection = document.createElement("div"),
610628
pivotBottomSection = document.createElement("div"),
@@ -622,6 +640,9 @@ PivotView.prototype.renderRawData = function (data) {
622640
pageSwitcher = this.pagination.on ? document.createElement("div") : null,
623641
pageNumbers = this.pagination.on ? [] : null,
624642
pageSwitcherContainer = pageSwitcher ? document.createElement("div") : null,
643+
_RESIZING = false, _RESIZING_ELEMENT = null, _RESIZING_COLUMN_INDEX = 0,
644+
_RESIZING_ELEMENT_BASE_WIDTH, _RESIZING_ELEMENT_BASE_X,
645+
renderedGroups = {}, // keys of rendered groups; key = group, value = { x, y, element }
625646
i, x, y, tr = null, th, td, primaryColumns = [], primaryRows = [], ratio, cellStyle,
626647
tempI, tempJ;
627648

@@ -638,6 +659,58 @@ PivotView.prototype.renderRawData = function (data) {
638659
}
639660
};
640661

662+
var bindResize = function (element, column) {
663+
664+
var el = element,
665+
colIndex = column;
666+
667+
var moveListener = function (e) {
668+
if (!_RESIZING) return;
669+
e.cancelBubble = true;
670+
e.preventDefault();
671+
_RESIZING_ELEMENT.style.width = _RESIZING_ELEMENT.style.minWidth =
672+
_RESIZING_ELEMENT_BASE_WIDTH - _RESIZING_ELEMENT_BASE_X + e.pageX + "px";
673+
};
674+
675+
if (!el._HAS_MOUSE_MOVE_LISTENER) {
676+
el.parentNode.addEventListener("mousemove", moveListener);
677+
el._HAS_MOUSE_MOVE_LISTENER = true;
678+
}
679+
680+
el.addEventListener("mousedown", function (e) {
681+
if (((e.layerX || e.offsetX) < el.offsetWidth - 5) && (e.layerX || e.offsetX) > 5) {
682+
return;
683+
}
684+
e.cancelBubble = true;
685+
e.preventDefault();
686+
_RESIZING = true;
687+
_RESIZING_ELEMENT = el;
688+
_RESIZING_ELEMENT_BASE_WIDTH = el.offsetWidth;
689+
_RESIZING_ELEMENT_BASE_X = e.pageX;
690+
_RESIZING_COLUMN_INDEX = colIndex;
691+
el._CANCEL_CLICK_EVENT = true;
692+
});
693+
694+
el.addEventListener("mouseup", function (e) {
695+
if (!_RESIZING) return;
696+
e.cancelBubble = true;
697+
e.preventDefault();
698+
_RESIZING = false;
699+
_RESIZING_ELEMENT.style.width = _RESIZING_ELEMENT.style.minWidth =
700+
(_.FIXED_COLUMN_SIZES[_RESIZING_COLUMN_INDEX] =
701+
_RESIZING_ELEMENT_BASE_WIDTH - _RESIZING_ELEMENT_BASE_X + e.pageX
702+
) + "px";
703+
_.saveScrollPosition();
704+
_.recalculateSizes(container);
705+
_.restoreScrollPosition();
706+
setTimeout(function () {
707+
_RESIZING_ELEMENT._CANCEL_CLICK_EVENT = false;
708+
_RESIZING_ELEMENT = null;
709+
}, 1);
710+
});
711+
712+
};
713+
641714
// clean previous content
642715
this.removeMessage();
643716
while (container.firstChild) { container.removeChild(container.firstChild); }
@@ -710,15 +783,22 @@ PivotView.prototype.renderRawData = function (data) {
710783
}
711784
if (!vertical && y === yTo - 1 - ATTACH_TOTALS && !th["_hasSortingListener"]) {
712785
th["_hasSortingListener"] = false; // why false?
713-
th.addEventListener(CLICK_EVENT, (function (i) {
786+
th.addEventListener(CLICK_EVENT, (function (i, th) {
714787
return function () {
788+
if (th._CANCEL_CLICK_EVENT) return;
715789
_._columnClickHandler.call(_, i);
716790
};
717-
})(x - info.leftHeaderColumnsNumber));
791+
})(x - info.leftHeaderColumnsNumber, th));
718792
th.className = (th.className || "") + " lpt-clickable";
719793
}
720794
if (!vertical && y === yTo - 1) {
721-
//th["_hasSortingListener"] = false; // why false?
795+
if (_.FIXED_COLUMN_SIZES[x]) {
796+
th.style.minWidth = th.style.width = _.FIXED_COLUMN_SIZES[x] + "px";
797+
}
798+
if (COLUMN_RESIZE_ON) {
799+
bindResize(th, x);
800+
th.className += " lpt-resizableColumn";
801+
}
722802
primaryColumns.push(th);
723803
}
724804

0 commit comments

Comments
 (0)