Skip to content

Commit b46c5a3

Browse files
v23entv23ent
authored andcommitted
Merge branch 'intersystems-ru/master'
2 parents 840e9eb + 09a6a37 commit b46c5a3

File tree

5 files changed

+68
-8
lines changed

5 files changed

+68
-8
lines changed

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<script type="text/javascript" src="../source/js/DataController.js"></script>
1515
<script type="text/javascript" src="../source/js/MDXParser.js"></script>
1616
<script type="text/javascript" src="../source/js/PivotLocale.js"></script>
17-
<script type="text/javascript" src="../source/js/ExcelExport.js"></script>
1817
<!-- endbuild -->
1918
<style>
2019
a {
@@ -115,6 +114,7 @@
115114
// if cellDrillThrough callback returns boolean false, DrillThrough won't be performed.
116115
//, cellDrillThrough: function ({Object { event: {event}, filters: {string[]} }}) {}
117116
//, rowSelect: function (rs) { console.log("Rows: ", rs); }
117+
//, contentRendered: function () { console.log("Rendered, wow!"); }
118118
}
119119
, pagination: 30 // Maximum rows number on one page (default: 200, turn off: 0)
120120
//, hideButtons: true // hides "back" and "drillThrough" buttons

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.2.6",
4+
"version": "1.2.8",
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
@@ -53,6 +53,7 @@ var setup = { // Object that contain settings. Properties in brackets can be mis
5353
, cellDrillThrough: function ({Object { event: {event}, filters: {string[]}, cellData: {object} }}) {}
5454
, responseHandler: function ({Object {url: {string}, status: {number}}}) {}
5555
, rowSelect: function ({Array}) {}
56+
, contentRendered: function () {}
5657
} ]
5758
[ , pagination: 30 ] // Maximum rows number on one page (default: 200, turn off: 0)
5859
[ , hideButtons: true ] // hides "back" and "drillThrough" buttons

source/js/DataController.js

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ DataController.prototype.setData = function (data) {
101101
this.resetConditionalFormatting();
102102
this.resetRawData();
103103
this.modifyRawData(data);
104+
this.postDataProcessing(data);
104105

105106
if (data.info.mdxType === "drillthrough") {
106107
this.setDrillThroughHandler(function (params) {
@@ -167,6 +168,51 @@ DataController.prototype.resetDimensionProps = function () {
167168

168169
};
169170

171+
/**
172+
* Try to recognise type by given value.
173+
* @param {*} value
174+
*/
175+
DataController.prototype.getTypeByValue = function (value) {
176+
177+
if (!isNaN(value)) {
178+
return { type: "number" };
179+
} else if ((value + "").match(/[0-9]{2}\.[0-9]{2}\.[0-9]{2,4}/)) { // local date (unique case for RU)
180+
return {
181+
type: "date",
182+
comparator: function (value) {
183+
var arr = value.split(".");
184+
return new Date(arr[2], arr[1], arr[0]); // day
185+
}
186+
};
187+
} else if (Date.parse(value)) { // standard date recognized by JS
188+
return {
189+
type: "date",
190+
comparator: function (value) {
191+
return new Date(value);
192+
}
193+
}
194+
} else {
195+
return { type: "string" };
196+
}
197+
198+
};
199+
200+
DataController.prototype.postDataProcessing = function (data) {
201+
202+
var cell, col;
203+
204+
if (!data || !data.rawData || !data.rawData[data.info.topHeaderRowsNumber]) return;
205+
if (!data.columnProps) data.columnProps = [];
206+
207+
// Inserts pseudo-type to cell. If data.columnProps[col]["$FORMAT"].comparator is a function, then this function
208+
// will be used to sort value of columns. @see DataController.sortByColumn.
209+
for (col = data.info.leftHeaderColumnsNumber; cell = data.rawData[data.info.topHeaderRowsNumber][col]; col++) {
210+
if (!data.columnProps[col]) data.columnProps[col] = {};
211+
data.columnProps[col]["$FORMAT"] = this.getTypeByValue(cell.value);
212+
}
213+
214+
};
215+
170216
DataController.prototype.resetConditionalFormatting = function () {
171217

172218
var data, cs, c1, c2, arr, min, max,
@@ -568,7 +614,8 @@ DataController.prototype._trigger = function () {
568614
DataController.prototype.sortByColumn = function (columnIndex) {
569615

570616
var data = this._dataStack[this._dataStack.length - 1].data,
571-
totalsAttached = this.SUMMARY_SHOWN && this.controller.CONFIG["attachTotals"] ? 1 : 0;
617+
totalsAttached = this.SUMMARY_SHOWN && this.controller.CONFIG["attachTotals"] ? 1 : 0,
618+
comparator;
572619

573620
if (this.SORT_STATE.column !== columnIndex) {
574621
order = this.SORT_STATE.order = 0;
@@ -599,11 +646,19 @@ DataController.prototype.sortByColumn = function (columnIndex) {
599646

600647
order = -order;
601648

602-
newRawData.sort(function (a, b) {
603-
if (b[xIndex].value > a[xIndex].value) return order;
604-
if (b[xIndex].value < a[xIndex].value) return -order;
605-
return 0;
606-
});
649+
if (typeof (comparator = ((data.columnProps[columnIndex] || {})["$FORMAT"] || {}).comparator) === "function") {
650+
newRawData.sort(function (a, b) { // sort using comparator function
651+
if (comparator(b[xIndex].value) > comparator(a[xIndex].value)) return order;
652+
if (comparator(b[xIndex].value) < comparator(a[xIndex].value)) return -order;
653+
return 0;
654+
});
655+
} else { // simple sort
656+
newRawData.sort(function (a, b) {
657+
if (b[xIndex].value > a[xIndex].value) return order;
658+
if (b[xIndex].value < a[xIndex].value) return -order;
659+
return 0;
660+
});
661+
}
607662

608663
data.rawData = data._rawDataOrigin.slice(0, data.info.topHeaderRowsNumber)
609664
.concat(newRawData)

source/js/PivotView.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,4 +1236,8 @@ PivotView.prototype.renderRawData = function (data) {
12361236
setCaretPosition(this.elements.searchInput, this.savedSearch.value.length);
12371237
}
12381238

1239+
if (typeof this.controller.CONFIG.triggers.contentRendered === "function") {
1240+
this.controller.CONFIG.triggers.contentRendered();
1241+
}
1242+
12391243
};

0 commit comments

Comments
 (0)