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 pathconditional-formatting.tsx
More file actions
174 lines (165 loc) · 7.65 KB
/
conditional-formatting.tsx
File metadata and controls
174 lines (165 loc) · 7.65 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { PropertyPane } from '../common/property-pane';
import { PivotViewComponent, IDataOptions, FieldList, Inject, ConditionalFormatting } 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%;
}
#conditional-formatting-btn {
width: 80%;
margin-left: 20px;
}
#reset-format {
width: 80%;
margin-left: 20px;
}`;
let dataSource: IDataOptions = {
data: Pivot_Data,
expandAll: false,
enableSorting: true,
drilledMembers: [{ name: 'Country', items: ['France', 'Germany'] }],
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' }],
filters: [{ name: 'Product_Categories', caption: 'Product Categories' }],
conditionalFormatSettings: [
{
measure: 'In Stock',
value1: 5000,
conditions: 'LessThan',
style: {
backgroundColor: '#80cbc4',
color: 'black',
fontFamily: 'Tahoma',
fontSize: '12px'
}
},
{
value1: 3400,
value2: 40000,
measure: 'Units Sold',
conditions: 'Between',
style: {
backgroundColor: '#f48fb1',
color: 'black',
fontFamily: 'Tahoma',
fontSize: '12px'
}
}
]
};
export class ConditionalFormattingClass extends SampleBase<{}, {}> {
private pivotGridObj: PivotViewComponent;
applyFormat(): void {
this.pivotGridObj.conditionalFormattingModule.showConditionalFormattingDialog();
}
resetFormat(): void {
if (this.pivotGridObj.dataSource.conditionalFormatSettings.length > 0) {
this.pivotGridObj.setProperties({ dataSource: { conditionalFormatSettings: [] } }, true);
this.pivotGridObj.renderPivotGrid();
}
this.pivotGridObj.conditionalFormattingModule.destroy();
document.getElementById('reset-format').blur();
}
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'} allowConditionalFormatting={true} gridSettings={{ columnWidth: 100 }}>
<Inject services={[ConditionalFormatting, 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>
<ButtonComponent id='conditional-formatting-btn' cssClass='e-primary' onClick={this.applyFormat.bind(this)}>APPLY FORMAT</ButtonComponent>
</td>
</tr>
<tr style={{ height: '50px' }}>
<td>
<ButtonComponent id='reset-format' cssClass='e-primary' onClick={this.resetFormat.bind(this)}>RESET ALL</ButtonComponent>
</td>
</tr>
</tbody>
</table>
</PropertyPane>
</div>
</div>
<div id="action-description">
<p>This sample demonstrates formatting the appearance of the pivot grid cells with values based on the applied conditions.</p>
</div>
<div id="description">
<p>Conditional formatting works only for cells with values,
allowing the users to change its appearance such as background color, font color, font family, and font size based on specific conditions.
Conditional formatting can be applied either through UI or code behind. To enable this option in UI, set
<code> allowConditionalFormatting</code> to true and invoke
<code> showConditionalFormattingDialog</code> method to view the UI.
To achieve this in code-behind, set
<code> allowConditionalFormatting</code> to true and use the
<code> conditionalFormatSettings</code> object in the pivot grid widget along with the following properties.
Both options are enabled in this sample.</p>
<table>
<tr>
<td style={{ verticalAlign: 'top', padding: '4px 0' }}>
<code>measure :</code>
</td>
<td>Specifies the value field name for which style will be applied.</td>
</tr>
<tr>
<td style={{ verticalAlign: 'top', padding: '4px 0' }}>
<code>condition :</code>
</td>
<td>Specifies the operator type like equals, greater than, less than, etc.</td>
</tr>
<tr>
<td style={{ verticalAlign: 'top', padding: '4px 0' }}>
<code>value1 :</code>
</td>
<td>Specifies the start value.</td>
</tr>
<tr>
<td style={{ verticalAlign: 'top', padding: '4px 0' }}>
<code>value2 :</code>
</td>
<td>Specifies the end value.</td>
</tr>
<tr>
<td style={{ verticalAlign: 'top', padding: '4px 0' }}>
<code>style :</code>
</td>
<td>Specifies the style for the cell.</td>
</tr>
</table>
<br />
<p>Also, user can clear the entire style applied for the value cell using reset all option.</p>
<br />
<p>
<strong>Injecting Module:</strong>
</p>
<p>
The pivot grid widget features are segregated into individual modules.
To enable conditional formatting, inject
<code> ConditionalFormatting</code> module using the
<code> services</code> tag.
</p>
</div>
</div>
);
}
}