Skip to content

Commit cd7687f

Browse files
authored
Merge pull request #10420 from IgniteUI/mkirova/fix-expand-rowid
Apply more complex row dimension key for expand/collapse based on pre…
2 parents cc6b195 + aef8de5 commit cd7687f

File tree

4 files changed

+45
-46
lines changed

4 files changed

+45
-46
lines changed

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.interface.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { GridColumnDataType } from '../../data-operations/data-util';
22
import { FilteringExpressionsTree } from '../../data-operations/filtering-expressions-tree';
33
import { IPivotDimensionStrategy } from '../../data-operations/pivot-strategy';
4-
5-
4+
import { IgxColumnComponent } from '../columns/column.component';
65

76
export type PivotAggregation = (members: any[], data: any[]) => any;
87

@@ -60,3 +59,9 @@ export enum PivotDimensionType {
6059
Column,
6160
Filter
6261
}
62+
63+
export interface IPivotDimensionData {
64+
column: IgxColumnComponent;
65+
dimension: IPivotDimension;
66+
prevDimensions: IPivotDimension[];
67+
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-row.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IgxPivotGridComponent } from './pivot-grid.component';
1515
import { IgxRowDirective } from '../row.directive';
1616
import { GridBaseAPIService, IgxColumnComponent } from '../hierarchical-grid/public_api';
1717
import { IgxGridSelectionService } from '../selection/selection.service';
18-
import { IPivotDimension } from './pivot-grid.interface';
18+
import { IPivotDimension, IPivotDimensionData } from './pivot-grid.interface';
1919
import { PivotUtil } from './pivot-util';
2020

2121

@@ -40,7 +40,11 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
4040
@ViewChild('headerTemplateGray', { read: TemplateRef, static: true })
4141
public headerTemplateGray: TemplateRef<any>;
4242

43-
public rowDimension: IgxColumnComponent[] = [];
43+
public rowDimensionData: IPivotDimensionData[] = [];
44+
45+
public get rowDimension() {
46+
return this.rowDimensionData?.map(x => x.column);
47+
}
4448

4549
constructor(
4650
public gridAPI: GridBaseAPIService<IgxPivotGridComponent>,
@@ -65,7 +69,8 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
6569
* @internal
6670
*/
6771
public getRowDimensionKey(col: IgxColumnComponent) {
68-
const key = PivotUtil.getRecordKey(this.rowData, this.rowData[col.field]);
72+
const dimData = this.rowDimensionData.find(x => x.column === col);
73+
const key = PivotUtil.getRecordKey(this.rowData, dimData.dimension, dimData.prevDimensions);
6974
return key;
7075
}
7176

@@ -81,7 +86,7 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
8186
public ngOnChanges(changes: SimpleChanges) {
8287
if (changes.rowData) {
8388
// generate new rowDimension on row data change
84-
this.rowDimension = [];
89+
this.rowDimensionData = [];
8590
const rowDimConfig = this.grid.rowDimensions;
8691
this.extractFromDimensions(rowDimConfig, 0);
8792
}
@@ -101,12 +106,19 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
101106
let dimIndex = 0;
102107
let currentLvl = 0;
103108
currentLvl += level;
109+
const prev = [];
104110
for (const dim of rowDimConfig) {
105111
const dimData = PivotUtil.getDimensionLevel(dim, this.rowData,
106112
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
107113
dimIndex += dimData.level;
108114
currentLvl += dimData.level;
109-
this.rowDimension.push(this.extractFromDimension(dimData.dimension, dimIndex, currentLvl));
115+
const column = this.extractFromDimension(dimData.dimension, dimIndex, currentLvl);
116+
this.rowDimensionData.push({
117+
column,
118+
dimension: dimData.dimension,
119+
prevDimensions: [...prev]
120+
});
121+
prev.push(dimData.dimension);
110122
}
111123
}
112124

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-util.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class PivotUtil {
6060
continue;
6161
}
6262
rec[field + '_' + pivotKeys.level] = currDimLvl;
63-
const expansionRowKey = PivotUtil.getRecordKey(rec, rec[field]);
63+
const expansionRowKey = PivotUtil.getRecordKey(rec, dim, prevDims);
6464
const isExpanded = expansionStates.get(expansionRowKey) === undefined ?
6565
defaultExpandState :
6666
expansionStates.get(expansionRowKey);
@@ -299,20 +299,17 @@ export class PivotUtil {
299299
return leafs;
300300
}
301301

302-
public static getRecordKey(rec, key) {
303-
const pivotKeys = { aggregations: 'aggregations', records: 'records', children: 'children', level: 'level' };
302+
public static getRecordKey(rec, currentDim: IPivotDimension, prevDims: IPivotDimension[]) {
304303
const parentFields = [];
305-
for (const property in rec) {
306-
if (rec.hasOwnProperty(property) &&
307-
Object.keys(pivotKeys).indexOf(property) === -1
308-
&& Object.keys(pivotKeys).filter(x => property.indexOf(x) !== -1).length === 0) {
309-
const currLevel = rec[property + '_level'];
310-
if (currLevel > 0) {
311-
parentFields.unshift(rec[property]);
312-
}
313-
}
304+
const field = currentDim.memberName;
305+
const value = rec[field];
306+
for(const prev of prevDims) {
307+
const dimData = PivotUtil.getDimensionLevel(prev, rec,
308+
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
309+
parentFields.push(rec[dimData.dimension.memberName]);
314310
}
315-
return parentFields.concat(key).join('_');
311+
parentFields.push(value);
312+
return parentFields.join('_');
316313
}
317314

318315
public static getTotalLvl(rec) {

src/app/pivot-grid/pivot-grid.sample.ts

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,20 @@ export class PivotGridSampleComponent {
3030
}
3131
]
3232
,
33-
rows: [
34-
{
35-
memberName: 'AllProd',
36-
memberFunction: () => 'AllProd',
37-
enabled: true,
38-
childLevel: {
33+
rows: [{
34+
memberName: 'City',
35+
enabled: true
36+
}, {
37+
memberFunction: () => 'All',
38+
memberName: 'AllProducts',
39+
enabled: true,
40+
childLevel:
41+
{
42+
memberFunction: (data) => data.ProductCategory,
3943
memberName: 'ProductCategory',
4044
enabled: true
4145
}
42-
},
43-
{
44-
memberName: 'AllDate',
45-
memberFunction: () => 'AllDate',
46-
enabled: true,
47-
childLevel: {
48-
memberName: 'Date',
49-
enabled: true
50-
}
51-
},
52-
{
53-
memberName: 'AllSel',
54-
memberFunction: () => 'AllSel',
55-
enabled: true,
56-
childLevel: {
57-
memberName: 'SellerName',
58-
enabled: true
59-
}
60-
}
61-
],
46+
}],
6247
values: [
6348
{
6449
member: 'UnitsSold',

0 commit comments

Comments
 (0)