@@ -5,7 +5,7 @@ import { PivotUtil } from '../grids/pivot-grid/pivot-util';
5
5
import { FilteringStrategy } from './filtering-strategy' ;
6
6
import { GridColumnDataType } from './data-util' ;
7
7
import { DefaultSortingStrategy , SortingDirection } from './sorting-strategy' ;
8
- import { parseDate } from '../core/utils' ;
8
+ import { cloneArray , parseDate } from '../core/utils' ;
9
9
10
10
export class NoopPivotDimensionsStrategy implements IPivotDimensionStrategy {
11
11
private static _instance : NoopPivotDimensionsStrategy = null ;
@@ -28,51 +28,53 @@ export class PivotRowDimensionsStrategy implements IPivotDimensionStrategy {
28
28
}
29
29
30
30
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 leafData = PivotUtil . getDirectLeafs ( currData , pivotKeys ) ;
54
- const hierarchyFields = PivotUtil
55
- . getFieldsHierarchy ( leafData , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
56
- const siblingData = PivotUtil
57
- . processHierarchy ( hierarchyFields , newData [ i ] ?? [ ] , pivotKeys , 0 ) ;
58
- PivotUtil . processSiblingProperties ( newData [ i ] , siblingData , pivotKeys ) ;
59
-
60
- PivotUtil . processSubGroups ( row , prevRowDims . slice ( 0 ) , siblingData , pivotKeys ) ;
61
- if ( siblingData . length > 1 ) {
62
- newData [ i ] [ row . memberName + '_' + pivotKeys . records ] = siblingData ;
63
- } else {
64
- newData . splice ( i , 1 , ...siblingData ) ;
65
- }
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
+ const currRows = cloneArray ( rows , true ) ;
42
+ PivotUtil . assignLevels ( currRows ) ;
43
+ for ( const row of currRows ) {
44
+ if ( ! data ) {
45
+ // build hierarchies - groups and subgroups
46
+ hierarchies = PivotUtil . getFieldsHierarchy ( collection , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
47
+ // generate flat data from the hierarchies
48
+ data = PivotUtil . processHierarchy ( hierarchies , collection [ 0 ] ?? [ ] , pivotKeys , 0 , true ) ;
49
+ prevRowDims . push ( row ) ;
50
+ prevDim = row ;
51
+ } else {
52
+ const newData = [ ...data ] ;
53
+ for ( let i = 0 ; i < newData . length ; i ++ ) {
54
+ const currData = newData [ i ] [ prevDim . memberName + '_' + pivotKeys . records ] ;
55
+ const leafData = PivotUtil . getDirectLeafs ( currData , pivotKeys ) ;
56
+ const hierarchyFields = PivotUtil
57
+ . getFieldsHierarchy ( leafData , [ row ] , PivotDimensionType . Row , pivotKeys ) ;
58
+ const siblingData = PivotUtil
59
+ . processHierarchy ( hierarchyFields , newData [ i ] ?? [ ] , pivotKeys , 0 ) ;
60
+ PivotUtil . processSiblingProperties ( newData [ i ] , siblingData , pivotKeys ) ;
61
+
62
+ PivotUtil . processSubGroups ( row , prevRowDims . slice ( 0 ) , siblingData , pivotKeys ) ;
63
+ if ( PivotUtil . getDimensionDepth ( prevDim ) > PivotUtil . getDimensionDepth ( row ) && siblingData . length > 1 ) {
64
+ newData [ i ] [ row . memberName + '_' + pivotKeys . records ] = siblingData ;
65
+ } else {
66
+ newData . splice ( i , 1 , ...siblingData ) ;
66
67
i += siblingData . length - 1 ;
67
68
}
68
- data = newData ;
69
- prevDim = row ;
70
- prevRowDims . push ( row ) ;
71
69
}
70
+ data = newData ;
71
+ prevDim = row ;
72
+ prevRowDims . push ( row ) ;
72
73
}
73
- return data ;
74
74
}
75
+ return data ;
75
76
}
77
+ }
76
78
77
79
export class PivotColumnDimensionsStrategy implements IPivotDimensionStrategy {
78
80
private static _instance : PivotRowDimensionsStrategy = null ;
@@ -175,7 +177,7 @@ export class DimensionValuesFilteringStrategy extends FilteringStrategy {
175
177
}
176
178
177
179
protected getFieldValue ( rec : any , fieldName : string , isDate : boolean = false , isTime : boolean = false ,
178
- grid ?: PivotGridType ) : any {
180
+ grid ?: PivotGridType ) : any {
179
181
const config = grid . pivotConfiguration ;
180
182
const allDimensions = config . rows . concat ( config . columns ) . concat ( config . filters ) . filter ( x => x !== null ) ;
181
183
const enabledDimensions = allDimensions . filter ( x => x && x . enabled ) ;
@@ -191,13 +193,13 @@ export class DefaultPivotSortingStrategy extends DefaultSortingStrategy {
191
193
return this . _instance || ( this . _instance = new this ( ) ) ;
192
194
}
193
195
public sort ( data : any [ ] ,
194
- fieldName : string ,
195
- dir : SortingDirection ,
196
- ignoreCase : boolean ,
197
- valueResolver : ( obj : any , key : string , isDate ?: boolean ) => any ,
198
- isDate ?: boolean ,
199
- isTime ?: boolean ,
200
- grid ?: PivotGridType ) {
196
+ fieldName : string ,
197
+ dir : SortingDirection ,
198
+ ignoreCase : boolean ,
199
+ valueResolver : ( obj : any , key : string , isDate ?: boolean ) => any ,
200
+ isDate ?: boolean ,
201
+ isTime ?: boolean ,
202
+ grid ?: PivotGridType ) {
201
203
const key = fieldName ;
202
204
const config = grid . pivotConfiguration ;
203
205
const allDimensions = config . rows . concat ( config . columns ) . concat ( config . filters ) . filter ( x => x !== null ) ;
0 commit comments