Skip to content

Commit 707e06d

Browse files
committed
angular
1 parent d8dbf1a commit 707e06d

File tree

10 files changed

+5311
-4667
lines changed

10 files changed

+5311
-4667
lines changed

Angular/src/app/app-routing.module.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

Angular/src/app/app.component.html

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
<div class="default-style">
2-
<dx-button [text]="buttonText" (onClick)="onClick($event)"></dx-button>
1+
<div class="long-title"><h3>Conditional Summary Calculation</h3></div>
2+
<dx-pivot-grid
3+
#sales
4+
[allowSortingBySummary]="true"
5+
[allowSorting]="true"
6+
[allowFiltering]="true"
7+
[allowExpandAll]="true"
8+
[height]="440"
9+
[showBorders]="true"
10+
[dataSource]="dataSource"
11+
>
12+
<dxo-field-chooser [enabled]="false"></dxo-field-chooser>
13+
</dx-pivot-grid>
14+
15+
<div class="options">
16+
<div class="caption">Options</div>
17+
<div class="option">
18+
<dx-check-box
19+
[(value)]="isConditional"
20+
text="Toggle Conditional Summary Calculation"
21+
(onValueChanged)="toggleConditionalChanged()"
22+
>
23+
</dx-check-box>
24+
</div>
325
</div>

Angular/src/app/app.component.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,42 @@
22
margin: 50px;
33
width: 90vw;
44
}
5+
6+
#sales {
7+
margin-top: 80px;
8+
}
9+
10+
.long-title h3 {
11+
font-family: 'Segoe UI Light', 'Helvetica Neue Light', 'Segoe UI', 'Helvetica Neue', 'Trebuchet MS', Verdana;
12+
font-weight: 200;
13+
font-size: 28px;
14+
text-align: center;
15+
margin-bottom: 20px;
16+
}
17+
18+
.options {
19+
margin-top: 20px;
20+
padding: 20px;
21+
background: #f5f5f5;
22+
}
23+
24+
.options .caption {
25+
font-size: 18px;
26+
font-weight: 500;
27+
}
28+
29+
.option {
30+
margin-top: 10px;
31+
}
32+
33+
.option > span {
34+
width: 120px;
35+
display: inline-block;
36+
}
37+
38+
.option > .dx-widget {
39+
display: inline-block;
40+
vertical-align: middle;
41+
width: 100%;
42+
max-width: 350px;
43+
}

Angular/src/app/app.component.ts

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,100 @@
1-
import { Component } from '@angular/core';
2-
import { ClickEvent } from 'devextreme/ui/button';
1+
import { Component, ViewChild } from '@angular/core';
2+
import { DxCheckBoxModule, DxPivotGridComponent, DxPivotGridModule } from 'devextreme-angular';
3+
import PivotGridDataSource from 'devextreme/ui/pivot_grid/data_source';
4+
import { Sale, Service } from './app.service';
5+
6+
interface CustomSummaryValue {
7+
summaryProcess?: string;
8+
value?: any;
9+
totalValue?: any;
10+
}
311

412
@Component({
513
selector: 'app-root',
614
templateUrl: './app.component.html',
715
styleUrls: ['./app.component.scss'],
16+
standalone: true,
17+
imports: [DxPivotGridModule, DxCheckBoxModule],
18+
providers: [Service],
819
})
920
export class AppComponent {
10-
title = 'Angular';
21+
@ViewChild('sales') pivotGrid!: DxPivotGridComponent;
22+
23+
sales: Sale[];
24+
25+
dataSource: PivotGridDataSource;
26+
27+
isConditional = true;
1128

12-
counter = 0;
29+
constructor(service: Service) {
30+
let tempSales: any = service.getSales();
31+
32+
tempSales.forEach((sale: Sale, index: number) => {
33+
sale.isApproved = index % 2 !== 0;
34+
});
35+
36+
this.sales = tempSales;
37+
38+
this.dataSource = new PivotGridDataSource({
39+
fields: [{
40+
caption: 'Region',
41+
width: 120,
42+
dataField: 'region',
43+
area: 'row',
44+
expanded: true,
45+
}, {
46+
caption: 'City',
47+
dataField: 'city',
48+
width: 150,
49+
area: 'row',
50+
selector: (data: Sale): string => `${data.city} (${data.country})`,
51+
}, {
52+
dataField: 'date',
53+
dataType: 'date',
54+
area: 'column',
55+
expanded: true,
56+
}, {
57+
caption: 'Sales',
58+
dataType: 'number',
59+
summaryType: 'custom',
60+
format: 'currency',
61+
area: 'data',
62+
calculateCustomSummary: this.calculateCustomSummary,
63+
},
64+
{
65+
caption: 'Approved',
66+
dataField: 'isApproved',
67+
summaryType: 'sum',
68+
area: 'data',
69+
}],
70+
store: this.sales,
71+
});
72+
}
1373

14-
buttonText = 'Click count: 0';
74+
calculateCustomSummary = (options: CustomSummaryValue): void => {
75+
switch (options.summaryProcess) {
76+
case 'start':
77+
options.totalValue = { conditionalVal: 0, rawVal: 0, count: 0 };
78+
break;
79+
case 'calculate':
80+
options.totalValue.count += 1;
81+
options.totalValue.rawVal += options.value.amount;
82+
if (options.value.isApproved) {
83+
options.totalValue.conditionalVal += options.value.amount;
84+
}
85+
break;
86+
case 'finalize':
87+
if (options.totalValue.count === 1 || !this.isConditional) {
88+
options.totalValue = options.totalValue.rawVal;
89+
} else {
90+
options.totalValue = options.totalValue.conditionalVal;
91+
}
92+
break;
93+
default: break;
94+
}
95+
};
1596

16-
onClick(e: ClickEvent): void {
17-
this.counter++;
18-
this.buttonText = `Click count: ${this.counter}`;
97+
toggleConditionalChanged(): void {
98+
this.pivotGrid.instance.getDataSource().reload().catch(() => {});
1999
}
20100
}

Angular/src/app/app.module.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)