@@ -30,12 +30,12 @@ import { GridType } from '../common/grid.interface';
3030import { IgxGridNavigationService } from '../grid-navigation.service' ;
3131import { IgxGridCRUDService } from '../common/crud.service' ;
3232import { IgxGridSummaryService } from '../summaries/grid-summary.service' ;
33- import { IPivotConfiguration , IPivotKeys , PivotDimensionType } from './pivot-grid.interface' ;
33+ import { IPivotConfiguration , IPivotDimension , IPivotKeys , PivotDimensionType } from './pivot-grid.interface' ;
3434import { IgxPivotHeaderRowComponent } from './pivot-header-row.component' ;
3535import { IgxColumnGroupComponent } from '../columns/column-group.component' ;
3636import { IgxColumnComponent } from '../columns/column.component' ;
3737import { PivotUtil } from './pivot-util' ;
38- import { NoopPivotDimensionsStrategy } from '../../data-operations/pivot-strategy' ;
38+ import { DimensionValuesFilteringStrategy , NoopPivotDimensionsStrategy } from '../../data-operations/pivot-strategy' ;
3939import { IgxGridExcelStyleFilteringComponent } from '../filtering/excel-style/grid.excel-style-filtering.component' ;
4040import { IgxPivotGridNavigationService } from './pivot-grid-navigation.service' ;
4141import { IgxColumnResizingService } from '../resizing/resizing.service' ;
@@ -46,6 +46,7 @@ import { cloneArray, PlatformUtil } from '../../core/utils';
4646import { IgxGridTransaction } from '../hierarchical-grid/public_api' ;
4747import { IgxPivotFilteringService } from './pivot-filtering.service' ;
4848import { DataUtil } from '../../data-operations/data-util' ;
49+ import { IFilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree' ;
4950
5051let NEXT_ID = 0 ;
5152const MINIMUM_COLUMN_WIDTH = 200 ;
@@ -112,7 +113,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
112113
113114
114115 public columnGroupStates = new Map < string , boolean > ( ) ;
115- public originalDataColumns ;
116+ public dimensionDataColumns ;
116117 public pivotKeys : IPivotKeys = { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ;
117118 public isPivot = true ;
118119 protected _defaultExpandState = true ;
@@ -168,6 +169,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
168169 public ngOnInit ( ) {
169170 // pivot grid always generates columns automatically.
170171 this . autoGenerate = true ;
172+ this . uniqueColumnValuesStrategy = this . uniqueColumnValuesStrategy || this . uniqueDimensionValuesStrategy ;
171173 super . ngOnInit ( ) ;
172174 }
173175
@@ -188,6 +190,32 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
188190 } ) ;
189191 }
190192
193+ public uniqueDimensionValuesStrategy ( column : IgxColumnComponent , exprTree : IFilteringExpressionsTree ,
194+ done : ( uniqueValues : any [ ] ) => void ) {
195+ const config = this . pivotConfiguration ;
196+ const allDimensions = config . rows . concat ( config . columns ) . concat ( config . filters ) . filter ( x => x !== null ) ;
197+ const enabledDimensions = allDimensions . filter ( x => x && x . enabled ) ;
198+ const dim = PivotUtil . flatten ( enabledDimensions ) . find ( x => x . memberName === column . field ) ;
199+ this . getDimensionData ( dim , exprTree , uniqueValues => done ( uniqueValues ) ) ;
200+ }
201+
202+ public getDimensionData ( dim : IPivotDimension ,
203+ dimExprTree : IFilteringExpressionsTree ,
204+ done : ( colVals : any [ ] ) => void ) {
205+ let columnValues = [ ] ;
206+ const data = this . gridAPI . get_data ( ) ;
207+ const allValuesHierarchy = PivotUtil . getFieldsHierarchy (
208+ data ,
209+ [ dim ] ,
210+ PivotDimensionType . Column ,
211+ { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
212+ ) ;
213+ const flatData = Array . from ( allValuesHierarchy . values ( ) ) ;
214+ columnValues = flatData . map ( record => this . extractValue ( record [ 'value' ] ) ) ;
215+ done ( columnValues ) ;
216+ return ;
217+ }
218+
191219 /** @hidden */
192220 public featureColumnsWidth ( ) {
193221 return this . pivotRowWidths ;
@@ -367,7 +395,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
367395 protected autogenerateColumns ( ) {
368396 let columns = [ ] ;
369397 const data = this . gridAPI . get_data ( ) ;
370- this . originalDataColumns = this . generateOriginalColumns ( ) ;
398+ this . dimensionDataColumns = this . generateDimensionColumns ( ) ;
371399 let fieldsMap ;
372400 if ( this . pivotConfiguration . columnStrategy && this . pivotConfiguration . columnStrategy instanceof NoopPivotDimensionsStrategy ) {
373401 const fields = this . generateDataFields ( data ) ;
@@ -393,15 +421,15 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
393421 }
394422 }
395423
396- protected generateOriginalColumns ( ) {
397- const data = this . gridAPI . get_data ( ) ;
398- const fields = this . generateDataFields ( data ) ;
424+ protected generateDimensionColumns ( ) {
425+ const config = this . pivotConfiguration ;
426+ const allDimensions = config . rows . concat ( config . columns ) . concat ( config . filters ) . filter ( x => x !== null ) ;
427+ const leafFields = PivotUtil . flatten ( allDimensions , 0 ) . filter ( x => ! x . childLevel ) . map ( x => x . memberName ) ;
399428 const columns = [ ] ;
400429 const factory = this . resolver . resolveComponentFactory ( IgxColumnComponent ) ;
401- fields . forEach ( ( field ) => {
430+ leafFields . forEach ( ( field ) => {
402431 const ref = factory . create ( this . viewRef . injector ) ;
403432 ref . instance . field = field ;
404- ref . instance . dataType = this . resolveDataTypes ( data [ 0 ] [ field ] ) ;
405433 ref . changeDetectorRef . detectChanges ( ) ;
406434 columns . push ( ref . instance ) ;
407435 } ) ;
@@ -436,10 +464,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
436464 if ( value . dimension && value . dimension . filters ) {
437465 const state = {
438466 expressionsTree : value . dimension . filters . filteringOperands [ 0 ] ,
439- strategy : this . filterStrategy ,
467+ strategy : this . filterStrategy || new DimensionValuesFilteringStrategy ( ) ,
440468 advancedFilteringExpressionsTree : this . advancedFilteringExpressionsTree
441469 } ;
442- const filtered = DataUtil . filter ( cloneArray ( value . records ) , state ) ;
470+ const filtered = DataUtil . filter ( cloneArray ( value . records ) , state , this ) ;
443471 if ( filtered . length === 0 ) {
444472 shouldGenerate = false ;
445473 }
@@ -514,4 +542,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
514542 } ) ;
515543 return cols ;
516544 }
545+ private extractValue ( value ) {
546+ return value . split ( '-' ) [ value . split ( '-' ) . length - 1 ] ;
547+ }
517548}
0 commit comments