@@ -31,12 +31,12 @@ 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' ;
38
38
import { 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' ;
40
40
import { IgxGridCRUDService } from '../common/crud.service' ;
41
41
import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
42
42
import { 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
71
71
import { IgxFlatTransactionFactory , IgxOverlayService , State , Transaction , TransactionService } from '../../services/public_api' ;
72
72
import { cloneArray , PlatformUtil , resizeObservable } from '../../core/utils' ;
73
73
import { IgxPivotFilteringService } from './pivot-filtering.service' ;
74
- import { DataUtil } from '../../data-operations/data-util' ;
74
+ import { DataUtil , GridColumnDataType } from '../../data-operations/data-util' ;
75
75
import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
76
76
import { IgxGridTransaction } from '../common/types' ;
77
77
import { GridBaseAPIService } from '../api.service' ;
@@ -198,7 +198,7 @@ const MINIMUM_COLUMN_WIDTH_SUPER_COMPACT = 104;
198
198
schemas : [ CUSTOM_ELEMENTS_SCHEMA ]
199
199
} )
200
200
export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnInit , AfterContentInit ,
201
- GridType , AfterViewInit , OnChanges {
201
+ PivotGridType , AfterViewInit , OnChanges {
202
202
203
203
/**
204
204
* Emitted when the dimension collection is changed via the grid chip area.
@@ -1666,7 +1666,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1666
1666
public autoSizeRowDimension ( dimension : IPivotDimension ) {
1667
1667
if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
1668
1668
const relatedDims : string [ ] = PivotUtil . flatten ( [ dimension ] ) . map ( ( x : IPivotDimension ) => x . memberName ) ;
1669
- const contentCollection = this . getContentCollection ( dimension ) ;
1669
+ const contentCollection = this . getContentCollection ( dimension ) ;
1670
1670
const content = contentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
1671
1671
const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
1672
1672
if ( this . pivotUI . showRowHeaders ) {
@@ -1940,8 +1940,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1940
1940
*/
1941
1941
public getRowDimensionByName ( memberName : string ) {
1942
1942
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 ) ;
1945
1945
const dimIndex = visibleRows . findIndex ( ( target ) => target . memberName === memberName ) ;
1946
1946
const dim = visibleRows [ dimIndex ] ;
1947
1947
return dim ;
@@ -2265,7 +2265,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2265
2265
const separator = this . pivotKeys . columnDimensionSeparator ;
2266
2266
const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
2267
2267
const hierarchy = new Map < string , any > ( ) ;
2268
- const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2268
+ const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2269
2269
dataArr . forEach ( arr => {
2270
2270
let currentHierarchy = hierarchy ;
2271
2271
const path = [ ] ;
@@ -2285,17 +2285,22 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2285
2285
} ) ;
2286
2286
return hierarchy ;
2287
2287
}
2288
-
2289
2288
protected generateColumnHierarchy ( fields : Map < string , any > , data , parent = null ) : IgxColumnComponent [ ] {
2290
2289
let columns = [ ] ;
2291
2290
if ( fields . size === 0 ) {
2292
2291
this . values . forEach ( ( value ) => {
2293
2292
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
+
2294
2299
ref . instance . header = value . displayName ;
2295
2300
ref . instance . field = value . member ;
2296
2301
ref . instance . parent = parent ;
2297
2302
ref . instance . sortable = true ;
2298
- ref . instance . dataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2303
+ ref . instance . dataType = columnDataType ;
2299
2304
ref . instance . formatter = value . formatter ;
2300
2305
columns . push ( ref . instance ) ;
2301
2306
} ) ;
@@ -2309,9 +2314,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2309
2314
}
2310
2315
if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
2311
2316
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
+
2312
2322
columns . push ( col ) ;
2313
2323
if ( this . hasMultipleValues ) {
2314
2324
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
+
2315
2331
col . children . reset ( measureChildren ) ;
2316
2332
columns = columns . concat ( measureChildren ) ;
2317
2333
}
@@ -2381,20 +2397,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2381
2397
} ;
2382
2398
values . push ( value ) ;
2383
2399
break ;
2384
- }
2385
- case "date" :
2386
- {
2387
- const dimension : IPivotDimension = new IgxPivotDateDimension (
2400
+ }
2401
+ case "date" :
2388
2402
{
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 ;
2392
2413
}
2393
- )
2394
- rowDimensions . push ( dimension ) ;
2395
- isFirstDate = false ;
2396
- break ;
2397
- }
2398
2414
default : {
2399
2415
const dimension : IPivotDimension = {
2400
2416
memberName : field ,
0 commit comments