@@ -28,33 +28,33 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
2828 }
2929
3030 public process (
31- collection : any ,
32- rows : IPivotDimension [ ] ,
33- values ?: IPivotValue [ ] ,
34- pivotKeys : IPivotKeys =
35- { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
36- ) : any [ ] {
37- let hierarchies ;
38- let data ;
39- const prevRowDims = [ ] ;
40- let prevDim ;
41- for ( const row of rows ) {
42- if ( ! data ) {
43- // build hierarchies - groups and subgroups
44- hierarchies = PivotUtil . getFieldsHierarchy ( collection , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
45- // generate flat data from the hierarchies
46- data = PivotUtil . processHierarchy ( hierarchies , collection [ 0 ] ?? [ ] , pivotKeys , 0 , true ) ;
47- prevRowDims . push ( row ) ;
48- prevDim = row ;
49- } else {
50- const newData = [ ...data ] ;
51- for ( let i = 0 ; i < newData . length ; i ++ ) {
52- const currData = newData [ i ] [ prevDim . memberName + '_' + pivotKeys . records ] ;
53- const hierarchyFields = PivotUtil
54- . getFieldsHierarchy ( currData , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
55- const siblingData = PivotUtil
56- . processHierarchy ( hierarchyFields , newData [ i ] ?? [ ] , pivotKeys , 0 ) ;
57- PivotUtil . processSiblingProperties ( newData [ i ] , siblingData , pivotKeys ) ;
31+ collection : any ,
32+ rows : IPivotDimension [ ] ,
33+ values ?: IPivotValue [ ] ,
34+ pivotKeys : IPivotKeys =
35+ { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
36+ ) : any [ ] {
37+ let hierarchies ;
38+ let data ;
39+ const prevRowDims = [ ] ;
40+ let prevDim ;
41+ for ( const row of rows ) {
42+ if ( ! data ) {
43+ // build hierarchies - groups and subgroups
44+ hierarchies = PivotUtil . getFieldsHierarchy ( collection , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
45+ // generate flat data from the hierarchies
46+ data = PivotUtil . processHierarchy ( hierarchies , collection [ 0 ] ?? [ ] , pivotKeys , 0 , true ) ;
47+ prevRowDims . push ( row ) ;
48+ prevDim = row ;
49+ } else {
50+ const newData = [ ...data ] ;
51+ for ( let i = 0 ; i < newData . length ; i ++ ) {
52+ const currData = newData [ i ] [ prevDim . memberName + '_' + pivotKeys . records ] ;
53+ const hierarchyFields = PivotUtil
54+ . getFieldsHierarchy ( currData , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
55+ const siblingData = PivotUtil
56+ . processHierarchy ( hierarchyFields , newData [ i ] ?? [ ] , pivotKeys , 0 ) ;
57+ PivotUtil . processSiblingProperties ( newData [ i ] , siblingData , pivotKeys ) ;
5858
5959 PivotUtil . processSubGroups ( row , prevRowDims . slice ( 0 ) , siblingData , pivotKeys ) ;
6060 if ( siblingData . length > 1 ) {
@@ -81,43 +81,57 @@ export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
8181 }
8282
8383 public process (
84- collection : any [ ] ,
85- columns : IPivotDimension [ ] ,
86- values : IPivotValue [ ] ,
87- pivotKeys : IPivotKeys = { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
88- ) : any [ ] {
89- const result = [ ] ;
90- collection . forEach ( hierarchy => {
91- // apply aggregations based on the created groups and generate column fields based on the hierarchies
92- this . groupColumns ( hierarchy , columns , values , pivotKeys ) ;
93- if ( hierarchy [ pivotKeys . children ] ) {
94- let flatCols = { } ;
95- PivotUtil . flattenColumnHierarchy ( hierarchy [ pivotKeys . children ] , values , pivotKeys ) . forEach ( o => {
96- delete o [ pivotKeys . records ] ;
97- flatCols = { ...flatCols , ...o } ;
98- } ) ;
99- delete hierarchy [ pivotKeys . children ] ; /* or we can keep it
100- and use when creating the columns in pivot grid instead of recreating it */
101- const keys = Object . keys ( hierarchy ) ;
102- //remove all record keys from final data since we don't need them anymore.
103- keys . forEach ( k => {
104- if ( k . indexOf ( pivotKeys . records ) !== - 1 || k === pivotKeys . level ) {
105- delete hierarchy [ k ] ;
84+ collection : any [ ] ,
85+ columns : IPivotDimension [ ] ,
86+ values : IPivotValue [ ] ,
87+ pivotKeys : IPivotKeys = { aggregations : 'aggregations' , records : 'records' , children : 'children' , level : 'level' }
88+ ) : any [ ] {
89+ const res = this . processHierarchy ( collection , columns , values , pivotKeys ) ;
90+ return res ;
91+ }
92+
93+ private processHierarchy ( collection , columns : IPivotDimension [ ] , values , pivotKeys ) {
94+ const result = [ ] ;
95+ collection . forEach ( hierarchy => {
96+ // apply aggregations based on the created groups and generate column fields based on the hierarchies
97+ this . groupColumns ( hierarchy , columns , values , pivotKeys ) ;
98+ if ( hierarchy [ pivotKeys . children ] ) {
99+ let flatCols = { } ;
100+ PivotUtil . flattenColumnHierarchy ( hierarchy [ pivotKeys . children ] , values , pivotKeys ) . forEach ( o => {
101+ delete o [ pivotKeys . records ] ;
102+ flatCols = { ...flatCols , ...o } ;
103+ } ) ;
104+ delete hierarchy [ pivotKeys . children ] ; /* or we can keep it
105+ and use when creating the columns in pivot grid instead of recreating it */
106+ const keys = Object . keys ( hierarchy ) ;
107+ //remove all record keys from final data since we don't need them anymore.
108+ hierarchy . processed = true ;
109+ keys . forEach ( k => {
110+ if ( k . indexOf ( pivotKeys . records ) !== - 1 ) {
111+ if ( hierarchy [ k ] && hierarchy [ k ] . length > 0 && k !== pivotKeys . records ) {
112+ const unprocessed = hierarchy [ k ] . filter ( r => ! r . processed ) ;
113+ this . processHierarchy ( unprocessed , columns , values , pivotKeys ) ;
106114 }
107- } ) ;
108- if ( this . isLeaf ( hierarchy , pivotKeys ) ) {
109- delete hierarchy [ pivotKeys . records ] ; /* remove the helper records of the actual records so that
110- expand indicators can be rendered properly */
115+ //delete hierarchy[k];
111116 }
112- for ( const property in flatCols ) {
113- if ( flatCols . hasOwnProperty ( property ) ) {
114- hierarchy [ property ] = flatCols [ property ] ;
115- }
117+ if ( k === pivotKeys . level ) {
118+ delete hierarchy [ k ] ;
119+ }
120+ } ) ;
121+ delete hierarchy . processed ;
122+ if ( this . isLeaf ( hierarchy , pivotKeys ) ) {
123+ delete hierarchy [ pivotKeys . records ] ; /* remove the helper records of the actual records so that
124+ expand indicators can be rendered properly */
125+ }
126+ for ( const property in flatCols ) {
127+ if ( flatCols . hasOwnProperty ( property ) ) {
128+ hierarchy [ property ] = flatCols [ property ] ;
116129 }
117- result . push ( hierarchy ) ;
118130 }
119- } ) ;
120- return result ;
131+ result . push ( hierarchy ) ;
132+ }
133+ } ) ;
134+ return result ;
121135 }
122136
123137 private groupColumns ( hierarchy , columns , values , pivotKeys ) {
0 commit comments