Skip to content

Commit f53b238

Browse files
MKirovaMKirova
authored andcommitted
Add handling for levels and expand/collapse indicators.
1 parent 872516a commit f53b238

File tree

4 files changed

+86
-14
lines changed

4 files changed

+86
-14
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,16 @@
9494
[cellSelectionMode]="grid.cellSelection"
9595
[displayPinnedChip]="shouldDisplayPinnedChip(col.visibleIndex)">
9696
</igx-grid-cell>
97+
</ng-template>
98+
99+
100+
<ng-template #headerTemplate let-column>
101+
<div class="header-group-template__container">
102+
<igx-icon [attr.draggable]="false"
103+
(click)="grid.toggleRow(rowID)"
104+
style='cursor: pointer;'
105+
class="header-group-template__icon">
106+
{{grid.expansionStates.get(rowID) ? 'expand_more' : 'expand_less'}}</igx-icon>
107+
{{column.header}}
108+
</div>
97109
</ng-template>

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import {
66
ElementRef,
77
forwardRef,
88
OnInit,
9+
TemplateRef,
10+
ViewChild,
911
ViewContainerRef
1012
} from '@angular/core';
1113
import { IgxPivotGridComponent } from './pivot-grid.component';
1214
import { IgxRowDirective } from '../row.directive';
1315
import { GridBaseAPIService, IgxColumnComponent } from '../hierarchical-grid/public_api';
1416
import { IgxGridSelectionService } from '../selection/selection.service';
17+
import { IPivotDimension } from './pivot-grid.interface';
1518

1619

1720
const MINIMUM_COLUMN_WIDTH = 136;
@@ -23,8 +26,15 @@ const MINIMUM_COLUMN_WIDTH = 136;
2326
})
2427
export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent> implements OnInit {
2528

29+
/**
30+
* @hidden @internal
31+
*/
32+
@ViewChild('headerTemplate', { read: TemplateRef, static: true })
33+
public headerTemplate: TemplateRef<any>;
2634

2735
public rowDimension: IgxColumnComponent[] = [];
36+
public level = 0;
37+
protected hasChild = false;
2838

2939
constructor(
3040
public gridAPI: GridBaseAPIService<IgxPivotGridComponent>,
@@ -36,7 +46,6 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
3646
){
3747
super(gridAPI, selectionService, element, cdr);
3848
}
39-
4049
/**
4150
* @hidden
4251
* @internal
@@ -48,24 +57,43 @@ export class IgxPivotRowComponent extends IgxRowDirective<IgxPivotGridComponent>
4857
public ngOnInit() {
4958
// generate rowDimension
5059
const rowDimConfig = this.grid.pivotConfiguration.rows;
51-
let field = null;
60+
this.level = this.rowData['level'] || 0;
61+
this.hasChild = this.rowData['records'] != null && this.rowData['records'].length > 0;
62+
this.extractFromDimensions(rowDimConfig, 0);
63+
}
64+
65+
protected extractFromDimensions(rowDimConfig: IPivotDimension[], level: number){
5266
for (const dim of rowDimConfig) {
53-
if (typeof dim.member === 'string') {
54-
field = this.rowData[dim.member];
55-
} else if (typeof dim.member === 'function'){
56-
field = dim.member.call(this, this.rowData);
67+
if (level === this.level) {
68+
this.rowDimension.push(this.extractFromDimension(dim));
69+
} else {
70+
level++;
71+
this.extractFromDimensions(dim.childLevels, level);
5772
}
58-
const col = this._createColComponent(field);
59-
this.rowDimension.push(col);
6073
}
6174
}
6275

76+
protected extractFromDimension(dim: IPivotDimension) {
77+
let field = null;
78+
if (typeof dim.member === 'string') {
79+
field = this.rowData[dim.member];
80+
} else if (typeof dim.member === 'function'){
81+
field = dim.member.call(this, this.rowData);
82+
}
83+
const col = this._createColComponent(field);
84+
return col;
85+
}
86+
6387
protected _createColComponent(field: string) {
6488
const factoryColumn = this.resolver.resolveComponentFactory(IgxColumnComponent);
6589
const ref = this.viewRef.createComponent(factoryColumn, null, this.viewRef.injector);
6690
ref.instance.field = field;
91+
ref.instance.header = field;
6792
ref.instance.width = MINIMUM_COLUMN_WIDTH + 'px';
6893
(ref as any).instance._vIndex = this.grid.columns.length + this.index;
94+
if (this.hasChild) {
95+
ref.instance.headerTemplate = this.headerTemplate;
96+
}
6997
return ref.instance;
7098
}
7199
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="sample-column">
2-
<igx-pivot-grid #grid1 [data]="data" [originalData]="origData" [pivotConfiguration]="pivotConfig">
2+
<igx-pivot-grid #grid1 [data]="dataHierarchical" [originalData]="origData" [pivotConfiguration]="pivotConfigHierarchy">
33
</igx-pivot-grid>
44
</div>

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ export class PivotGridSampleComponent {
3333
filters: null
3434
};
3535

36+
public pivotConfigHierarchy: IPivotConfiguration = {
37+
columns: [{
38+
member: 'Country',
39+
enabled: true,
40+
childLevels:[]
41+
}],
42+
rows: [{
43+
member: () => 'All',
44+
enabled: true,
45+
childLevels:[
46+
{
47+
member: (data) => data.ProductCategory,
48+
enabled: true,
49+
childLevels:[]
50+
}
51+
]
52+
}],
53+
values: [
54+
{
55+
member: 'UnitsSold',
56+
aggregate: IgxNumberSummaryOperand.sum,
57+
enabled: true
58+
}
59+
],
60+
filters: null
61+
};
62+
3663
public origData = [
3764
{ ProductCategory: 'Clothing', UnitPrice: 12.81, SellerName: 'Stanley', Country: 'Bulgaria', Date: '01/01/2021', UnitsSold: 282 },
3865
{ ProductCategory: 'Clothing', UnitPrice: 49.57, SellerName: 'Elisa', Country: 'USA', Date: '01/05/2019', UnitsSold: 296 },
@@ -52,10 +79,15 @@ export class PivotGridSampleComponent {
5279
];
5380

5481
public dataHierarchical = [
55-
{ ProductCategory: 'All', Bulgaria: 774, USA: 829, Uruguay: 524 },
56-
{ ProductCategory: 'Clothing', Bulgaria: 774, USA: 296, Uruguay: 456 },
57-
{ ProductCategory: 'Bikes', Uruguay: 68 },
58-
{ ProductCategory: 'Accessories', USA: 293 },
59-
{ ProductCategory: 'Components', USA: 240 }
82+
{ ProductCategory: 'All', Bulgaria: 774, USA: 829, Uruguay: 524, level: 0, records: [
83+
{ ProductCategory: 'Clothing', Bulgaria: 774, USA: 296, Uruguay: 456, level: 1 },
84+
{ ProductCategory: 'Bikes', Uruguay: 68, level: 1 },
85+
{ ProductCategory: 'Accessories', USA: 293, level: 1 },
86+
{ ProductCategory: 'Components', USA: 240, level: 1 }
87+
] },
88+
{ ProductCategory: 'Clothing', Bulgaria: 774, USA: 296, Uruguay: 456, level: 1 },
89+
{ ProductCategory: 'Bikes', Uruguay: 68, level: 1 },
90+
{ ProductCategory: 'Accessories', USA: 293, level: 1 },
91+
{ ProductCategory: 'Components', USA: 240, level: 1 }
6092
];
6193
}

0 commit comments

Comments
 (0)