-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-105.html
220 lines (214 loc) · 7.4 KB
/
template-105.html
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<h1 id="predefined-formatter">Predefined Formatter</h1>
<h2 id="setup-guide">Setup guide</h2>
<p>Use <code>import</code> syntax to import the formatter into your app.</p>
<pre><code class="language-js">import { EFButtonFormatter, EFSelectFormatter } from "@refinitiv-ui/efx-grid/formatters";
</code></pre>
<h2 id="the-basics">The basics</h2>
<p>The simplest way to get the basic formatter is by calling <code>create()</code> without options, for example <code>SimpleInputFormatter.create()</code>. Then pass it to Grid using configuration, as shown below:</p>
<pre><code class="language-js">var config = {
columns: [{
name: "Company Info",
field: "info",
binding: SimpleInputFormatter.create()
}, {
name: "Currency",
field: "currency",
binding: EFSelectFormatter.create()
}, {
name: "DatePicker",
field: "date",
binding: EFDateTimePickerFormatter.create()
}]
}
</code></pre>
<p>Formatter with default options supports basic functioning and can be used for general usage. For input formatters, like <code>SimpleInputFormatter</code>, <code>EFTextFieldFormatter</code>, <code>EFComboBoxFormatter</code>, and so on, when the value has changed the new value will be saved to the <code>dataTable</code> of Grid. See basic formatters in the below example:</p>
<code-sandbox hash="9131e2f6"><pre><code class="language-css">efx-grid {
height: 320px;
}
</code></pre>
<pre><code class="language-html"><efx-grid id="grid"></efx-grid>
</code></pre>
<pre><code class="language-javascript">import { halo } from './theme-loader.js'; // This line is only required for demo purpose. It is not relevant for your application.
await halo(); // This line is only required for demo purpose. It is not relevant for your application.
/* ---------------------------------- Note ----------------------------------
DataGenerator, Formatters and extensions are exposed to global scope
in the bundle file to make it easier to create live examples.
Importing formatters and extensions is still required in your application.
Please see the document for further information.
---------------------------------------------------------------------------*/
var currencies = ["THB", "AUD", "USD", "YEN", "TWD"];
DataGenerator.addFieldInfo("currency", { type: "set", members: currencies});
var fields = ["number_1", "currency", "CF_NETCHNG"];
var records = DataGenerator.generateRecords(fields, { seed: 1, numRows: 20 });
var configObj = {
columns: [
{
name: "SimpleLink",
field: fields[0],
alignment: "center",
binding: SimpleLinkFormatter.create()
},
{
name: "Input",
field: fields[0],
alignment: "center",
binding: EFNumberFieldFormatter.create()
},
{
name: "Select",
field: fields[1],
alignment: "center",
binding: EFSelectFormatter.create({
data: currencies
})
},
{
name: "PercentBar",
field: fields[2],
alignment: "center",
binding: PercentBarFormatter.create()
}
],
staticDataRows: records
};
var grid = document.getElementById("grid");
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="advance-usage">Advance usage</h2>
<p>Customizations are allowed through various options, as detailed in the following sections.</p>
<h3 id="common-options">Common options</h3>
<p>There are some options that are available for all formatters, see the below table for more details.</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>attributes</td>
<td>Object</td>
<td>optional</td>
<td>List of attributes name and values</td>
</tr>
<tr>
<td>styles</td>
<td>Object</td>
<td>optional</td>
<td>List of inline styles for the element</td>
</tr>
<tr>
<td>events</td>
<td>Object</td>
<td>optional</td>
<td>List of event names and listeners</td>
</tr>
<tr>
<td>disablingField</td>
<td>string</td>
<td>optional</td>
<td>Field to be used for representing disabled attribute of the element</td>
</tr>
<tr>
<td>errorField</td>
<td>string</td>
<td>optional</td>
<td>Field to be used for representing error attribute of the element</td>
</tr>
<tr>
<td>onElementRendered</td>
<td>Function</td>
<td>optional</td>
<td>Event handler after default rendering. It is useful for additional styling</td>
</tr>
</tbody></table>
<blockquote>
<p>Note: The available value for each option is dependent on the type of element. In the case of the EF element, more information about attributes and events can be found <a href="https://ui.refinitiv.com">here</a>.</p>
</blockquote>
<p>Below is an example of showing a button with a label, icon, light coral background color, and listen for click and active-changed event.</p>
<pre><code class="language-js">var config = {
columns: [{
name: "Number",
field: "number",
binding: EFButtonFormatter.create({
label: "More detail",
attributes: {
"icon": "info"
},
styles: {
"background": "lightcoral"
},
events: {
"active-changed": function(e, context) { // Custom event exposed by the element
},
"click": function(e, context) { // Native events are also supported
}
},
onElementRendered: function(element, context) {
}
})
}]
}
</code></pre>
<h3 id="event-listeners-parameters">Event listener's parameters</h3>
<p>Available parameters for all listeners are described below:</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>event</td>
<td>Event</td>
<td>Native event argument object</td>
</tr>
<tr>
<td>context</td>
<td>Object</td>
<td>Context object, contains all kind of information and methods</td>
</tr>
</tbody></table>
<blockquote>
<p>Context object also contains information about the position of the element (the same information from <a href="#/apis/rt-grid/grid">getRelativePosition</a> method).</p>
</blockquote>
<h3 id="context-object-methods">Context object methods</h3>
<p>Context object also provides helper methods as shown below:</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>getData(field)</td>
<td>Get field value from the current row</td>
</tr>
<tr>
<td>setData(field, value)</td>
<td>Set field value to the current row</td>
</tr>
<tr>
<td>isElementDisabled()</td>
<td>Get data from the disablingField of the current row</td>
</tr>
<tr>
<td>disableElement(bool)</td>
<td>Set data to the disablingField of the current row</td>
</tr>
<tr>
<td>getError()</td>
<td>Get data from the errorField of the current row</td>
</tr>
<tr>
<td>setError(value)</td>
<td>Set data to the errorField of the current row</td>
</tr>
</tbody></table>
<h3 id="specific-options">Specific Options</h3>
<p>The specific options for each formatters are separately described on each formatter page.</p>