Skip to content

Commit

Permalink
RowCount control (also option) support
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Dec 30, 2015
1 parent d91a8a7 commit ca20b0b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions export/LightPivotTable-DeepSeePortlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ If LPT has been created before, method fires given callback immidiately.</Descri
controller.setProperty("selectedRange", ss.join("\n"));
}
}
};
// widget controls processing
for (var c in info.controls) {
if (info.controls[c].action === "setRowCount") {
setup.rowCount = info.controls[c].value;
}
}
// Getting filters from controller, if it has filters added from URL or default...
// such filters are marked as "transient"
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "LightPivotTable",
"author": "ZitRo",
"version": "1.4.7",
"version": "1.4.9",
"description": "A lightweight pivot table for MDX2JSON source for InterSystems Cache",
"main": "test/testServer.js",
"repository": {
Expand All @@ -28,7 +28,7 @@
"pivot",
"table",
"data",
"collection",
"mdx",
"visualization"
],
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
[ , showRowNumbers: true ] // show the row number in first column
[ , enableListingSelect: true ] // enable listing selection, true by default
[ , showListingRowsNumber: true ] // show rows number in listing and tables if paginated
[ , rowCount: 5 ] // number of rows to show. Use lp.setRowCount(N) to change rowCount. Manual lp.refresh() needed to apply.
},
lp = new LightPivotTable(setup);

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

// Additional calls:
lp.pivotView.getCellElement(x, y, considerHeaders); // returns cell element by given coordinates
Expand Down
4 changes: 4 additions & 0 deletions source/js/DataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ DataSource.prototype.getCurrentData = function (callback) {
mdx = mdxParser.applyFilter(mdx, this.FILTERS[i]);
}

if (typeof this.GLOBAL_CONFIG.rowCount === "number") {
mdx = mdxParser.applyRowCount(mdx, this.GLOBAL_CONFIG.rowCount);
}

var setupPivotOptions = function () {

var data = ready.pivotData;
Expand Down
10 changes: 10 additions & 0 deletions source/js/LightPivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ LightPivotTable.prototype.changeBasicMDX = function (mdx) {

};

LightPivotTable.prototype.setRowCount = function (n) {

this.CONFIG.rowCount = n;

};

/**
* Returns current mdx including filters.
* @returns {string}
Expand All @@ -101,6 +107,10 @@ LightPivotTable.prototype.getActualMDX = function () {
mdx = mdxParser.applyFilter(mdx, filters[i]);
}

if (typeof this.CONFIG.rowCount === "number") {
mdx = mdxParser.applyRowCount(mdx, this.CONFIG.rowCount);
}

return mdx;

};
Expand Down
19 changes: 16 additions & 3 deletions source/js/MDXParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,22 @@ MDXParser.prototype.prependNonEmpty = function (expression) {
return expression.match(/^\s*non\s+empty/i) ? expression : "NON EMPTY " + expression;
};

/**
* Applies Row Count to mdx.
* Source: SELECT [Test].Members ON 0, NON EMPTY [Test2].Members ON 1 FROM [Tests] %FILTER
* Out: SELECT [Test].Members ON 0, NON EMPTY HEAD([Test2].Members, N) ON 1 FROM [Tests] %FILTER
* @param {string} expression - MDX expression.
* @param {number} n - Number of rows to return.
* @returns {string}
*/
MDXParser.prototype.applyRowCount = function (expression, n) {
return expression.replace(/\s*on\s*0\s*,\s*(?:non\s*empty\s*)?(.*)\s*on\s*1/i, function (a,b) {
return typeof n !== "undefined" ? " ON 0, NON EMPTY HEAD(" + b + ", " + n + ") ON 1" : a;
});
};

/**
* Performs DrillDown on MDX query.
*
* @param {string} mdx
* @param {string} filter
* @param {string} [expression] - if is set, "* ON 1" will be replaced with "{value} ON 1"
Expand All @@ -49,8 +62,8 @@ MDXParser.prototype.prependNonEmpty = function (expression) {
MDXParser.prototype.drillDown = function (mdx, filter, expression) {

if (!filter) {
if (/]\s+ON\s+1/.test(mdx)) {
return mdx = mdx.replace(/]\s+ON\s+1/, "].children ON 1");
if (/]\s+ON\s+1/i.test(mdx)) {
return mdx = mdx.replace(/]\s+ON\s+1/i, "].children ON 1");
} else {
this._warnMDX(mdx, "no filter specified");
return "";
Expand Down
1 change: 1 addition & 0 deletions source/js/PivotView.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ PivotView.prototype.init = function () {
els = this.elements;

els.base.className = "lpt";
els.base.setAttribute("LPTVersion", this.controller.VERSION);
els.container.appendChild(els.base);

this.pushTable();
Expand Down

0 comments on commit ca20b0b

Please sign in to comment.