This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaggregation.tsx
More file actions
153 lines (136 loc) · 6.37 KB
/
aggregation.tsx
File metadata and controls
153 lines (136 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { PropertyPane } from '../common/property-pane';
import { PivotViewComponent, IDataOptions, IDataSet, FieldList, Inject, SummaryTypes } from '@syncfusion/ej2-react-pivotview';
import { DropDownListComponent, ChangeEventArgs } from '@syncfusion/ej2-react-dropdowns';
import { renewableEnergy } from './data-source';
import { SampleBase } from '../common/sample-base';
/**
* PivotView Aggregation Sample.
*/
let dataSource: IDataOptions = {
enableSorting: true,
formatSettings: [{ name: 'ProCost', format: 'C0' }, { name: 'PowUnits', format: 'N0' }],
drilledMembers: [{ name: 'EnerType', items: ['Biomass', 'Free Energy'] }],
columns: [
{ name: 'EnerType', caption: 'Energy Type' },
{ name: 'EneSource', caption: 'Energy Source' }
],
data: renewableEnergy,
expandAll: false,
rows: [
{ name: 'Year', caption: 'Production Year' },
{ name: 'HalfYear', caption: 'Half Year' },
{ name: 'Quarter', caption: 'Quarter Year' }
],
values: [
{ name: 'PowUnits', caption: 'Units (GWh)' },
{ name: 'ProCost', caption: 'Cost (MM)' }
],
filters: []
};
const SAMPLE_CSS = `
.e-pivotview {
width: 100%;
height: 100%;
}`;
export class Aggregation extends SampleBase<{}, {}> {
private pivotGridObj: PivotViewComponent;
private fields: object = { text: 'text', value: 'value' };
private mVal: string = 'Sum';
private qData: { [key: string]: Object }[] = [
{ 'value': 'Max', 'text': 'Max' }, { 'value': 'Min', 'text': 'Min' },
{ 'value': 'Count', 'text': 'Count' }, { 'value': 'Sum', 'text': 'Sum' },
{ 'value': 'Avg', 'text': 'Average' }
];
private cData: { [key: string]: Object }[] = [
{ 'value': 'Max', 'text': 'Max' }, { 'value': 'Min', 'text': 'Min' },
{ 'value': 'Sum', 'text': 'Sum' }, { 'value': 'Avg', 'text': 'Average' }
];
public changeBalance(e: ChangeEventArgs): void {
this.setSummaryType('PowUnits', e.value as SummaryTypes);
}
public changeQuantity(e: ChangeEventArgs): void {
this.setSummaryType('ProCost', e.value as SummaryTypes);
}
public setSummaryType(fieldName: string, summaryType: SummaryTypes): void {
let isAvail: boolean = false;
for (let vCnt: number = 0; vCnt < this.pivotGridObj.dataSource.values.length; vCnt++) {
if (this.pivotGridObj.dataSource.values[vCnt].name === fieldName) {
this.pivotGridObj.dataSource.values[vCnt].type = summaryType;
isAvail = (this.pivotGridObj.dataSource.values as any)[vCnt].properties ? false : true;
}
}
if (isAvail) {
this.pivotGridObj.updateDataSource();
}
}
render() {
return (
<div className='control-pane'>
<style>
{SAMPLE_CSS}
</style>
<div className='control-section' style={{ overflow: 'initial' }}>
<div className='col-lg-9 adaptive'>
<PivotViewComponent id='PivotView' ref={(pivotview) => { this.pivotGridObj = pivotview }} dataSource={dataSource} showFieldList={true} width={'100%'} height={'300'} gridSettings={{columnWidth: 140}}>
<Inject services={[FieldList]} />
</PivotViewComponent>
</div>
<div className='col-lg-3 property-section'>
<PropertyPane title='Properties'>
<table id='property' title='Properties' className='property-panel-table' style={{ width: '100%' }}>
<tbody>
<tr style={{ height: '50px' }}>
<td>
<div>
{/* Render the DropDownList Component */}
<DropDownListComponent id='mode' floatLabelType={'Auto'} placeholder={'Units'} width={'100%'} dataSource={this.qData} fields={this.fields} value={this.mVal}
change={this.changeBalance.bind(this)} />
</div>
</td>
</tr>
<tr style={{ height: '50px' }}>
<td>
<div>
{/* Render the DropDownList Component */}
<DropDownListComponent id='mode' floatLabelType={'Auto'} placeholder={'Cost'} width={'100%'} dataSource={this.cData} fields={this.fields} value={this.mVal}
change={this.changeQuantity.bind(this)} />
</div>
</td>
</tr>
</tbody>
</table>
</PropertyPane>
</div>
</div>
<div id="action-description">
<p>This sample demonstrates the aggregate types in the pivotgrid widget. In this sample, you can change the aggregate types
for value fields using a dropdown list separately.</p>
</div>
<div id="description">
<p>The pivotgrid widget supports different types of aggregation for value fields. The aggregate type can be set using the type
property of the value field. The built-in aggregates are:
</p>
<ul>
<li>
<code>Sum</code>
</li>
<li>
<code>Average</code>
</li>
<li>
<code>Min</code>
</li>
<li>
<code>Max</code>
</li>
<li>
<code>Count</code>
</li>
</ul>
</div>
</div>
)
}
}