@@ -295,59 +295,78 @@ DataController.prototype.TOTAL_FUNCTIONS = {
295
295
return isFinite ( a ) ;
296
296
} ,
297
297
298
- totalSUM : function ( array , iStart , iEnd , column ) {
298
+ totalSUM : function ( array , iStart , iEnd , column , xStart , row ) {
299
299
var sum = 0 ;
300
300
for ( var i = iStart ; i < iEnd ; i ++ ) {
301
- if ( this . isNumber ( array [ i ] [ column ] [ "value" ] ) ) {
302
- sum += parseFloat ( array [ i ] [ column ] [ "value" ] ) || 0 ;
301
+ var r = typeof row === "undefined" ? i : row ,
302
+ c = typeof column === "undefined" ? i : column ;
303
+ if ( this . isNumber ( array [ r ] [ c ] [ "value" ] ) ) {
304
+ sum += parseFloat ( array [ r ] [ c ] [ "value" ] ) || 0 ;
303
305
}
304
306
}
305
307
return sum ;
306
308
} ,
307
309
308
- totalAVG : function ( array , iStart , iEnd , column ) {
310
+ totalAVG : function ( array , iStart , iEnd , column , xStart , row ) {
309
311
var sum = 0 ;
310
312
for ( var i = iStart ; i < iEnd ; i ++ ) {
311
- if ( ! this . isNumber ( array [ i ] [ column ] [ "value" ] ) ) {
313
+ var r = typeof row === "undefined" ? i : row ,
314
+ c = typeof column === "undefined" ? i : column ;
315
+ if ( ! this . isNumber ( array [ r ] [ c ] [ "value" ] ) ) {
312
316
sum = 0 ;
313
317
break ;
314
318
}
315
- sum += parseFloat ( array [ i ] [ column ] [ "value" ] ) || 0 ;
319
+ sum += parseFloat ( array [ r ] [ c ] [ "value" ] ) || 0 ;
316
320
}
317
321
return sum / ( iEnd - iStart ) || "" ;
318
322
} ,
319
323
320
- totalCOUNT : function ( array , iStart , iEnd ) {
321
- return iEnd - iStart ;
324
+ totalCOUNT : function ( array , iStart , iEnd , column , xStart , row ) {
325
+ var count = 0 ;
326
+ for ( var i = iStart ; i < iEnd ; i ++ ) {
327
+ var r = typeof row === "undefined" ? i : row ,
328
+ c = typeof column === "undefined" ? i : column ;
329
+ if ( array [ r ] [ c ] [ "value" ] ) {
330
+ count ++ ;
331
+ }
332
+ }
333
+ return count ;
322
334
} ,
323
335
324
- totalMIN : function ( array , iStart , iEnd , column ) {
336
+ totalMIN : function ( array , iStart , iEnd , column , xStart , row ) {
325
337
var min = Infinity ;
326
338
for ( var i = iStart ; i < iEnd ; i ++ ) {
327
- if ( this . isNumber ( array [ i ] [ column ] [ "value" ] ) && array [ i ] [ column ] [ "value" ] < min ) {
328
- min = array [ i ] [ column ] [ "value" ] ;
339
+ var r = typeof row === "undefined" ? i : row ,
340
+ c = typeof column === "undefined" ? i : column ;
341
+ if ( this . isNumber ( array [ r ] [ c ] [ "value" ] ) && array [ r ] [ c ] [ "value" ] < min ) {
342
+ min = array [ r ] [ c ] [ "value" ] ;
329
343
}
330
344
}
331
345
return min ;
332
346
} ,
333
347
334
- totalMAX : function ( array , iStart , iEnd , column ) {
348
+ totalMAX : function ( array , iStart , iEnd , column , xStart , row ) {
335
349
var max = - Infinity ;
336
350
for ( var i = iStart ; i < iEnd ; i ++ ) {
337
- if ( this . isNumber ( array [ i ] [ column ] [ "value" ] ) && array [ i ] [ column ] [ "value" ] > max ) {
338
- max = array [ i ] [ column ] [ "value" ] ;
351
+ var r = typeof row === "undefined" ? i : row ,
352
+ c = typeof column === "undefined" ? i : column ;
353
+ if ( this . isNumber ( array [ r ] [ c ] [ "value" ] ) && array [ r ] [ c ] [ "value" ] > max ) {
354
+ max = array [ r ] [ c ] [ "value" ] ;
339
355
}
340
356
}
341
357
return max ;
342
358
} ,
343
359
344
- totalPERCENTAGE : function ( array , iStart , iEnd , column , xStart ) {
360
+ totalPERCENTAGE : function ( array , iStart , iEnd , column , xStart , row ) {
345
361
var averages = [ ] , x , summ ;
346
- for ( x = xStart ; x < array [ 0 ] . length ; x ++ ) {
347
- averages . push ( this . totalSUM ( array , iStart , iEnd , x ) ) ;
362
+ for ( x = xStart ; x < typeof column === "undefined" ? array . length : array [ 0 ] . length ; x ++ ) {
363
+ averages . push ( this . totalSUM ( array , iStart , iEnd ,
364
+ typeof column === "undefined" ? column : x , xStart ,
365
+ typeof row === "undefined" ? row : x ) ) ;
348
366
}
349
367
summ = averages . reduce ( function ( a , b ) { return a + b ; } ) ;
350
- return ( averages [ column - xStart ] / summ * 100 || 0 ) . toFixed ( 2 ) + "%" ;
368
+ return ( averages [ ( typeof row === "undefined" ? column : row ) - xStart ]
369
+ / summ * 100 || 0 ) . toFixed ( 2 ) + "%" ;
351
370
} ,
352
371
353
372
totalNONE : function ( ) {
@@ -378,6 +397,8 @@ DataController.prototype.setLeftHeaderColumnsNumber = function (data) {
378
397
*/
379
398
DataController . prototype . resetRawData = function ( ) {
380
399
400
+ var TOTALS_STYLE = "font-weight: bold;text-align: right;" ;
401
+
381
402
var data , summary , y , x ,
382
403
dimCaption ,
383
404
_ = this ;
@@ -579,13 +600,16 @@ DataController.prototype.resetRawData = function () {
579
600
580
601
/**
581
602
* @param {number } columnIndex
603
+ * @param {boolean=false } byColumns
582
604
* @returns {Function }
583
605
*/
584
- var getTotalFunction = function ( columnIndex ) {
585
- var pivotDefault = _ . controller . getPivotProperty ( [ "rowTotalAgg" ] ) ;
586
- if ( ! data [ "columnProps" ] [ columnIndex ] && ! pivotDefault )
606
+ var getTotalFunction = function ( columnIndex , byColumns ) {
607
+ var pivotDefault = _ . controller . getPivotProperty ( [ "rowTotalAgg" ] ) || "sum" ,
608
+ pivotDefaultCol = _ . controller . getPivotProperty ( [ "columnTotalAgg" ] ) || "sum" ,
609
+ props = byColumns ? "rowProps" : "columnProps" ;
610
+ if ( ! data [ props ] [ columnIndex ] && ! ( byColumns ? pivotDefaultCol : pivotDefault ) )
587
611
return _ . TOTAL_FUNCTIONS . totalSUM ;
588
- switch ( ( data [ "columnProps" ] [ columnIndex ] || { } ) . summary || pivotDefault ) {
612
+ switch ( ( data [ props ] [ columnIndex ] || { } ) . summary || pivotDefault ) {
589
613
case "count" : return _ . TOTAL_FUNCTIONS . totalCOUNT ;
590
614
case "avg" : return _ . TOTAL_FUNCTIONS . totalAVG ;
591
615
case "min" : return _ . TOTAL_FUNCTIONS . totalMIN ;
@@ -596,7 +620,7 @@ DataController.prototype.resetRawData = function () {
596
620
}
597
621
} ;
598
622
599
- if ( this . controller . CONFIG [ "showSummary" ] && rawData . length - xh > 1 // xh - see above
623
+ if ( this . controller . CONFIG [ "showSummary" ] && rawData . length - data . info . topHeaderRowsNumber > 1
600
624
&& ( rawData [ rawData . length - 1 ] [ 0 ] || { } ) [ "isCaption" ] ) {
601
625
data . info . SUMMARY_SHOWN = true ;
602
626
this . SUMMARY_SHOWN = true ;
@@ -619,7 +643,7 @@ DataController.prototype.resetRawData = function () {
619
643
this . TOTAL_FUNCTIONS ,
620
644
rawData , xh , rawData . length , i , data . info . leftHeaderColumnsNumber
621
645
) ,
622
- style : "font-weight: bold;text-align: right;"
646
+ style : TOTALS_STYLE
623
647
}
624
648
}
625
649
}
@@ -632,6 +656,31 @@ DataController.prototype.resetRawData = function () {
632
656
}
633
657
}
634
658
659
+ if ( this . controller . getPivotProperty ( [ "columnTotals" ] )
660
+ && rawData . length - data . info . topHeaderRowsNumber > 1
661
+ && data . info . leftHeaderColumnsNumber > 0 ) {
662
+ var group = ++ groupNum ,
663
+ row ;
664
+ for ( row = 0 ; row < data . info . topHeaderRowsNumber ; row ++ ) {
665
+ rawData [ row ] . push ( {
666
+ group : group ,
667
+ isCaption : true ,
668
+ value : pivotLocale . get ( 0 )
669
+ } ) ;
670
+ }
671
+ for ( row = data . info . topHeaderRowsNumber ; row < rawData . length ; row ++ ) {
672
+ rawData [ row ] . push ( {
673
+ isCaption : true ,
674
+ value : getTotalFunction ( row , true ) . call (
675
+ this . TOTAL_FUNCTIONS ,
676
+ rawData , data . info . leftHeaderColumnsNumber , rawData [ row ] . length , undefined ,
677
+ data . info . leftHeaderColumnsNumber , row
678
+ ) ,
679
+ style : TOTALS_STYLE
680
+ } ) ;
681
+ }
682
+ }
683
+
635
684
rawData = parseColumnFormatting ( rawData ) ;
636
685
637
686
data . rawData = data . _rawDataOrigin = rawData ;
0 commit comments