@@ -289,11 +289,13 @@ PivotView.prototype._drillThroughClickHandler = function (event) {
289289PivotView . prototype . _cellClickHandler = function ( cell , x , y , event , drillThroughHandler ) {
290290
291291 var data = this . controller . dataController . getData ( ) ,
292- f = [ ] , f1 , f2 , callbackRes = true ;
292+ f = [ ] , f1 , f2 , callbackRes = true ,
293+ ATTACH_TOTALS = this . controller . CONFIG [ "showSummary" ]
294+ && this . controller . CONFIG [ "attachTotals" ] ? 1 : 0 ;
293295
294296 try {
295297 f1 = data . rawData [ y ] [ data . info . leftHeaderColumnsNumber - 1 ] . source . path ;
296- f2 = data . rawData [ data . info . topHeaderRowsNumber - 1 ] [ x ] . source . path ;
298+ f2 = data . rawData [ data . info . topHeaderRowsNumber - 1 - ATTACH_TOTALS ] [ x ] . source . path ;
297299 } catch ( e ) {
298300 console . warn ( "Unable to get filters for cell (%d, %d)" , x , y ) ;
299301 }
@@ -600,6 +602,8 @@ PivotView.prototype.renderRawData = function (data) {
600602
601603 var _ = this ,
602604 CLICK_EVENT = this . controller . CONFIG [ "triggerEvent" ] || "click" ,
605+ ATTACH_TOTALS = this . controller . CONFIG [ "showSummary" ]
606+ && this . controller . CONFIG [ "attachTotals" ] ? 1 : 0 ,
603607 renderedGroups = { } , // keys of rendered groups; key = group, value = { x, y, element }
604608 rawData = data [ "rawData" ] ,
605609 info = data [ "info" ] ,
@@ -626,6 +630,19 @@ PivotView.prototype.renderRawData = function (data) {
626630 i , x , y , tr = null , th , td , primaryColumns = [ ] , primaryRows = [ ] , ratio , cellStyle ,
627631 tempI , tempJ ;
628632
633+ var formatContent = function ( value , element , format ) {
634+ if ( ! isFinite ( value ) ) {
635+ element . className += " formatLeft" ;
636+ element . textContent = value || "" ;
637+ } else { // number
638+ if ( format ) {
639+ element . textContent = value ? _ . numeral ( value ) . format ( format ) : "" ;
640+ } else {
641+ element . textContent = value || "" ;
642+ }
643+ }
644+ } ;
645+
629646 // clean previous content
630647 this . removeMessage ( ) ;
631648 while ( container . firstChild ) { container . removeChild ( container . firstChild ) ; }
@@ -657,7 +674,9 @@ PivotView.prototype.renderRawData = function (data) {
657674
658675 if ( ! rendered || separatelyGrouped ) { // create element
659676 if ( ! tr ) tr = document . createElement ( "tr" ) ;
660- tr . appendChild ( th = document . createElement ( "th" ) ) ;
677+ tr . appendChild (
678+ th = document . createElement ( rawData [ y ] [ x ] . isCaption ? "th" : "td" )
679+ ) ;
661680 th . textContent = rawData [ y ] [ x ] . value || " " ;
662681 if ( rawData [ y ] [ x ] . style ) th . setAttribute ( "style" , rawData [ y ] [ x ] . style ) ;
663682 if ( rawData [ y ] [ x ] . className ) th . className = rawData [ y ] [ x ] . className ;
@@ -666,6 +685,11 @@ PivotView.prototype.renderRawData = function (data) {
666685 y : y ,
667686 element : th
668687 } ;
688+ if ( ! rawData [ y ] [ x ] . isCaption ) formatContent (
689+ rawData [ y ] [ x ] . value ,
690+ th ,
691+ columnProps [ x - info . leftHeaderColumnsNumber ] . format
692+ ) ;
669693 }
670694
671695 // add listeners
@@ -677,14 +701,18 @@ PivotView.prototype.renderRawData = function (data) {
677701 } ;
678702 } ) ( y , rawData [ y ] [ x ] ) ) ;
679703 }
680- if ( ! vertical && y === yTo - 1 && ! th [ "_hasSortingListener" ] ) {
681- th [ "_hasSortingListener" ] = false ;
682- primaryColumns . push ( th ) ;
704+ if ( ! vertical && y === yTo - 1 - ATTACH_TOTALS && ! th [ "_hasSortingListener" ] ) {
705+ th [ "_hasSortingListener" ] = false ; // why false?
683706 th . addEventListener ( CLICK_EVENT , ( function ( i ) {
684707 return function ( ) {
685708 _ . _columnClickHandler . call ( _ , i ) ;
686709 } ;
687710 } ) ( x - info . leftHeaderColumnsNumber ) ) ;
711+ th . className = ( th . className || "" ) + " lpt-clickable" ;
712+ }
713+ if ( ! vertical && y === yTo - 1 ) {
714+ //th["_hasSortingListener"] = false; // why false?
715+ primaryColumns . push ( th ) ;
688716 }
689717
690718 }
@@ -732,24 +760,17 @@ PivotView.prototype.renderRawData = function (data) {
732760 ) ;
733761
734762 // render table
735- for ( y = tempI /*info.topHeaderRowsNumber*/ ; y < tempJ /*rawData.length*/ ; y ++ ) {
763+ for ( y = tempI ; y < tempJ ; y ++ ) {
736764 tr = document . createElement ( "tr" ) ;
737765 for ( x = info . leftHeaderColumnsNumber ; x < rawData [ 0 ] . length ; x ++ ) {
738766
739767 cellStyle = "" ;
740768 tr . appendChild ( td = document . createElement ( "td" ) ) ;
741- if ( ! isFinite ( rawData [ y ] [ x ] . value ) ) {
742- td . className += " formatLeft" ;
743- td . textContent = rawData [ y ] [ x ] . value || "" ;
744- } else { // number
745- if ( columnProps [ x - info . leftHeaderColumnsNumber ] . format ) {
746- td . textContent = rawData [ y ] [ x ] . value ? this . numeral ( rawData [ y ] [ x ] . value ) . format (
747- columnProps [ x - info . leftHeaderColumnsNumber ] . format
748- ) : "" ;
749- } else {
750- td . textContent = rawData [ y ] [ x ] . value || "" ;
751- }
752- }
769+ formatContent (
770+ rawData [ y ] [ x ] . value ,
771+ td ,
772+ columnProps [ x - info . leftHeaderColumnsNumber ] . format
773+ ) ;
753774 if (
754775 colorScale
755776 && ! ( info . SUMMARY_SHOWN && rawData . length - 1 === y ) // exclude totals formatting
0 commit comments