Skip to content

Commit 60465b6

Browse files
MKirovaMKirova
authored andcommitted
Update samples with additional combo from which you can add/remove extra dimensions.
1 parent 90bf08c commit 60465b6

File tree

6 files changed

+140
-54
lines changed

6 files changed

+140
-54
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
481481
});
482482
}
483483

484+
/**
485+
* Notifies for dimension change.
486+
*/
487+
public notifyDimensionChange(regenerateColumns = false) {
488+
if (regenerateColumns) {
489+
this.setupColumns();
490+
}
491+
this.pipeTrigger++;
492+
this.cdr.detectChanges();
493+
}
494+
484495
public uniqueDimensionValuesStrategy(column: IgxColumnComponent, exprTree: IFilteringExpressionsTree,
485496
done: (uniqueValues: any[]) => void) {
486497
const config = this.pivotConfiguration;
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<div class="sample-column">
2+
<span>Dimensions:</span>
3+
<igx-combo #combo class="combo" [itemsMaxHeight]="250" (selectionChanging)="handleChange($event)"
4+
[data]="dimensions" [displayKey]="'memberName'" [(ngModel)]="selected"
5+
placeholder="Dimension(s)" searchPlaceholder="Search...">
6+
</igx-combo>
27
<igx-pivot-grid #grid1 [data]="origData" [pivotConfiguration]="pivotConfigHierarchy">
38
</igx-pivot-grid>
4-
</div>
9+
</div>

src/app/pivot-grid-hierarchy/pivot-grid-hierarchy.sample.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
}
1717

1818
.sample-column {
19-
max-width: 900px;
19+
max-width: 1200px;
2020
}
2121
}

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

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, ViewChild } from '@angular/core';
2-
import { IgxPivotGridComponent, IgxPivotNumericAggregate, IPivotConfiguration } from 'igniteui-angular';
2+
import { IgxPivotGridComponent, IgxPivotNumericAggregate, IPivotConfiguration, IPivotDimension } from 'igniteui-angular';
33
import { DATA } from '../shared/pivot-data';
44

