Skip to content

Commit d996ffc

Browse files
MKirovaMKirova
authored andcommitted
Apply more complex row dimension key for expand/collapse based on previous dimensions.
1 parent 5fe7bdd commit d996ffc

File tree

5 files changed

+55
-52
lines changed

5 files changed

+55
-52
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

@@ -57,3 +56,9 @@ export enum PivotDimensionType {
5756
Row,
5857
Column
5958
}
59+
60+
export interface IPivotDimensionData {
61+
column: IgxColumnComponent;
62+
dimension: IPivotDimension;
63+
prevDimensions: IPivotDimension[];
64+
}

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
@@ -16,7 +16,7 @@ import { IgxPivotGridComponent } from './pivot-grid.component';
1616
import { IgxRowDirective } from '../row.directive';
1717
import { GridBaseAPIService, IgxColumnComponent } from '../hierarchical-grid/public_api';
1818
import { IgxGridSelectionService } from '../selection/selection.service';
19-
import { IPivotDimension } from './pivot-grid.interface';
19+
import { IPivotDimension, IPivotDimensionData } from './pivot-grid.interface';
2020
import { PivotUtil } from './pivot-util';
2121

2222

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

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

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

@@ -82,7 +87,7 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
8287
public ngOnChanges(changes: SimpleChanges) {
8388
if (changes.rowData) {
8489
// generate new rowDimension on row data change
85-
this.rowDimension = [];
90+
this.rowDimensionData = [];
8691
const rowDimConfig = this.grid.pivotConfiguration.rows;
8792
this.extractFromDimensions(rowDimConfig, 0);
8893
}
@@ -102,12 +107,19 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
102107
let dimIndex = 0;
103108
let currentLvl = 0;
104109
currentLvl += level;
110+
const prev = [];
105111
for (const dim of rowDimConfig) {
106112
const dimData = PivotUtil.getDimensionLevel(dim, this.rowData,
107113
{ aggregations: 'aggregations', records: 'records', children: 'children', level: 'level'});
108114
dimIndex += dimData.level;
109115
currentLvl += dimData.level;
110-
this.rowDimension.push(this.extractFromDimension(dimData.dimension, dimIndex, currentLvl));
116+
const column = this.extractFromDimension(dimData.dimension, dimIndex, currentLvl);
117+
this.rowDimensionData.push({
118+
column,
119+
dimension: dimData.dimension,
120+
prevDimensions: [...prev]
121+
});
122+
prev.push(dimData.dimension);
111123
}
112124
}
113125

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-hierarchy/pivot-grid-hierarchy.sample.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,32 @@ export class PivotGridHierarchySampleComponent {
1414

1515
public pivotConfigHierarchy: IPivotConfiguration = {
1616
columns: [{
17-
member: () => 'All',
17+
memberName: 'AllProducts',
18+
memberFunction: () => 'All',
1819
enabled: true,
1920
childLevel:
2021
{
21-
22-
member: (data) => data.Product.Name,
22+
memberName: 'Product',
23+
memberFunction: (data) => data.Product.Name,
2324
enabled: true,
2425
childLevel:
2526
{
26-
member: (data) => data.Seller.City,
27+
memberName: 'City',
28+
memberFunction: (data) => data.Seller.City,
2729
enabled: true,
2830
}
2931

3032
}
3133
},
3234
],
3335
rows: [{
34-
member: () => 'All',
36+
memberName: 'AllSeller',
37+
memberFunction: () => 'All',
3538
enabled: true,
3639
childLevel:
3740
{
38-
member: (data) => data.Seller.Name,
41+
memberName: 'Seller',
42+
memberFunction: (data) => data.Seller.Name,
3943
enabled: true,
4044
}
4145
}],

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)