@@ -32,12 +32,12 @@ import {
3232} from '@angular/core' ;
3333import { NgTemplateOutlet , NgClass , NgStyle } from '@angular/common' ;
3434
35- import { first , take , takeUntil } from 'rxjs/operators' ;
35+ import { first , take , takeUntil } from 'rxjs/operators' ;
3636import { IgxGridBaseDirective } from '../grid-base.directive' ;
3737import { IgxFilteringService } from '../filtering/grid-filtering.service' ;
3838import { IgxGridSelectionService } from '../selection/selection.service' ;
3939import { IgxForOfSyncService , IgxForOfScrollSyncService } from '../../directives/for-of/for_of.sync.service' ;
40- import { ColumnType , GridType , IGX_GRID_BASE , IGX_GRID_SERVICE_BASE , IgxColumnTemplateContext , RowType } from '../common/grid.interface' ;
40+ import { ColumnType , GridType , IGX_GRID_BASE , IGX_GRID_SERVICE_BASE , IgxColumnTemplateContext , PivotGridType , RowType } from '../common/grid.interface' ;
4141import { IgxGridCRUDService } from '../common/crud.service' ;
4242import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
4343import { DEFAULT_PIVOT_KEYS , IDimensionsChange , IgxPivotGridValueTemplateContext , IPivotConfiguration , IPivotConfigurationChangedEventArgs , IPivotDimension , IPivotValue , IValuesChange , PivotDimensionType , IPivotUISettings , PivotRowLayoutType , PivotSummaryPosition } from './pivot-grid.interface' ;
@@ -72,7 +72,7 @@ import { IgxPivotColumnResizingService } from '../resizing/pivot-grid/pivot-resi
7272import { IgxFlatTransactionFactory , IgxOverlayService , State , Transaction , TransactionService } from '../../services/public_api' ;
7373import { cloneArray , PlatformUtil , resizeObservable } from '../../core/utils' ;
7474import { IgxPivotFilteringService } from './pivot-filtering.service' ;
75- import { DataUtil } from '../../data-operations/data-util' ;
75+ import { DataUtil , GridColumnDataType } from '../../data-operations/data-util' ;
7676import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
7777import { IgxGridTransaction } from '../common/types' ;
7878import { GridBaseAPIService } from '../api.service' ;
@@ -199,7 +199,7 @@ const MINIMUM_COLUMN_WIDTH_SUPER_COMPACT = 104;
199199 schemas : [ CUSTOM_ELEMENTS_SCHEMA ]
200200} )
201201export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnInit , AfterContentInit ,
202- GridType , AfterViewInit , OnChanges {
202+ PivotGridType , AfterViewInit , OnChanges {
203203
204204 /**
205205 * Emitted when the dimension collection is changed via the grid chip area.
@@ -1672,7 +1672,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
16721672 public autoSizeRowDimension ( dimension : IPivotDimension ) {
16731673 if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
16741674 const relatedDims : string [ ] = PivotUtil . flatten ( [ dimension ] ) . map ( ( x : IPivotDimension ) => x . memberName ) ;
1675- const contentCollection = this . getContentCollection ( dimension ) ;
1675+ const contentCollection = this . getContentCollection ( dimension ) ;
16761676 const content = contentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
16771677 const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
16781678 if ( this . pivotUI . showRowHeaders ) {
@@ -1946,8 +1946,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
19461946 */
19471947 public getRowDimensionByName ( memberName : string ) {
19481948 const visibleRows = this . pivotUI . rowLayout === PivotRowLayoutType . Vertical ?
1949- this . pivotConfiguration . rows :
1950- PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
1949+ this . pivotConfiguration . rows :
1950+ PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
19511951 const dimIndex = visibleRows . findIndex ( ( target ) => target . memberName === memberName ) ;
19521952 const dim = visibleRows [ dimIndex ] ;
19531953 return dim ;
@@ -2281,7 +2281,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
22812281 const separator = this . pivotKeys . columnDimensionSeparator ;
22822282 const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
22832283 const hierarchy = new Map < string , any > ( ) ;
2284- const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2284+ const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
22852285 dataArr . forEach ( arr => {
22862286 let currentHierarchy = hierarchy ;
22872287 const path = [ ] ;
@@ -2301,17 +2301,22 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23012301 } ) ;
23022302 return hierarchy ;
23032303 }
2304-
23052304 protected generateColumnHierarchy ( fields : Map < string , any > , data , parent = null ) : IgxColumnComponent [ ] {
23062305 let columns = [ ] ;
23072306 if ( fields . size === 0 ) {
23082307 this . values . forEach ( ( value ) => {
23092308 const ref = createComponent ( IgxColumnComponent , { environmentInjector : this . envInjector , elementInjector : this . injector } ) ;
2309+ let columnDataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2310+
2311+ if ( value . aggregate ?. key ?. toLowerCase ( ) === 'count' && ( columnDataType === GridColumnDataType . Currency || columnDataType == GridColumnDataType . Percent ) ) {
2312+ columnDataType = GridColumnDataType . Number ;
2313+ }
2314+
23102315 ref . instance . header = value . displayName ;
23112316 ref . instance . field = value . member ;
23122317 ref . instance . parent = parent ;
23132318 ref . instance . sortable = true ;
2314- ref . instance . dataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2319+ ref . instance . dataType = columnDataType ;
23152320 ref . instance . formatter = value . formatter ;
23162321 columns . push ( ref . instance ) ;
23172322 } ) ;
@@ -2325,9 +2330,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23252330 }
23262331 if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
23272332 const col = this . createColumnForDimension ( value , data , parent , this . hasMultipleValues ) ;
2333+
2334+ if ( ! this . hasMultipleValues && this . values . length > 0 ) {
2335+ PivotUtil . updateColumnTypeByAggregator ( [ col ] , this . values [ 0 ] , true ) ;
2336+ }
2337+
23282338 columns . push ( col ) ;
23292339 if ( this . hasMultipleValues ) {
23302340 const measureChildren = this . getMeasureChildren ( data , col , false , value . dimension . width ) ;
2341+
2342+ measureChildren . forEach ( ( child , index ) => {
2343+ const pivotValue = this . values [ index ] ;
2344+ PivotUtil . updateColumnTypeByAggregator ( [ child ] , pivotValue , this . values . length === 1 ) ;
2345+ } ) ;
2346+
23312347 col . children . reset ( measureChildren ) ;
23322348 columns = columns . concat ( measureChildren ) ;
23332349 }
@@ -2397,20 +2413,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23972413 } ;
23982414 values . push ( value ) ;
23992415 break ;
2400- }
2401- case "date" :
2402- {
2403- const dimension : IPivotDimension = new IgxPivotDateDimension (
2416+ }
2417+ case "date" :
24042418 {
2405- memberName : field ,
2406- enabled : isFirstDate ,
2407- dataType : dataType
2419+ const dimension : IPivotDimension = new IgxPivotDateDimension (
2420+ {
2421+ memberName : field ,
2422+ enabled : isFirstDate ,
2423+ dataType : dataType
2424+ }
2425+ )
2426+ rowDimensions . push ( dimension ) ;
2427+ isFirstDate = false ;
2428+ break ;
24082429 }
2409- )
2410- rowDimensions . push ( dimension ) ;
2411- isFirstDate = false ;
2412- break ;
2413- }
24142430 default : {
24152431 const dimension : IPivotDimension = {
24162432 memberName : field ,
0 commit comments