@@ -31,12 +31,12 @@ import {
3131} from '@angular/core' ;
3232import { DOCUMENT , NgTemplateOutlet , NgClass , NgStyle } from '@angular/common' ;
3333
34- import { first , take , takeUntil } from 'rxjs/operators' ;
34+ import { first , take , takeUntil } from 'rxjs/operators' ;
3535import { IgxGridBaseDirective } from '../grid-base.directive' ;
3636import { IgxFilteringService } from '../filtering/grid-filtering.service' ;
3737import { IgxGridSelectionService } from '../selection/selection.service' ;
3838import { IgxForOfSyncService , IgxForOfScrollSyncService } from '../../directives/for-of/for_of.sync.service' ;
39- import { ColumnType , GridType , IGX_GRID_BASE , IGX_GRID_SERVICE_BASE , IgxColumnTemplateContext , RowType } from '../common/grid.interface' ;
39+ import { ColumnType , GridType , IGX_GRID_BASE , IGX_GRID_SERVICE_BASE , IgxColumnTemplateContext , PivotGridType , RowType } from '../common/grid.interface' ;
4040import { IgxGridCRUDService } from '../common/crud.service' ;
4141import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
4242import { DEFAULT_PIVOT_KEYS , IDimensionsChange , IgxPivotGridValueTemplateContext , IPivotConfiguration , IPivotConfigurationChangedEventArgs , IPivotDimension , IPivotValue , IValuesChange , PivotDimensionType , IPivotUISettings , PivotRowLayoutType , PivotSummaryPosition } from './pivot-grid.interface' ;
@@ -71,7 +71,7 @@ import { IgxPivotColumnResizingService } from '../resizing/pivot-grid/pivot-resi
7171import { IgxFlatTransactionFactory , IgxOverlayService , State , Transaction , TransactionService } from '../../services/public_api' ;
7272import { cloneArray , PlatformUtil , resizeObservable } from '../../core/utils' ;
7373import { IgxPivotFilteringService } from './pivot-filtering.service' ;
74- import { DataUtil } from '../../data-operations/data-util' ;
74+ import { DataUtil , GridColumnDataType } from '../../data-operations/data-util' ;
7575import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
7676import { IgxGridTransaction } from '../common/types' ;
7777import { GridBaseAPIService } from '../api.service' ;
@@ -198,7 +198,7 @@ const MINIMUM_COLUMN_WIDTH_SUPER_COMPACT = 104;
198198 schemas : [ CUSTOM_ELEMENTS_SCHEMA ]
199199} )
200200export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnInit , AfterContentInit ,
201- GridType , AfterViewInit , OnChanges {
201+ PivotGridType , AfterViewInit , OnChanges {
202202
203203 /**
204204 * Emitted when the dimension collection is changed via the grid chip area.
@@ -1666,7 +1666,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
16661666 public autoSizeRowDimension ( dimension : IPivotDimension ) {
16671667 if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
16681668 const relatedDims : string [ ] = PivotUtil . flatten ( [ dimension ] ) . map ( ( x : IPivotDimension ) => x . memberName ) ;
1669- const contentCollection = this . getContentCollection ( dimension ) ;
1669+ const contentCollection = this . getContentCollection ( dimension ) ;
16701670 const content = contentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
16711671 const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
16721672 if ( this . pivotUI . showRowHeaders ) {
@@ -1940,8 +1940,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
19401940 */
19411941 public getRowDimensionByName ( memberName : string ) {
19421942 const visibleRows = this . pivotUI . rowLayout === PivotRowLayoutType . Vertical ?
1943- this . pivotConfiguration . rows :
1944- PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
1943+ this . pivotConfiguration . rows :
1944+ PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
19451945 const dimIndex = visibleRows . findIndex ( ( target ) => target . memberName === memberName ) ;
19461946 const dim = visibleRows [ dimIndex ] ;
19471947 return dim ;
@@ -2265,7 +2265,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
22652265 const separator = this . pivotKeys . columnDimensionSeparator ;
22662266 const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
22672267 const hierarchy = new Map < string , any > ( ) ;
2268- const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2268+ const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
22692269 dataArr . forEach ( arr => {
22702270 let currentHierarchy = hierarchy ;
22712271 const path = [ ] ;
@@ -2285,17 +2285,22 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
22852285 } ) ;
22862286 return hierarchy ;
22872287 }
2288-
22892288 protected generateColumnHierarchy ( fields : Map < string , any > , data , parent = null ) : IgxColumnComponent [ ] {
22902289 let columns = [ ] ;
22912290 if ( fields . size === 0 ) {
22922291 this . values . forEach ( ( value ) => {
22932292 const ref = createComponent ( IgxColumnComponent , { environmentInjector : this . envInjector , elementInjector : this . injector } ) ;
2293+ let columnDataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2294+
2295+ if ( value . aggregate ?. key ?. toLowerCase ( ) === 'count' && ( columnDataType === GridColumnDataType . Currency || columnDataType == GridColumnDataType . Percent ) ) {
2296+ columnDataType = GridColumnDataType . Number ;
2297+ }
2298+
22942299 ref . instance . header = value . displayName ;
22952300 ref . instance . field = value . member ;
22962301 ref . instance . parent = parent ;
22972302 ref . instance . sortable = true ;
2298- ref . instance . dataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2303+ ref . instance . dataType = columnDataType ;
22992304 ref . instance . formatter = value . formatter ;
23002305 columns . push ( ref . instance ) ;
23012306 } ) ;
@@ -2309,9 +2314,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23092314 }
23102315 if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
23112316 const col = this . createColumnForDimension ( value , data , parent , this . hasMultipleValues ) ;
2317+
2318+ if ( ! this . hasMultipleValues && this . values . length > 0 ) {
2319+ PivotUtil . updateColumnTypeByAggregator ( [ col ] , this . values [ 0 ] , true ) ;
2320+ }
2321+
23122322 columns . push ( col ) ;
23132323 if ( this . hasMultipleValues ) {
23142324 const measureChildren = this . getMeasureChildren ( data , col , false , value . dimension . width ) ;
2325+
2326+ measureChildren . forEach ( ( child , index ) => {
2327+ const pivotValue = this . values [ index ] ;
2328+ PivotUtil . updateColumnTypeByAggregator ( [ child ] , pivotValue , this . values . length === 1 ) ;
2329+ } ) ;
2330+
23152331 col . children . reset ( measureChildren ) ;
23162332 columns = columns . concat ( measureChildren ) ;
23172333 }
@@ -2381,20 +2397,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23812397 } ;
23822398 values . push ( value ) ;
23832399 break ;
2384- }
2385- case "date" :
2386- {
2387- const dimension : IPivotDimension = new IgxPivotDateDimension (
2400+ }
2401+ case "date" :
23882402 {
2389- memberName : field ,
2390- enabled : isFirstDate ,
2391- dataType : dataType
2403+ const dimension : IPivotDimension = new IgxPivotDateDimension (
2404+ {
2405+ memberName : field ,
2406+ enabled : isFirstDate ,
2407+ dataType : dataType
2408+ }
2409+ )
2410+ rowDimensions . push ( dimension ) ;
2411+ isFirstDate = false ;
2412+ break ;
23922413 }
2393- )
2394- rowDimensions . push ( dimension ) ;
2395- isFirstDate = false ;
2396- break ;
2397- }
23982414 default : {
23992415 const dimension : IPivotDimension = {
24002416 memberName : field ,
0 commit comments