@@ -38,6 +38,7 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
3838 let data ;
3939 const prevRowDims = [ ] ;
4040 let prevDim ;
41+ let prevDimTopRecords = [ ] ;
4142 const currRows = cloneArray ( rows , true ) ;
4243 PivotUtil . assignLevels ( currRows ) ;
4344 for ( const row of currRows ) {
@@ -48,8 +49,10 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
4849 data = PivotUtil . processHierarchy ( hierarchies , collection [ 0 ] ?? [ ] , pivotKeys , 0 , true ) ;
4950 prevRowDims . push ( row ) ;
5051 prevDim = row ;
52+ prevDimTopRecords = data ;
5153 } else {
5254 const newData = [ ...data ] ;
55+ const curDimTopRecords = [ ] ;
5356 for ( let i = 0 ; i < newData . length ; i ++ ) {
5457 const currData = newData [ i ] [ prevDim . memberName + '_' + pivotKeys . records ] ;
5558 const leafData = PivotUtil . getDirectLeafs ( currData , pivotKeys ) ;
@@ -60,15 +63,22 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
6063 PivotUtil . processSiblingProperties ( newData [ i ] , siblingData , pivotKeys ) ;
6164
6265 PivotUtil . processSubGroups ( row , prevRowDims . slice ( 0 ) , siblingData , pivotKeys ) ;
63- if ( PivotUtil . getDimensionDepth ( prevDim ) > PivotUtil . getDimensionDepth ( row ) && siblingData . length > 1 ) {
66+ if ( ( prevDimTopRecords [ i ] . length != undefined && prevDimTopRecords [ i ] . length < siblingData . length ) || prevDimTopRecords . length <= siblingData . length ) {
6467 newData [ i ] [ row . memberName + '_' + pivotKeys . records ] = siblingData ;
6568 } else {
6669 newData . splice ( i , 1 , ...siblingData ) ;
70+ if ( prevDimTopRecords [ i ] . length == undefined ) {
71+ prevDimTopRecords . splice ( siblingData . length , prevDimTopRecords . length - siblingData . length , ...prevDimTopRecords ) ;
72+ } else {
73+ prevDimTopRecords [ i ] . splice ( siblingData . length , prevDimTopRecords . length - siblingData . length , ...prevDimTopRecords [ i ] ) ;
74+ }
6775 i += siblingData . length - 1 ;
6876 }
77+ curDimTopRecords . push ( cloneArray ( siblingData , true ) ) ;
6978 }
7079 data = newData ;
7180 prevDim = row ;
81+ prevDimTopRecords = curDimTopRecords ;
7282 prevRowDims . push ( row ) ;
7383 }
7484 }
0 commit comments