@@ -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.
@@ -1667,7 +1667,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
16671667 public autoSizeRowDimension ( dimension : IPivotDimension ) {
16681668 if ( this . getDimensionType ( dimension ) === PivotDimensionType . Row ) {
16691669 const relatedDims : string [ ] = PivotUtil . flatten ( [ dimension ] ) . map ( ( x : IPivotDimension ) => x . memberName ) ;
1670- const contentCollection = this . getContentCollection ( dimension ) ;
1670+ const contentCollection = this . getContentCollection ( dimension ) ;
16711671 const content = contentCollection . filter ( x => relatedDims . indexOf ( x . dimension . memberName ) !== - 1 ) ;
16721672 const headers = content . map ( x => x . headerGroups . toArray ( ) ) . flat ( ) . map ( x => x . header && x . header . refInstance ) ;
16731673 if ( this . pivotUI . showRowHeaders ) {
@@ -1941,8 +1941,8 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
19411941 */
19421942 public getRowDimensionByName ( memberName : string ) {
19431943 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 ) ;
19461946 const dimIndex = visibleRows . findIndex ( ( target ) => target . memberName === memberName ) ;
19471947 const dim = visibleRows [ dimIndex ] ;
19481948 return dim ;
@@ -2266,7 +2266,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
22662266 const separator = this . pivotKeys . columnDimensionSeparator ;
22672267 const dataArr = fields . map ( x => x . split ( separator ) ) . sort ( x => x . length ) ;
22682268 const hierarchy = new Map < string , any > ( ) ;
2269- const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
2269+ const columnDimensions = PivotUtil . flatten ( this . columnDimensions ) ;
22702270 dataArr . forEach ( arr => {
22712271 let currentHierarchy = hierarchy ;
22722272 const path = [ ] ;
@@ -2286,17 +2286,22 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
22862286 } ) ;
22872287 return hierarchy ;
22882288 }
2289-
22902289 protected generateColumnHierarchy ( fields : Map < string , any > , data , parent = null ) : IgxColumnComponent [ ] {
22912290 let columns = [ ] ;
22922291 if ( fields . size === 0 ) {
22932292 this . values . forEach ( ( value ) => {
22942293 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+
22952300 ref . instance . header = value . displayName ;
22962301 ref . instance . field = value . member ;
22972302 ref . instance . parent = parent ;
22982303 ref . instance . sortable = true ;
2299- ref . instance . dataType = value . dataType || this . resolveDataTypes ( data . length ? data [ 0 ] [ value . member ] : null ) ;
2304+ ref . instance . dataType = columnDataType ;
23002305 ref . instance . formatter = value . formatter ;
23012306 columns . push ( ref . instance ) ;
23022307 } ) ;
@@ -2310,9 +2315,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23102315 }
23112316 if ( shouldGenerate && ( value . children == null || value . children . length === 0 || value . children . size === 0 ) ) {
23122317 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+
23132323 columns . push ( col ) ;
23142324 if ( this . hasMultipleValues ) {
23152325 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+
23162332 col . children . reset ( measureChildren ) ;
23172333 columns = columns . concat ( measureChildren ) ;
23182334 }
@@ -2382,20 +2398,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
23822398 } ;
23832399 values . push ( value ) ;
23842400 break ;
2385- }
2386- case "date" :
2387- {
2388- const dimension : IPivotDimension = new IgxPivotDateDimension (
2401+ }
2402+ case "date" :
23892403 {
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 ;
23932414 }
2394- )
2395- rowDimensions . push ( dimension ) ;
2396- isFirstDate = false ;
2397- break ;
2398- }
23992415 default : {
24002416 const dimension : IPivotDimension = {
24012417 memberName : field ,
0 commit comments