@@ -41,6 +41,9 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
41
41
@Input ( )
42
42
public rowIndex : number ;
43
43
44
+ @Input ( )
45
+ public dimension : IPivotDimension ;
46
+
44
47
@Input ( )
45
48
public rowData : any ;
46
49
@@ -65,10 +68,10 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
65
68
) {
66
69
super ( ref , cdr ) ;
67
70
}
68
- protected rowDimensionData : IPivotDimensionData [ ] = [ ] ;
71
+ protected rowDimensionData : IPivotDimensionData ;
69
72
70
- public get rowDimension ( ) {
71
- return this . rowDimensionData ?. filter ( x => ! x . isChild ) . map ( x => x . column ) ;
73
+ public get rowDimensionColumn ( ) {
74
+ return this . rowDimensionData ?. column ;
72
75
}
73
76
74
77
/**
@@ -77,19 +80,17 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
77
80
*/
78
81
public ngOnChanges ( changes : SimpleChanges ) {
79
82
const rowDimConfig = this . grid . rowDimensions ;
80
- if ( changes . data || rowDimConfig . length !== this . rowDimensionData . length ) {
83
+ if ( changes . rowData ) {
81
84
// generate new rowDimension on row data change
82
- this . rowDimensionData = [ ] ;
85
+ this . rowDimensionData = null ;
83
86
this . viewRef . clear ( ) ;
84
- this . extractFromDimensions ( rowDimConfig , 0 ) ;
87
+ this . extractFromDimensions ( ) ;
85
88
this . viewRef . clear ( ) ;
86
89
}
87
90
if ( changes . pivotRowWidths && this . rowDimensionData ) {
88
- for ( const dim of rowDimConfig ) {
89
- const dimData = PivotUtil . getDimensionLevel ( dim , this . rowData , this . grid . pivotKeys ) ;
90
- const data = this . rowDimensionData . find ( x => x . dimension . memberName === dimData . dimension . memberName ) ;
91
- data . column . width = this . grid . resolveRowDimensionWidth ( dim ) + 'px' ;
92
- }
91
+ const dimData = PivotUtil . getDimensionLevel ( this . dimension , this . rowData , this . grid . pivotKeys ) ;
92
+ const data = this . rowDimensionData ;
93
+ data . column . width = this . grid . resolveRowDimensionWidth ( this . dimension ) + 'px' ;
93
94
}
94
95
}
95
96
@@ -99,7 +100,7 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
99
100
* @internal
100
101
*/
101
102
public getRowDimensionKey ( col : IgxColumnComponent ) {
102
- const dimData = this . rowDimensionData . find ( x => x . column . field === col . field ) ;
103
+ const dimData = this . rowDimensionData ;
103
104
const key = PivotUtil . getRecordKey ( this . rowData , dimData . dimension , dimData . prevDimensions , this . grid . pivotKeys ) ;
104
105
return key ;
105
106
}
@@ -112,6 +113,19 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
112
113
return this . rowData [ col . field + this . grid . pivotKeys . rowDimensionSeparator + this . grid . pivotKeys . level ] ;
113
114
}
114
115
116
+ get rowSpan ( ) {
117
+ return this . rowData [ this . rowDimensionData . dimension . memberName + this . grid . pivotKeys . rowDimensionSeparator + 'rowSpan' ] || 1 ;
118
+ }
119
+
120
+ get headerHeight ( ) {
121
+ return this . rowSpan * this . grid . renderedRowHeight ;
122
+ }
123
+
124
+ get isFirst ( ) {
125
+ const hasRowSpan = this . rowSpan && this . rowSpan > 1 ;
126
+ return ! hasRowSpan || this . rowData [ this . rowDimensionData . dimension . memberName + this . grid . pivotKeys . rowDimensionSeparator + 'first' ] ;
127
+ }
128
+
115
129
116
130
/**
117
131
* @hidden @internal
@@ -129,91 +143,41 @@ export class IgxPivotRowDimensionContentComponent extends IgxGridHeaderRowCompon
129
143
}
130
144
}
131
145
132
- protected extractFromDimensions ( rowDimConfig : IPivotDimension [ ] , level : number ) {
133
- let dimIndex = 0 ;
134
- let currentLvl = 0 ;
135
- currentLvl += level ;
136
- const prev = [ ] ;
137
- let prevDim ;
138
- for ( const dim of rowDimConfig ) {
139
- const dimData = PivotUtil . getDimensionLevel ( dim , this . rowData , this . grid . pivotKeys ) ;
140
- dimIndex += dimData . level ;
141
- currentLvl += dimData . level ;
142
- const prevChildren = prevDim ? this . rowData [ prevDim . memberName + this . grid . pivotKeys . rowDimensionSeparator + this . grid . pivotKeys . children ] : [ ] ;
143
- if ( prevChildren && prevChildren . length > 0 ) {
144
- const childrenCols = [ ] ;
145
- const layoutCol = this . rowDimensionData . find ( x => x . column . columnLayout ) . column ;
146
- prevChildren . forEach ( ( childData , index ) => {
147
- const dimData = PivotUtil . getDimensionLevel ( dim , childData , this . grid . pivotKeys ) ;
148
- dimIndex += dimData . level ;
149
- currentLvl += dimData . level ;
150
- const column = this . extractFromDimension ( dimData . dimension , childData , [ ] , dimIndex , currentLvl , dim , [ ...prev ] ) ;
151
- column . rowStart = index + 1 ;
152
- column . rowEnd = index + 2 ;
153
- column . colStart = 2 ;
154
- childrenCols . push ( column ) ;
155
- this . rowDimensionData . push ( {
156
- column,
157
- dimension : dimData . dimension ,
158
- prevDimensions : [ ...prev ] ,
159
- isChild : true
160
- } ) ;
161
- } ) ;
162
- const all_children = layoutCol . children . toArray ( ) . concat ( childrenCols ) ;
163
- layoutCol . children . reset ( all_children ) ;
164
- continue ;
165
- }
166
- const children = this . rowData [ dim . memberName + this . grid . pivotKeys . rowDimensionSeparator + this . grid . pivotKeys . children ] ;
167
- const column = this . extractFromDimension ( dimData . dimension , this . rowData , children , dimIndex , currentLvl , dim , [ ...prev ] ) ;
168
- this . rowDimensionData . push ( {
169
- column,
170
- dimension : dimData . dimension ,
171
- prevDimensions : [ ...prev ]
172
- } ) ;
173
- prevDim = dim ;
174
- prev . push ( dimData . dimension ) ;
146
+ protected extractFromDimensions ( ) {
147
+ const dimData = PivotUtil . getDimensionLevel ( this . dimension , this . rowData , this . grid . pivotKeys ) ;
148
+ const col = this . extractFromDimension ( dimData , this . rowData ) ;
149
+ const prevDims = this . getPrevDims ( this . dimension ) ;
150
+ this . rowDimensionData = {
151
+ column : col ,
152
+ dimension : dimData . dimension ,
153
+ prevDimensions : prevDims
154
+ } ;
155
+ }
156
+
157
+ protected getPrevDims ( currDim ) {
158
+ const ind = this . grid . rowDimensions . indexOf ( currDim ) ;
159
+ const prevDims = [ ] ;
160
+ for ( let i = 0 ; i < ind - 1 ; i ++ ) {
161
+ const prevDim = this . grid . rowDimensions [ i ] ;
162
+ const dimData = PivotUtil . getDimensionLevel ( prevDim , this . rowData , this . grid . pivotKeys ) ;
163
+ prevDims . push ( dimData . dimension ) ;
175
164
}
165
+ return prevDims ;
176
166
}
177
167
178
- protected extractFromDimension ( dim : IPivotDimension , rowData : any [ ] , children : any [ ] , index : number = 0 , lvl = 0 , rootDim : IPivotDimension , prevDims ) {
179
- const field = dim . memberName ;
168
+ protected extractFromDimension ( dimData , rowData : any [ ] ) {
169
+ const field = dimData . dimension . memberName ;
180
170
const header = rowData [ field ] ;
181
- let col ;
182
- if ( children && children . length > 0 ) {
183
- const ref = this . viewRef . createComponent ( IgxColumnLayoutComponent ) ;
184
- col = ref . instance ;
185
- ref . instance . field = 'group' ;
186
- const childCol = this . _createColComponent ( field , header , children , index , dim , lvl , rootDim ) ;
187
- ref . instance . children . reset ( [ childCol ] ) ;
188
- this . rowDimensionData . push ( {
189
- column : childCol ,
190
- dimension : dim ,
191
- prevDimensions : prevDims ,
192
- isChild : true
193
- } ) ;
194
- } else {
195
- col = this . _createColComponent ( field , header , children , index , dim , lvl , rootDim ) ;
196
- }
171
+ const col = this . _createColComponent ( field , header , dimData . dimension , dimData . level ) ;
197
172
return col ;
198
173
}
199
174
200
- protected _createColComponent ( field : string , header : string , children : any [ ] ,
201
- index : number = 0 ,
202
- dim : IPivotDimension , lvl = 0 , rootDim : IPivotDimension ) {
175
+ protected _createColComponent ( field : string , header : string , dim : IPivotDimension , lvl ) {
203
176
const ref = this . viewRef . createComponent ( IgxColumnComponent ) ;
204
- if ( children && children . length > 0 ) {
205
- ref . instance . rowStart = 1 ;
206
- ref . instance . rowEnd = children . length + 1 ;
207
- ref . instance . colStart = 1 ;
208
- } else {
209
- ref . instance . colStart = 2 ;
210
- ref . instance . rowStart = 1 ;
211
- ref . instance . rowEnd = 2 ;
212
- }
213
177
ref . instance . field = field ;
214
178
ref . instance . header = header ;
215
- ref . instance . width = this . grid . resolveRowDimensionWidth ( rootDim ) + 'px' ;
216
- ( ref as any ) . instance . _vIndex = this . grid . columns . length + index + this . rowIndex * this . grid . pivotConfiguration . rows . length ;
179
+ ref . instance . width = this . grid . resolveRowDimensionWidth ( this . dimension ) + 'px' ;
180
+ ( ref as any ) . instance . _vIndex = this . grid . columns . length + this . rowIndex + this . rowIndex * this . grid . pivotConfiguration . rows . length ;
217
181
if ( dim . childLevel && lvl >= PivotUtil . getTotalLvl ( this . rowData , this . grid . pivotKeys ) ) {
218
182
ref . instance . headerTemplate = this . headerTemplate ;
219
183
} else {
0 commit comments