@@ -99,6 +99,7 @@ import { IgxColumnResizingService } from '../resizing/resizing.service';
9999import { DefaultDataCloneStrategy , IDataCloneStrategy } from '../../data-operations/data-clone-strategy' ;
100100import { IgxTextHighlightService } from '../../directives/text-highlight/text-highlight.service' ;
101101import { IgxPivotRowHeaderGroupComponent } from './pivot-row-header-group.component' ;
102+ import { IgxPivotDateDimension } from './pivot-grid-dimensions' ;
102103
103104let NEXT_ID = 0 ;
104105const MINIMUM_COLUMN_WIDTH = 200 ;
@@ -328,6 +329,19 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
328329 return this . _pivotConfiguration || { rows : null , columns : null , values : null , filters : null } ;
329330 }
330331
332+ /**
333+ * Gets/Sets whether to auto-generate the pivot configuration based on the provided data.
334+ *
335+ * @remarks
336+ * The default value is false. When set to true, it will override all dimensions and values in the pivotConfiguration.
337+ * @example
338+ * ```html
339+ * <igx-pivot-grid [data]="Data" [autoGenerateConfig]="true"></igx-pivot-grid>
340+ * ```
341+ */
342+ @Input ( { transform : booleanAttribute } )
343+ public autoGenerateConfig = false ;
344+
331345 @Input ( )
332346 /**
333347 * Gets/Sets the pivot ui settings for the pivot grid - chips and their
@@ -1001,6 +1015,9 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10011015 // ignore any user defined columns and auto-generate based on pivot config.
10021016 this . updateColumns ( [ ] ) ;
10031017 Promise . resolve ( ) . then ( ( ) => {
1018+ if ( this . autoGenerateConfig ) {
1019+ this . generateConfig ( ) ;
1020+ }
10041021 this . setupColumns ( ) ;
10051022 } ) ;
10061023 if ( this . valueChipTemplateDirective ) {
@@ -1093,6 +1110,9 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10931110 public set data ( value : any [ ] | null ) {
10941111 this . _data = value || [ ] ;
10951112 if ( ! this . _init ) {
1113+ if ( this . autoGenerateConfig ) {
1114+ this . generateConfig ( ) ;
1115+ }
10961116 this . setupColumns ( ) ;
10971117 this . reflow ( ) ;
10981118 }
@@ -2169,6 +2189,67 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
21692189 return columns ;
21702190 }
21712191
2192+
2193+ protected generateConfig ( ) {
2194+ if ( ! this . data ) return ;
2195+
2196+ const data = this . data ;
2197+ const fields = this . generateDataFields ( data ) ;
2198+ const columnDimensions : IPivotDimension [ ] = [ ] ;
2199+ const rowDimensions : IPivotDimension [ ] = [ ] ;
2200+ const values : IPivotValue [ ] = [ ] ;
2201+ let isFirstDate = true ;
2202+ fields . forEach ( ( field ) => {
2203+ const dataType = this . resolveDataTypes ( data [ 0 ] [ field ] ) ;
2204+ switch ( dataType ) {
2205+ case "number" :
2206+ {
2207+ const value : IPivotValue = {
2208+ member : field ,
2209+ displayName : field ,
2210+ dataType : dataType ,
2211+ aggregate : {
2212+ key : 'sum' ,
2213+ label : 'Sum' ,
2214+ aggregatorName : "SUM"
2215+ } ,
2216+ enabled : true
2217+ } ;
2218+ values . push ( value ) ;
2219+ break ;
2220+ }
2221+ case "date" :
2222+ {
2223+ const dimension : IPivotDimension = new IgxPivotDateDimension (
2224+ {
2225+ memberName : field ,
2226+ enabled : isFirstDate ,
2227+ dataType : dataType
2228+ }
2229+ )
2230+ rowDimensions . push ( dimension ) ;
2231+ isFirstDate = false ;
2232+ break ;
2233+ }
2234+ default : {
2235+ const dimension : IPivotDimension = {
2236+ memberName : field ,
2237+ enabled : false ,
2238+ dataType : dataType
2239+ } ;
2240+ columnDimensions . push ( dimension ) ;
2241+ break ;
2242+ }
2243+ }
2244+ } ) ;
2245+ const config : IPivotConfiguration = {
2246+ columns : columnDimensions ,
2247+ rows : rowDimensions ,
2248+ values : values
2249+ } ;
2250+ this . pivotConfiguration = config ;
2251+ }
2252+
21722253 protected createColumnForDimension ( value : any , data : any , parent : ColumnType , isGroup : boolean ) {
21732254 const key = value . value ;
21742255 const ref = isGroup ?
0 commit comments