@@ -101,6 +101,7 @@ DataController.prototype.setData = function (data) {
101
101
this . resetConditionalFormatting ( ) ;
102
102
this . resetRawData ( ) ;
103
103
this . modifyRawData ( data ) ;
104
+ this . postDataProcessing ( data ) ;
104
105
105
106
if ( data . info . mdxType === "drillthrough" ) {
106
107
this . setDrillThroughHandler ( function ( params ) {
@@ -167,6 +168,51 @@ DataController.prototype.resetDimensionProps = function () {
167
168
168
169
} ;
169
170
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
+
170
216
DataController . prototype . resetConditionalFormatting = function ( ) {
171
217
172
218
var data , cs , c1 , c2 , arr , min , max ,
@@ -568,7 +614,8 @@ DataController.prototype._trigger = function () {
568
614
DataController . prototype . sortByColumn = function ( columnIndex ) {
569
615
570
616
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 ;
572
619
573
620
if ( this . SORT_STATE . column !== columnIndex ) {
574
621
order = this . SORT_STATE . order = 0 ;
@@ -599,11 +646,19 @@ DataController.prototype.sortByColumn = function (columnIndex) {
599
646
600
647
order = - order ;
601
648
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
+ }
607
662
608
663
data . rawData = data . _rawDataOrigin . slice ( 0 , data . info . topHeaderRowsNumber )
609
664
. concat ( newRawData )
0 commit comments