Skip to content

Commit 2697fcb

Browse files
authored
Merge pull request #3507 from IgniteUI/ttonev/pgrid-layout-sample
docs(pivotGrid): added layout sample
2 parents b0bf394 + 69fbefb commit 2697fcb

File tree

6 files changed

+235
-3
lines changed

6 files changed

+235
-3
lines changed

src/app/pivot-grid/pivot-grid-routes-data.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export const pivotGridsRoutesData = {
77
'pivot-grid-features': { displayName: 'Pivot Grid With Features', parentName: 'Pivot Grid' },
88
'pivot-grid-state-persistence': { displayName: 'Pivot Grid With State Persistence', parentName: 'Pivot Grid' },
99
'pivot-grid-noop-persistence': { displayName: 'Pivot Noop Grid with State Persistence', parentName: 'Pivot Grid' },
10-
'pivot-grid-about': { displayName: 'Pivot Grid About', parentName: 'Pivot Grid' }
10+
'pivot-grid-about': { displayName: 'Pivot Grid About', parentName: 'Pivot Grid' },
11+
'pivot-grid-layout': { displayName: 'Pivot Grid Layout', parentName: 'Pivot Grid' }
1112
};

src/app/pivot-grid/pivot-grids-routing.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { PivotGridNoopSampleComponent } from './pivot-grid-noop/pivot-grid-noop-
1010
import { pivotGridsRoutesData } from './pivot-grid-routes-data';
1111
import { PivotGridAboutComponent } from './pivot-state-persistence/about.component';
1212
import { PivotGridStatePersistenceSampleComponent } from './pivot-state-persistence/pivot-grid-state-persistence-sample.component';
13+
import { PivotGridLayoutComponent } from './pivot-layout/pivot-layout.component'
1314
// tslint:enable:max-line-length
1415

1516
export const gridsRoutes: Routes = [
@@ -52,6 +53,11 @@ export const gridsRoutes: Routes = [
5253
component: PivotGridAboutComponent,
5354
data: pivotGridsRoutesData['pivot-grid-about'],
5455
path: 'pivot-state-about'
56+
},
57+
{
58+
component: PivotGridLayoutComponent,
59+
data: pivotGridsRoutesData['pivot-grid-features'],
60+
path: 'pivot-grid-layout'
5561
}
5662
];
5763

src/app/pivot-grid/pivot-grids.module.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CommonModule } from '@angular/common';
44
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
55
import { NgModule } from '@angular/core';
66
import { FormsModule } from '@angular/forms';
7-
import { IgxCheckboxModule, IgxIconModule, IgxPivotGridModule } from 'igniteui-angular';
7+
import { IgxCheckboxModule, IgxIconModule, IgxPivotGridModule, IgxSwitchModule } from 'igniteui-angular';
88
import { PivotExportComponent } from './pivot-export/pivot-export.component';
99
import { PivotFeaturesComponent } from './pivot-features/pivot-features.component';
1010
import { PivotGridBasicSampleComponent } from './pivot-basic-sample/pivot-grid-basic-sample.component';
@@ -14,6 +14,7 @@ import { PivotGridsRoutingModule } from './pivot-grids-routing.module';
1414
import { PivotGridStatePersistenceSampleComponent } from './pivot-state-persistence/pivot-grid-state-persistence-sample.component';
1515
import { PivotGridAboutComponent } from './pivot-state-persistence/about.component';
1616
import { PivotGridNoopPersistenceSampleComponent } from './pivot-grid-noop-persistence/pivot-grid-noop-persistence-sample.component';
17+
import { PivotGridLayoutComponent } from './pivot-layout/pivot-layout.component';
1718

