@@ -32,12 +32,12 @@ import {
32
32
} from '@angular/core' ;
33
33
import { NgTemplateOutlet , NgClass , NgStyle } from '@angular/common' ;
34
34
35
- import { first , take , takeUntil } from 'rxjs/operators' ;
35
+ import { first , take , takeUntil } from 'rxjs/operators' ;
36
36
import { IgxGridBaseDirective } from '../grid-base.directive' ;
37
37
import { IgxFilteringService } from '../filtering/grid-filtering.service' ;
38
38
import { IgxGridSelectionService } from '../selection/selection.service' ;
39
39
import { 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' ;
41
41
import { IgxGridCRUDService } from '../common/crud.service' ;
42
42
import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
43
43
import { 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
72
72
import { IgxFlatTransactionFactory , IgxOverlayService , State , Transaction , TransactionService } from '../../services/public_api' ;
73
73
import { cloneArray , PlatformUtil , resizeObservable } from '../../core/utils' ;
74
74
import { IgxPivotFilteringService } from './pivot-filtering.service' ;
75
- import { DataUtil } from '../../data-operations/data-util' ;
75
+ import { DataUtil , GridColumnDataType } from '../../data-operations/data-util' ;
76
76
import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
77
77
import { IgxGridTransaction } from '../common/types' ;
78
78
import { GridBaseAPIService } from '../api.service' ;
@@ -199,7 +199,7 @@ const MINIMUM_COLUMN_WIDTH_SUPER_COMPACT = 104;
199
199
schemas : [ CUSTOM_ELEMENTS_SCHEMA ]
200
200
} )
201
201
export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnInit , AfterContentInit ,
202
- GridType , AfterViewInit , OnChanges {
202
+ PivotGridType , AfterViewInit , OnChanges {
203
203
204
204
/**
205
205
* Emitted when the dimension collection is changed via the grid chip area.
@@ -1667,7 +1667,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1667
1667
public autoSizeRowDimension ( dimension : IPivotDimension ) {
1668
1668
if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
1669
1669
const relatedDims : string [ ] = PivotUtil . flatten ( [ dimension ] ) . map ( ( x : IPivotDimension ) => x . memberName ) ;
1670
- const contentCollection = this . getContentCollection ( dimension ) ;
1670
+ const contentCollection = this . getContentCollection ( dimension ) ;
1671
1671
const content = contentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
1672
1672
const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
1673
1673
if ( this . pivotUI . showRowHeaders ) {
@@ -1941,8 +1941,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
1941
1941
*/
1942
1942
public getRowDimensionByName ( memberName : string ) {
1943
1943
const visibleRows = this . pivotUI . rowLayout === PivotRowLayoutType . Vertical ?
1944
- this . pivotConfiguration . rows :
1945
- PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
1944
+ this . pivotConfiguration . rows :
1945
+ PivotUtil . flatten ( this . pivotConfiguration . rows ) ;
1946
1946
const dimIndex = visibleRows . findIndex ( ( target ) => target . memberName === memberName ) ;
1947
1947
const dim = visibleRows [ dimIndex ] ;
1948
1948
return dim ;
@@ -2266,7 +2266,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2266
2266
const separator = this . pivotKeys . columnDimensionSeparator ;
2267
2267
const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
2268
2268
const hierarchy = new Map < string , any > ( ) ;
2269
- const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2269
+ const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2270
2270
dataArr . forEach ( arr => {
2271
2271
let currentHierarchy = hierarchy ;
2272
2272
const path = [ ] ;
@@ -2286,17 +2286,22 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2286
2286
} ) ;
2287
2287
return hierarchy ;
2288
2288
}
2289
-
2290
2289
protected generateColumnHierarchy ( fields : Map < string , any > , data , parent = null ) : IgxColumnComponent [ ] {
2291
2290
let columns = [ ] ;
2292
2291
if ( fields . size === 0 ) {
2293
2292
this . values . forEach ( ( value ) => {
2294
2293
const ref = createComponent ( IgxColumnComponent , { environmentInjector : this . envInjector , elementInjector : this . injector } ) ;
2294
+ let columnDataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2295
+
2296
+ if ( value . aggregate ?. key ?. toLowerCase ( ) === 'count' && ( columnDataType === GridColumnDataType . Currency || columnDataType == GridColumnDataType . Percent ) ) {
2297
+ columnDataType = GridColumnDataType . Number ;
2298
+ }
2299
+
2295
2300
ref . instance . header = value . displayName ;
2296
2301
ref . instance . field = value . member ;
2297
2302
ref . instance . parent = parent ;
2298
2303
ref . instance . sortable = true ;
2299
- ref . instance . dataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2304
+ ref . instance . dataType = columnDataType ;
2300
2305
ref . instance . formatter = value . formatter ;
2301
2306
columns . push ( ref . instance ) ;
2302
2307
} ) ;
@@ -2310,9 +2315,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2310
2315
}
2311
2316
if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
2312
2317
const col = this . createColumnForDimension ( value , data , parent , this . hasMultipleValues ) ;
2318
+
2319
+ if ( ! this . hasMultipleValues && this . values . length > 0 ) {
2320
+ PivotUtil . updateColumnTypeByAggregator ( [ col ] , this . values [ 0 ] , true ) ;
2321
+ }
2322
+
2313
2323
columns . push ( col ) ;
2314
2324
if ( this . hasMultipleValues ) {
2315
2325
const measureChildren = this . getMeasureChildren ( data , col , false , value . dimension . width ) ;
2326
+
2327
+ measureChildren . forEach ( ( child , index ) => {
2328
+ const pivotValue = this . values [ index ] ;
2329
+ PivotUtil . updateColumnTypeByAggregator ( [ child ] , pivotValue , this . values . length === 1 ) ;
2330
+ } ) ;
2331
+
2316
2332
col . children . reset ( measureChildren ) ;
2317
2333
columns = columns . concat ( measureChildren ) ;
2318
2334
}
@@ -2382,20 +2398,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
2382
2398
} ;
2383
2399
values . push ( value ) ;
2384
2400
break ;
2385
- }
2386
- case "date" :
2387
- {
2388
- const dimension : IPivotDimension = new IgxPivotDateDimension (
2401
+ }
2402
+ case "date" :
2389
2403
{
2390
- memberName : field ,
2391
- enabled : isFirstDate ,
2392
- dataType : dataType
2404
+ const dimension : IPivotDimension = new IgxPivotDateDimension (
2405
+ {
2406
+ memberName : field ,
2407
+ enabled : isFirstDate ,
2408
+ dataType : dataType
2409
+ }
2410
+ )
2411
+ rowDimensions . push ( dimension ) ;
2412
+ isFirstDate = false ;
2413
+ break ;
2393
2414
}
2394
- )
2395
- rowDimensions . push ( dimension ) ;
2396
- isFirstDate = false ;
2397
- break ;
2398
- }
2399
2415
default : {
2400
2416
const dimension : IPivotDimension = {
2401
2417
memberName : field ,
0 commit comments