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 pathcalculated-field.tsx
More file actions
83 lines (75 loc) · 3.86 KB
/
calculated-field.tsx
File metadata and controls
83 lines (75 loc) · 3.86 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
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { PropertyPane } from '../common/property-pane';
import { PivotViewComponent, IDataOptions, FieldList, Inject, CalculatedField } from '@syncfusion/ej2-react-pivotview';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { Pivot_Data } from './data-source';
import { SampleBase } from '../common/sample-base';
/**
* PivotView Sample with Calculated Fields.
*/
const SAMPLE_CSS = `
.e-pivotview {
width: 100%;
height: 100%;
}`;
let dataSource: IDataOptions = {
data: Pivot_Data,
expandAll: false,
enableSorting: true,
formatSettings: [{ name: 'Amount', format: 'C0' }],
columns: [{ name: 'Year' }, { name: 'Order_Source', caption: 'Order Source' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
values: [{ name: 'In_Stock', caption: 'In Stock' },
{ name: 'Sold', caption: 'Units Sold' }, { name: 'Total', caption: 'Total Units', type: 'CalculatedField' }],
filters: [{ name: 'Product_Categories', caption: 'Product Categories' }],
calculatedFieldSettings: [
{
name: 'Total',
formula: '"Sum(In_Stock)"+"Sum(Sold)"'
}]
};
export class CalculatedFieldClass extends SampleBase<{}, {}> {
private pivotGridObj: PivotViewComponent;
btnClick(): void {
this.pivotGridObj.calculatedFieldModule.createCalculatedFieldDialog();
}
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'} allowCalculatedField={true} gridSettings={{columnWidth: 140}}>
<Inject services={[CalculatedField, FieldList]} />
</PivotViewComponent>
</div>
<div className='col-lg-3 property-section'>
<PropertyPane title='Properties'>
<div style={{ float: 'Right', marginRight: '10px' }}>
<ButtonComponent cssClass='e-primary' onClick={this.btnClick.bind(this)}>Calculated Field</ButtonComponent>
</div>
</PropertyPane>
</div>
</div>
<div id="action-description">
<p>In this sample,
<b> Total Units</b> acts as the calculated field. Users are allowed to insert a new calculated field based on the existing
calculated items either through a dialog window at run time or through code behind.</p>
</div>
<div id="description">
<p>The calculated field feature allows users to create custom fields which are not present in the actual data. Users can
create these fields using basic mathematical expression collaborating with existing fields. Calculated fields can
be created through UI dialog as well as code behind and it can be enabled by setting <code>allowCalculatedField</code> as true. The
<code> calculatedFieldSettings</code> property is available to configure the calculated field in code behind.
<br />
<br />The pivotgrid widget features are segregated into individual modules. To add calculated field, we need to inject
<code> CalculatedField</code> module into the
<code> services</code>.</p>
</div>
</div>
)
}
}