@@ -114,6 +114,16 @@ export class PivotUtil {
114114 data . splice ( i , 1 , ...dimData ) ;
115115 i += dimData . length - 1 ;
116116 }
117+ } else {
118+ // this is leaf
119+ let leafDim = dim ;
120+ let currLvl = currDimLvl ;
121+ while ( leafDim . childLevel ) {
122+ leafDim = leafDim . childLevel ;
123+ currLvl ++ ;
124+ }
125+ rec [ leafDim . memberName + '_' + pivotKeys . level ] = currLvl ;
126+ rec [ field + '_' + pivotKeys . level ] = undefined ;
117127 }
118128 }
119129 return data ;
@@ -227,21 +237,21 @@ export class PivotUtil {
227237 . getFieldsHierarchy ( child [ pivotKeys . records ] , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
228238 const siblingData2 = PivotUtil
229239 . processHierarchy ( hierarchyFields2 , child ?? [ ] , keys , 0 ) ;
230- if ( siblingData2 . length === 1 ) {
231- child [ row . memberName ] = sibling [ row . memberName ] ;
232- // add children to current level if dimensions have same depth
233- for ( const sib of siblingData2 ) {
234- if ( sib [ row . memberName + '_' + pivotKeys . records ] ) {
235- child [ row . memberName + '_' + pivotKeys . records ] =
236- child [ row . memberName + '_' + pivotKeys . records ]
240+ if ( siblingData2 . length === 1 ) {
241+ child [ row . memberName ] = sibling [ row . memberName ] ;
242+ // add children to current level if dimensions have same depth
243+ for ( const sib of siblingData2 ) {
244+ if ( sib [ row . memberName + '_' + pivotKeys . records ] ) {
245+ child [ row . memberName + '_' + pivotKeys . records ] =
246+ child [ row . memberName + '_' + pivotKeys . records ]
237247 . concat ( sib [ row . memberName + '_' + pivotKeys . records ] ) ;
238- child [ row . memberName ] = sib [ row . memberName ] ;
239- }
248+ child [ row . memberName ] = sib [ row . memberName ] ;
240249 }
241- } else {
242- // otherwise overwrite direct child collection
243- child [ row . memberName + '_' + pivotKeys . records ] = siblingData2 ;
244250 }
251+ } else {
252+ // otherwise overwrite direct child collection
253+ child [ row . memberName + '_' + pivotKeys . records ] = siblingData2 ;
254+ }
245255 PivotUtil . processSiblingProperties ( child , siblingData2 , keys ) ;
246256 }
247257 if ( prevRowDim . childLevel ) {
@@ -270,6 +280,12 @@ export class PivotUtil {
270280 if ( h [ pivotKeys . children ] && h [ pivotKeys . children ] . size > 0 ) {
271281 const nestedData = this . processHierarchy ( h [ pivotKeys . children ] , rec ,
272282 pivotKeys , level + 1 , rootData ) ;
283+ for ( const nested of nestedData ) {
284+ if ( nested [ pivotKeys . records ] && nested [ pivotKeys . records ] . length === 1 ) {
285+ // only 1 child record, apply same props to parent.
286+ PivotUtil . processSiblingProperties ( nested [ pivotKeys . records ] [ 0 ] , [ nested ] , pivotKeys ) ;
287+ }
288+ }
273289 obj [ pivotKeys . records ] = this . getDirectLeafs ( nestedData , pivotKeys ) ;
274290 obj [ field + '_' + pivotKeys . records ] = nestedData ;
275291 if ( ! rootData ) {
@@ -298,10 +314,10 @@ export class PivotUtil {
298314 const parentFields = [ ] ;
299315 const field = currentDim . memberName ;
300316 const value = rec [ field ] ;
301- for ( const prev of prevDims ) {
317+ for ( const prev of prevDims ) {
302318 const dimData = PivotUtil . getDimensionLevel ( prev , rec ,
303- { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ) ;
304- parentFields . push ( rec [ dimData . dimension . memberName ] ) ;
319+ { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' } ) ;
320+ parentFields . push ( rec [ dimData . dimension . memberName ] ) ;
305321 }
306322 parentFields . push ( value ) ;
307323 return parentFields . join ( '_' ) ;
0 commit comments