55
@Component({
@@ -12,43 +12,74 @@ import { DATA } from '../shared/pivot-data';
1212
export class PivotGridHierarchySampleComponent {
1313
@ViewChild('grid1', { static: true }) public grid1: IgxPivotGridComponent;
1414

15-
public pivotConfigHierarchy: IPivotConfiguration = {
16-
columns: [{
17-
memberName: 'All',
18-
memberFunction: () => 'All',
15+
public dimensions: IPivotDimension[] = [
16+
{
17+
memberName: 'AllSeller',
18+
memberFunction: () => 'All Sellers',
19+
enabled: true,
20+
childLevel:
21+
{
22+
memberName: 'Seller',
23+
memberFunction: (data) => data.Seller.Name,
24+
enabled: true,
25+
},
26+
},
27+
{
28+
memberName: 'AllProduct',
29+
memberFunction: () => 'All Products',
1930
enabled: true,
2031
childLevel:
2132
{
2233

2334
memberName: 'Product',
2435
memberFunction: (data) => data.Product.Name,
25-
enabled: true,
26-
childLevel:
27-
{
28-
memberName: 'City',
29-
memberFunction: (data) => data.Seller.City,
30-
enabled: true,
31-
}
32-
36+
enabled: true
3337
}
3438
},
35-
],
36-
rows: [{
37-
memberName: 'AllSeller',
38-
memberFunction: () => 'All',
39+
{
40+
memberName: 'City',
41+
memberFunction: (data) => data.Seller.City,
3942
enabled: true,
40-
childLevel:
41-
{
42-
memberName: 'Seller',
43-
memberFunction: (data) => data.Seller.Name,
44-
enabled: true,
43+
},
44+
{
45+
memberName: 'Date',
46+
enabled: true,
47+
}
48+
];
49+
public selected: IPivotDimension[] = [ this.dimensions[1], this.dimensions[2]];
50+
51+
public handleChange(event) {
52+
let isColumnChange = false
53+
const allDims = this.pivotConfigHierarchy.rows.concat(this.pivotConfigHierarchy.columns).concat(this.pivotConfigHierarchy.filters);
54+
if (event.added.length > 0) {
55+
const dim = allDims.find(x => x && x.memberName === event.added[0].memberName);
56+
isColumnChange = this.pivotConfigHierarchy.columns.indexOf(dim) !== -1;
57+
if (dim) {
58+
dim.enabled = true;
59+
} else {
60+
// add as row by default
61+
this.pivotConfigHierarchy.rows = this.pivotConfigHierarchy.rows.concat(event.added);
4562
}
46-
}],
63+
} else if (event.removed.length > 0) {
64+
const dims = allDims.filter(x => x && event.removed.indexOf(x) !== -1);
65+
dims.forEach(x => x.enabled = false);
66+
isColumnChange = dims.some(x => this.pivotConfigHierarchy.columns.indexOf(x) !== -1);
67+
}
68+
this.grid1.notifyDimensionChange(isColumnChange);
69+
}
70+
71+
public pivotConfigHierarchy: IPivotConfiguration = {
72+
columns: [
73+
this.dimensions[2]
74+
],
75+
rows: [
76+
this.dimensions[1]
77+
],
4778
values: [
4879
{
4980
member: 'NumberOfUnits',
5081
aggregate: {
51-
aggregator: IgxPivotNumericAggregate.sum,
82+
aggregator: IgxPivotNumericAggregate.sum,
5283
key: 'sum',
5384
label: 'Sum'
5485
},
@@ -57,7 +88,7 @@ export class PivotGridHierarchySampleComponent {
5788
}, {
5889
member: 'Value',
5990
aggregate: {
60-
aggregator: IgxPivotNumericAggregate.sum,
91+
aggregator: IgxPivotNumericAggregate.sum,
6192
key: 'sum',
6293
label: 'Sum'
6394
},
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<div class="sample-column">
2+
<span>Dimensions:</span>
3+
<igx-combo #combo class="combo" [itemsMaxHeight]="250" (selectionChanging)="handleChange($event)"
4+
[data]="dimensions" [displayKey]="'memberName'" [(ngModel)]="selected"
5+
placeholder="Dimension(s)" searchPlaceholder="Search...">
6+
</igx-combo>
27
<igx-pivot-grid #grid1 [data]="origData" [width]="'100%'" [height]="'100%'" [pivotConfiguration]="pivotConfigHierarchy">
38
</igx-pivot-grid>
49
</div>

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

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { trigger } from '@angular/animations';
12
import { Component, ViewChild } from '@angular/core';
23
import {
34
IgxPivotNumericAggregate,
45
IgxPivotGridComponent,
56
IPivotConfiguration,
67
PivotAggregation,
7-
IgxPivotDateDimension
8+
IgxPivotDateDimension,
9+
IPivotDimension
810
} from 'igniteui-angular';
911
import { HIERARCHICAL_SAMPLE_DATA } from '../shared/sample-data';
1012

@@ -42,38 +44,50 @@ export class IgxTotalSaleAggregate {
4244
export class PivotGridSampleComponent {
4345
@ViewChild('grid1', { static: true }) public grid1: IgxPivotGridComponent;
4446

45-
public pivotConfigHierarchy: IPivotConfiguration = {
46-
columns: [
47-
{
48-
memberName: 'Country',
49-
enabled: true
50-
}
51-
],
52-
rows: [
53-
54-
new IgxPivotDateDimension(
55-
{
56-
memberName: 'Date',
57-
enabled: true
58-
},
59-
{
60-
months: false
61-
}
62-
),
47+
public dimensions: IPivotDimension[] = [
48+
{
49+
memberName: 'Country',
50+
enabled: true
51+
},
52+
new IgxPivotDateDimension(
6353
{
64-
memberName: 'City',
54+
memberName: 'Date',
6555
enabled: true
6656
},
6757
{
68-
memberFunction: () => 'All',
69-
memberName: 'AllProducts',
58+
months: false
59+
}
60+
),
61+
{
62+
memberFunction: () => 'All',
63+
memberName: 'AllProducts',
64+
enabled: true,
65+
childLevel: {
66+
memberFunction: (data) => data.ProductCategory,
67+
memberName: 'ProductCategory',
68+
enabled: true
69+
}
70+
},
71+
{
72+
memberName: 'AllSeller',
73+
memberFunction: () => 'All Sellers',
74+
enabled: true,
75+
childLevel: {
7076
enabled: true,
71-
childLevel: {
72-
memberFunction: (data) => data.ProductCategory,
73-
memberName: 'ProductCategory',
74-
enabled: true
75-
}
77+
memberName: 'Seller'
7678
}
79+
},
80+
];
81+
82+
public selected: IPivotDimension[] = [this.dimensions[0], this.dimensions[1], this.dimensions[2]];
83+
84+
public pivotConfigHierarchy: IPivotConfiguration = {
85+
columns: [
86+
this.dimensions[0]
87+
],
88+
rows: [
89+
this.dimensions[1],
90+
this.dimensions[2]
7791
],
7892
values: [
7993
{
@@ -152,4 +166,24 @@ export class PivotGridSampleComponent {
152166
ProductCategory: 'Components', UnitPrice: 16.05, SellerName: 'Walter Pang',
153167
Country: 'Bulgaria', City: 'Sofia', Date: '02/19/2013', UnitsSold: 492
154168
}];
169+
170+
public handleChange(event) {
171+
let isColumnChange = false
172+
const allDims = this.pivotConfigHierarchy.rows.concat(this.pivotConfigHierarchy.columns).concat(this.pivotConfigHierarchy.filters);
173+
if (event.added.length > 0) {
174+
const dim = allDims.find(x => x && x.memberName === event.added[0].memberName);
175+
isColumnChange = this.pivotConfigHierarchy.columns.indexOf(dim) !== -1;
176+
if (dim) {
177+
dim.enabled = true;
178+
} else {
179+
// add as row by default
180+
this.pivotConfigHierarchy.rows = this.pivotConfigHierarchy.rows.concat(event.added);
181+
}
182+
} else if (event.removed.length > 0) {
183+
const dims = allDims.filter(x => x && event.removed.indexOf(x) !== -1);
184+
dims.forEach(x => x.enabled = false);
185+
isColumnChange = dims.some(x => this.pivotConfigHierarchy.columns.indexOf(x) !== -1);
186+
}
187+
this.grid1.notifyDimensionChange(isColumnChange);
188+
}
155189
}

0 commit comments

Comments
 (0)