@@ -31,7 +31,7 @@ import {
31
31
} from '@angular/core' ;
32
32
import { DOCUMENT , NgTemplateOutlet , NgClass , NgStyle } from '@angular/common' ;
33
33
34
- import { first , take , takeUntil } from 'rxjs/operators' ;
34
+ import { first , take , takeUntil } from 'rxjs/operators' ;
35
35
import { IgxGridBaseDirective } from '../grid-base.directive' ;
36
36
import { IgxFilteringService } from '../filtering/grid-filtering.service' ;
37
37
import { IgxGridSelectionService } from '../selection/selection.service' ;
@@ -1655,7 +1655,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1655
1655
public autoSizeRowDimension ( dimension : IPivotDimension ) {
1656
1656
if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
1657
1657
const relatedDims : string [ ] = PivotUtil . flatten ( [ dimension ] ) . map ( ( x : IPivotDimension ) => x . memberName ) ;
1658
- const contentCollection = this . getContentCollection ( dimension ) ;
1658
+ const contentCollection = this . getContentCollection ( dimension ) ;
1659
1659
const content = contentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
1660
1660
const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
1661
1661
if ( this . pivotUI . showRowHeaders ) {
@@ -1929,8 +1929,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1929
1929
*/
1930
1930
public getRowDimensionByName ( memberName : string ) {
1931
1931
const visibleRows = this . pivotUI . rowLayout === PivotRowLayoutType . Vertical ?
1932
- this . pivotConfiguration . rows :
1933
- PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
1932
+ this . pivotConfiguration . rows :
1933
+ PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
1934
1934
const dimIndex = visibleRows . findIndex ( ( target ) => target . memberName === memberName ) ;
1935
1935
const dim = visibleRows [ dimIndex ] ;
1936
1936
return dim ;
@@ -2254,7 +2254,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2254
2254
const separator = this . pivotKeys . columnDimensionSeparator ;
2255
2255
const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
2256
2256
const hierarchy = new Map < string , any > ( ) ;
2257
- const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2257
+ const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2258
2258
dataArr . forEach ( arr => {
2259
2259
let currentHierarchy = hierarchy ;
2260
2260
const path = [ ] ;
@@ -2274,18 +2274,31 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2274
2274
} ) ;
2275
2275
return hierarchy ;
2276
2276
}
2277
-
2278
- /** @hidden @internal */
2279
- public currencyColumnSet : Set < string > = new Set ( ) ;
2277
+ private updateColumnDataTypeByAggregator ( column : any ) {
2278
+ this . values . forEach ( ( aggregatorValue ) => {
2279
+ if ( ( aggregatorValue . dataType === GridColumnDataType . Currency || aggregatorValue . dataType === GridColumnDataType . Percent ) && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) === 'count' ) {
2280
+ if ( column . field ?. includes ( aggregatorValue . member ) || this . values . length === 1 ) {
2281
+ column . dataType = GridColumnDataType . Number ;
2282
+ }
2283
+ } else if ( aggregatorValue . dataType === GridColumnDataType . Currency && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) !== 'count' ) {
2284
+ if ( column . field ?. includes ( aggregatorValue . member ) || this . values . length === 1 ) {
2285
+ column . dataType = GridColumnDataType . Currency ;
2286
+ }
2287
+ } else if ( aggregatorValue . dataType === GridColumnDataType . Percent && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) !== 'count' ) {
2288
+ if ( column . field ?. includes ( aggregatorValue . member ) || this . values . length === 1 ) {
2289
+ column . dataType = GridColumnDataType . Percent ;
2290
+ }
2291
+ }
2292
+ } )
2293
+ }
2280
2294
protected generateColumnHierarchy ( fields : Map < string , any > , data , parent = null ) : IgxColumnComponent [ ] {
2281
2295
let columns = [ ] ;
2282
2296
if ( fields . size === 0 ) {
2283
2297
this . values . forEach ( ( value ) => {
2284
2298
const ref = createComponent ( IgxColumnComponent , { environmentInjector : this . envInjector , elementInjector : this . injector } ) ;
2285
2299
let columnDataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2286
2300
2287
- if ( value . aggregate ?. key ?. toLowerCase ( ) === 'count' && columnDataType === GridColumnDataType . Currency ) {
2288
- this . currencyColumnSet . add ( value . member ) ;
2301
+ if ( value . aggregate ?. key ?. toLowerCase ( ) === 'count' && ( columnDataType === GridColumnDataType . Currency || columnDataType == GridColumnDataType . Percent ) ) {
2289
2302
columnDataType = GridColumnDataType . Number ;
2290
2303
}
2291
2304
@@ -2308,32 +2321,14 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2308
2321
if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
2309
2322
const col = this . createColumnForDimension ( value , data , parent , this . hasMultipleValues ) ;
2310
2323
2311
- this . values . forEach ( ( aggregatorValue ) => {
2312
- if ( col . dataType === GridColumnDataType . Currency && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) === 'count' ) {
2313
- col . dataType = GridColumnDataType . Number ;
2314
- this . currencyColumnSet . add ( aggregatorValue . member ) ;
2315
- } else if ( this . currencyColumnSet . has ( aggregatorValue . member ) && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) !== 'count' ) {
2316
- col . dataType = GridColumnDataType . Currency ;
2317
- this . currencyColumnSet . delete ( aggregatorValue . member ) ;
2318
- }
2319
- } )
2324
+ this . updateColumnDataTypeByAggregator ( col ) ;
2320
2325
2321
2326
columns . push ( col ) ;
2322
2327
if ( this . hasMultipleValues ) {
2323
2328
const measureChildren = this . getMeasureChildren ( data , col , false , value . dimension . width ) ;
2324
2329
2325
2330
measureChildren . forEach ( ( child ) => {
2326
- this . values . forEach ( ( aggregatorValue ) => {
2327
- if ( child . field . includes ( aggregatorValue . member ) ) {
2328
- if ( child . dataType === GridColumnDataType . Currency && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) === 'count' ) {
2329
- child . dataType = GridColumnDataType . Number ;
2330
- this . currencyColumnSet . add ( aggregatorValue . member ) ;
2331
- } else if ( this . currencyColumnSet . has ( aggregatorValue . member ) && aggregatorValue . aggregate ?. key ?. toLowerCase ( ) !== 'count' ) {
2332
- child . dataType = GridColumnDataType . Currency ;
2333
- this . currencyColumnSet . delete ( aggregatorValue . member ) ;
2334
- }
2335
- }
2336
- } )
2331
+ this . updateColumnDataTypeByAggregator ( child ) ;
2337
2332
} )
2338
2333
2339
2334
col . children . reset ( measureChildren ) ;
@@ -2405,20 +2400,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2405
2400
} ;
2406
2401
values . push ( value ) ;
2407
2402
break ;
2408
- }
2409
- case "date" :
2410
- {
2411
- const dimension : IPivotDimension = new IgxPivotDateDimension (
2403
+ }
2404
+ case "date" :
2412
2405
{
2413
- memberName : field ,
2414
- enabled : isFirstDate ,
2415
- dataType : dataType
2406
+ const dimension : IPivotDimension = new IgxPivotDateDimension (
2407
+ {
2408
+ memberName : field ,
2409
+ enabled : isFirstDate ,
2410
+ dataType : dataType
2411
+ }
2412
+ )
2413
+ rowDimensions . push ( dimension ) ;
2414
+ isFirstDate = false ;
2415
+ break ;
2416
2416
}
2417
- )
2418
- rowDimensions . push ( dimension ) ;
2419
- isFirstDate = false ;
2420
- break ;
2421
- }
2422
2417
default : {
2423
2418
const dimension : IPivotDimension = {
2424
2419
memberName : field ,
0 commit comments