1819
@NgModule({ declarations: [
1920
PivotGridBasicSampleComponent,
@@ -23,11 +24,13 @@ import { PivotGridNoopPersistenceSampleComponent } from './pivot-grid-noop-persi
2324
PivotGridStatePersistenceSampleComponent,
2425
PivotGridNoopSampleComponent,
2526
PivotGridAboutComponent,
26-
PivotGridNoopPersistenceSampleComponent
27+
PivotGridNoopPersistenceSampleComponent,
28+
PivotGridLayoutComponent
2729
], imports: [CommonModule,
2830
FormsModule,
2931
PivotGridsRoutingModule,
3032
IgxPivotGridModule,
3133
IgxCheckboxModule,
34+
IgxSwitchModule,
3235
IgxIconModule], providers: [provideHttpClient(withInterceptorsFromDi())] })
3336
export class PivotGridsModule { }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="switches">
2+
<igx-switch [checked]="pivotUI.showRowHeaders" (change)="onShowRowHeaders($event)">Show row headers</igx-switch>
3+
<igx-switch [checked]="pivotUI.rowLayout === 'horizontal'" (change)="onLayoutToggle($event)">Horizontal layout</igx-switch>
4+
<igx-switch [checked]="pivotConfig.rows[0].horizontalSummary" (change)="onSummariesToggle($event)">Horizontal summaries</igx-switch>
5+
<igx-switch [checked]="pivotUI.horizontalSummariesPosition === 'top'" (change)="onSummariesPositionToggle($event)">Horizontal summaries position</igx-switch>
6+
</div>
7+
<div class="pivot-container">
8+
<igx-pivot-grid #grid1 [data]="data" [height]="'800px'" [pivotConfiguration]="pivotConfig" [rowSelection]="'single'"
9+
[superCompactMode]="true" [defaultExpandState]='true' [pivotUI]="pivotUI">
10+
</igx-pivot-grid>
11+
</div>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
:host {
2+
padding: 8px;
3+
display: flex;
4+
flex-direction: column;
5+
6+
::ng-deep {
7+
.upFontValue {
8+
color: hsla(var(--ig-success-500));
9+
}
10+
11+
.downFontValue {
12+
color: hsla(var(--ig-error-500));
13+
}
14+
15+
igx-pivot-data-selector {
16+
border: 1px solid hsla(var(--igx-gray-200));
17+
margin: 0 8px;
18+
}
19+
}
20+
21+
}
22+
23+
igx-pivot-grid {
24+
flex: 1;
25+
}
26+
27+
igx-pivot-data-selector {
28+
--ig-size: var(--ig-size-small);
29+
}
30+
31+
.pivot-container {
32+
display: flex;
33+
align-items: flex-start;
34+
flex: 1 1 auto;
35+
order: 0;
36+
}
37+
38+
.switches {
39+
margin-top: 12px;
40+
margin-bottom: 8px;
41+
width: 100%;
42+
display: flex;
43+
gap: 15px;
44+
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import { Component, ViewChild } from "@angular/core";
2+
3+
import {
4+
IPivotConfiguration, PivotAggregation, IgxPivotNumericAggregate,
5+
IgxPivotDateDimension, FilteringExpressionsTree, FilteringLogic, IgxStringFilteringOperand,
6+
PivotRowLayoutType,
7+
IPivotUISettings,
8+
IChangeCheckboxEventArgs,
9+
IgxPivotGridComponent,
10+
PivotSummaryPosition
11+
} from "igniteui-angular"
12+
import { SALES_DATA } from "../../data/dataToAnalyze";
13+
14+
export class IgxTotalSaleAggregate {
15+
public static totalSale: PivotAggregation = (members, data: any) =>
16+
data.reduce((accumulator, value) => accumulator + value.Product.UnitPrice * value.NumberOfUnits, 0);
17+
18+
public static totalMin: PivotAggregation = (members, data: any) => {
19+
let min = 0;
20+
if (data.length === 1) {
21+
min = data[0].Product.UnitPrice * data[0].NumberOfUnits;
22+
} else if (data.length > 1) {
23+
const mappedData = data.map(x => x.Product.UnitPrice * x.NumberOfUnits);
24+
min = mappedData.reduce((a, b) => Math.min(a, b));
25+
}
26+
return min;
27+
};
28+
29+
public static totalMax: PivotAggregation = (members, data: any) => {
30+
let max = 0;
31+
if (data.length === 1) {
32+
max = data[0].Product.UnitPrice * data[0].NumberOfUnits;
33+
} else if (data.length > 1) {
34+
const mappedData = data.map(x => x.Product.UnitPrice * x.NumberOfUnits);
35+
max = mappedData.reduce((a, b) => Math.max(a, b));
36+
}
37+
return max;
38+
};
39+
}
40+
41+
@Component({
42+
selector: 'app-pivot-layout-sample',
43+
styleUrls: ['./pivot-layout.component.scss'],
44+
templateUrl: './pivot-layout.component.html'
45+
})
46+
export class PivotGridLayoutComponent {
47+
public data = SALES_DATA;
48+
public enableSummaries = true;
49+
public pivotUI: IPivotUISettings = { showRowHeaders: true, rowLayout: PivotRowLayoutType.Horizontal };
50+
51+
@ViewChild("grid1")
52+
public grid1: IgxPivotGridComponent;
53+
54+
public pivotConfig = this.buildPivotConfig();
55+
56+
public buildPivotConfig(): IPivotConfiguration {
57+
return {
58+
columns: [
59+
new IgxPivotDateDimension(
60+
{
61+
memberName: 'Date',
62+
enabled: true
63+
},
64+
{
65+
months: false,
66+
quarters: true,
67+
fullDate: false
68+
}
69+
)
70+
],
71+
rows: [
72+
{
73+
memberFunction: () => 'All Products',
74+
memberName: 'AllProducts',
75+
enabled: true,
76+
horizontalSummary: this.enableSummaries,
77+
width: "150px",
78+
childLevel: {
79+
memberFunction: (data) => data.Product.Name,
80+
memberName: 'ProductCategory',
81+
horizontalSummary: this.enableSummaries,
82+
width: "150px",
83+
enabled: true,
84+
childLevel: {
85+
memberName: 'City',
86+
width: "150px",
87+
memberFunction: (data) => data.Seller.City,
88+
enabled: true
89+
}
90+
}
91+
}
92+
],
93+
values: [
94+
{
95+
member: 'Value',
96+
aggregate: {
97+
key: 'SUM',
98+
aggregator: IgxPivotNumericAggregate.sum,
99+
label: 'Sum'
100+
},
101+
aggregateList: [{
102+
key: 'SUM',
103+
aggregator: IgxPivotNumericAggregate.sum,
104+
label: 'Sum'
105+
}],
106+
enabled: true,
107+
styles: {
108+
downFontValue: (rowData: any, columnKey: any): boolean => parseFloat(rowData.aggregationValues.get(columnKey.field)) <= 150,
109+
upFontValue: (rowData: any, columnKey: any): boolean => parseFloat(rowData.aggregationValues.get(columnKey.field)) > 150
110+
},
111+
formatter: (value) => value ? '$' + parseFloat(value).toFixed(3) : undefined
112+
},
113+
{
114+
member: 'AmountofSale',
115+
displayName: 'Amount of Sale',
116+
aggregate: {
117+
key: 'SUM',
118+
aggregator: IgxTotalSaleAggregate.totalSale,
119+
label: 'Sum of Sale'
120+
},
121+
aggregateList: [{
122+
key: 'SUM',
123+
aggregator: IgxTotalSaleAggregate.totalSale,
124+
label: 'Sum of Sale'
125+
}, {
126+
key: 'MIN',
127+
aggregator: IgxTotalSaleAggregate.totalMin,
128+
label: 'Minimum of Sale'
129+
}, {
130+
key: 'MAX',
131+
aggregator: IgxTotalSaleAggregate.totalMax,
132+
label: 'Maximum of Sale'
133+
}],
134+
enabled: true,
135+
dataType: 'currency'
136+
}
137+
],
138+
filters: [
139+
{
140+
memberName: 'SellerName',
141+
memberFunction: (data) => data.Seller.Name,
142+
enabled: true
143+
}
144+
]
145+
};
146+
}
147+
148+
public onShowRowHeaders(event: IChangeCheckboxEventArgs) {
149+
this.pivotUI.showRowHeaders = event.checked;
150+
this.grid1.pivotUI = this.pivotUI;
151+
}
152+
153+
public onLayoutToggle(event: IChangeCheckboxEventArgs) {
154+
this.pivotUI.rowLayout = event.checked ? PivotRowLayoutType.Horizontal : PivotRowLayoutType.Vertical;
155+
this.grid1.pivotUI = this.pivotUI;
156+
}
157+
158+
public onSummariesToggle(event: IChangeCheckboxEventArgs) {
159+
this.enableSummaries = event.checked;
160+
this.grid1.pivotConfiguration = this.buildPivotConfig();
161+
}
162+
163+
public onSummariesPositionToggle(event: IChangeCheckboxEventArgs) {
164+
this.pivotUI.horizontalSummariesPosition = event.checked ? PivotSummaryPosition.Top : PivotSummaryPosition.Bottom ;
165+
this.grid1.pivotUI = this.pivotUI;
166+
}
167+
}

0 commit comments

Comments
 (0)