Skip to content

Commit ca20b0b

Browse files
RowCount control (also option) support
1 parent d91a8a7 commit ca20b0b

7 files changed

+41
-5
lines changed

export/LightPivotTable-DeepSeePortlet.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ If LPT has been created before, method fires given callback immidiately.</Descri
286286
controller.setProperty("selectedRange", ss.join("\n"));
287287
}
288288
}
289+
};
290+
// widget controls processing
291+
for (var c in info.controls) {
292+
if (info.controls[c].action === "setRowCount") {
293+
setup.rowCount = info.controls[c].value;
294+
}
289295
}
290296
// Getting filters from controller, if it has filters added from URL or default...
291297
// such filters are marked as "transient"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "LightPivotTable",
33
"author": "ZitRo",
4-
"version": "1.4.7",
4+
"version": "1.4.9",
55
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
66
"main": "test/testServer.js",
77
"repository": {
@@ -28,7 +28,7 @@
2828
"pivot",
2929
"table",
3030
"data",
31-
"collection",
31+
"mdx",
3232
"visualization"
3333
],
3434
"dependencies": {

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
7878
[ , showRowNumbers: true ] // show the row number in first column
7979
[ , enableListingSelect: true ] // enable listing selection, true by default
8080
[ , showListingRowsNumber: true ] // show rows number in listing and tables if paginated
81+
[ , rowCount: 5 ] // number of rows to show. Use lp.setRowCount(N) to change rowCount. Manual lp.refresh() needed to apply.
8182
},
8283
lp = new LightPivotTable(setup);
8384

@@ -96,6 +97,7 @@ lp.changeBasicMDX("..."); // change mdx for LPT
9697
lp.getActualMDX(); // returns currently displayed MDX
9798
lp.getSelectedRows(); // returns array with selected rows indexes. First row have index 1.
9899
lp.attachTrigger("contentRendered", function (lpInstance) { }); // attaches trigger during runtime
100+
lp.setRowCount(5); // sets the number of rows to display
99101

100102
// Additional calls:
101103
lp.pivotView.getCellElement(x, y, considerHeaders); // returns cell element by given coordinates

source/js/DataSource.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ DataSource.prototype.getCurrentData = function (callback) {
148148
mdx = mdxParser.applyFilter(mdx, this.FILTERS[i]);
149149
}
150150

151+
if (typeof this.GLOBAL_CONFIG.rowCount === "number") {
152+
mdx = mdxParser.applyRowCount(mdx, this.GLOBAL_CONFIG.rowCount);
153+
}
154+
151155
var setupPivotOptions = function () {
152156

153157
var data = ready.pivotData;

source/js/LightPivotTable.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ LightPivotTable.prototype.changeBasicMDX = function (mdx) {
8686

8787
};
8888

89+
LightPivotTable.prototype.setRowCount = function (n) {
90+
91+
this.CONFIG.rowCount = n;
92+
93+
};
94+
8995
/**
9096
* Returns current mdx including filters.
9197
* @returns {string}
@@ -101,6 +107,10 @@ LightPivotTable.prototype.getActualMDX = function () {
101107
mdx = mdxParser.applyFilter(mdx, filters[i]);
102108
}
103109

110+
if (typeof this.CONFIG.rowCount === "number") {
111+
mdx = mdxParser.applyRowCount(mdx, this.CONFIG.rowCount);
112+
}
113+
104114
return mdx;
105115

106116
};

source/js/MDXParser.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,22 @@ MDXParser.prototype.prependNonEmpty = function (expression) {
3838
return expression.match(/^\s*non\s+empty/i) ? expression : "NON EMPTY " + expression;
3939
};
4040

41+
/**
42+
* Applies Row Count to mdx.
43+
* Source: SELECT [Test].Members ON 0, NON EMPTY [Test2].Members ON 1 FROM [Tests] %FILTER
44+
* Out: SELECT [Test].Members ON 0, NON EMPTY HEAD([Test2].Members, N) ON 1 FROM [Tests] %FILTER
45+
* @param {string} expression - MDX expression.
46+
* @param {number} n - Number of rows to return.
47+
* @returns {string}
48+
*/
49+
MDXParser.prototype.applyRowCount = function (expression, n) {
50+
return expression.replace(/\s*on\s*0\s*,\s*(?:non\s*empty\s*)?(.*)\s*on\s*1/i, function (a,b) {
51+
return typeof n !== "undefined" ? " ON 0, NON EMPTY HEAD(" + b + ", " + n + ") ON 1" : a;
52+
});
53+
};
54+
4155
/**
4256
* Performs DrillDown on MDX query.
43-
*
4457
* @param {string} mdx
4558
* @param {string} filter
4659
* @param {string} [expression] - if is set, "* ON 1" will be replaced with "{value} ON 1"
@@ -49,8 +62,8 @@ MDXParser.prototype.prependNonEmpty = function (expression) {
4962
MDXParser.prototype.drillDown = function (mdx, filter, expression) {
5063

5164
if (!filter) {
52-
if (/]\s+ON\s+1/.test(mdx)) {
53-
return mdx = mdx.replace(/]\s+ON\s+1/, "].children ON 1");
65+
if (/]\s+ON\s+1/i.test(mdx)) {
66+
return mdx = mdx.replace(/]\s+ON\s+1/i, "].children ON 1");
5467
} else {
5568
this._warnMDX(mdx, "no filter specified");
5669
return "";

source/js/PivotView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ PivotView.prototype.init = function () {
9191
els = this.elements;
9292

9393
els.base.className = "lpt";
94+
els.base.setAttribute("LPTVersion", this.controller.VERSION);
9495
els.container.appendChild(els.base);
9596

9697
this.pushTable();

0 commit comments

Comments
 (0)