@@ -6,12 +6,15 @@ import {
66 ElementRef ,
77 forwardRef ,
88 OnInit ,
9+ TemplateRef ,
10+ ViewChild ,
911 ViewContainerRef
1012} from '@angular/core' ;
1113import { IgxPivotGridComponent } from './pivot-grid.component' ;
1214import { IgxRowDirective } from '../row.directive' ;
1315import { GridBaseAPIService , IgxColumnComponent } from '../hierarchical-grid/public_api' ;
1416import { IgxGridSelectionService } from '../selection/selection.service' ;
17+ import { IPivotDimension } from './pivot-grid.interface' ;
1518
1619
1720const MINIMUM_COLUMN_WIDTH = 136 ;
@@ -23,8 +26,15 @@ const MINIMUM_COLUMN_WIDTH = 136;
2326} )
2427export class IgxPivotRowComponent extends IgxRowDirective < IgxPivotGridComponent > implements OnInit {
2528
29+ /**
30+ * @hidden @internal
31+ */
32+ @ViewChild ( 'headerTemplate' , { read : TemplateRef , static : true } )
33+ public headerTemplate : TemplateRef < any > ;
2634
2735 public rowDimension : IgxColumnComponent [ ] = [ ] ;
36+ public level = 0 ;
37+ protected hasChild = false ;
2838
2939 constructor (
3040 public gridAPI : GridBaseAPIService < IgxPivotGridComponent > ,
@@ -36,7 +46,6 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
3646 ) {
3747 super ( gridAPI , selectionService , element , cdr ) ;
3848 }
39-
4049 /**
4150 * @hidden
4251 * @internal
@@ -48,24 +57,43 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
4857 public ngOnInit ( ) {
4958 // generate rowDimension
5059 const rowDimConfig = this . grid . pivotConfiguration . rows ;
51- let field = null ;
60+ this . level = this . rowData [ 'level' ] || 0 ;
61+ this . hasChild = this . rowData [ 'records' ] != null && this . rowData [ 'records' ] . length > 0 ;
62+ this . extractFromDimensions ( rowDimConfig , 0 ) ;
63+ }
64+
65+ protected extractFromDimensions ( rowDimConfig : IPivotDimension [ ] , level : number ) {
5266 for ( const dim of rowDimConfig ) {
53- if ( typeof dim . member === 'string' ) {
54- field = this . rowData [ dim . member ] ;
55- } else if ( typeof dim . member === 'function' ) {
56- field = dim . member . call ( this , this . rowData ) ;
67+ if ( level === this . level ) {
68+ this . rowDimension . push ( this . extractFromDimension ( dim ) ) ;
69+ } else {
70+ level ++ ;
71+ this . extractFromDimensions ( dim . childLevels , level ) ;
5772 }
58- const col = this . _createColComponent ( field ) ;
59- this . rowDimension . push ( col ) ;
6073 }
6174 }
6275
76+ protected extractFromDimension ( dim : IPivotDimension ) {
77+ let field = null ;
78+ if ( typeof dim . member === 'string' ) {
79+ field = this . rowData [ dim . member ] ;
80+ } else if ( typeof dim . member === 'function' ) {
81+ field = dim . member . call ( this , this . rowData ) ;
82+ }
83+ const col = this . _createColComponent ( field ) ;
84+ return col ;
85+ }
86+
6387 protected _createColComponent ( field : string ) {
6488 const factoryColumn = this . resolver . resolveComponentFactory ( IgxColumnComponent ) ;
6589 const ref = this . viewRef . createComponent ( factoryColumn , null , this . viewRef . injector ) ;
6690 ref . instance . field = field ;
91+ ref . instance . header = field ;
6792 ref . instance . width = MINIMUM_COLUMN_WIDTH + 'px' ;
6893 ( ref as any ) . instance . _vIndex = this . grid . columns . length + this . index ;
94+ if ( this . hasChild ) {
95+ ref . instance . headerTemplate = this . headerTemplate ;
96+ }
6997 return ref . instance ;
7098 }
7199}
0 commit comments