-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-154.html
326 lines (309 loc) · 29.2 KB
/
template-154.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<link rel="stylesheet" href="./resources/styles/elf-template.css">
<h1 id="filter-dialog">Filter Dialog</h1>
<p>The Filter Dialog is a user-friendly interface for filtering and sorting. The example below shows how Filter Dialog can be used in conjunction with <a href="#/extensions/tr-grid-row-filtering">Row Filtering Extension</a>. Users can hover over column header to show filter icon. Clicking on the icon will open Filter Dialog.</p>
<code-sandbox hash="ea3cfb10"><pre><code class="language-css">body {
padding: 2px;
}
efx-grid {
height: 500px;
}
</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 fields = ["companyName", "market", "CF_LAST", "CF_NETCHNG", "industry"];
var records = DataGenerator.generateRecords(fields, { seed: 0, numRows: 20 });
var configObj = {
columns: [
{ name: "Company", field: fields[0] },
{ name: "Market", field: fields[1], width: 120 },
{ name: "Last", field: fields[2], width: 100 },
{ name: "Net. Chng", field: fields[3], width: 100 },
{ name: "Industry", field: fields[4] }
],
staticDataRows: records,
rowFiltering:{
iconActivation: "onHover"
},
extensions: [
new RowFiltering()
]
};
var grid = document.getElementById("grid");
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="setup-guide">Setup guide</h2>
<pre><code class="language-js"> // efx-grid
import "@refinitiv-ui/efx-grid";
import "@refinitiv-ui/efx-grid/themes/halo/light";
// Extensions
import { RowFiltering } from "@refinitiv-ui/efx-grid/extensions";
// Filter Dialog module
import "@refinitiv-ui/efx-grid/filter-dialog";
import "@refinitiv-ui/efx-grid/filter-dialog/themes/halo/light"; // !Important. Theme must be imported.
</code></pre>
<p>The dialog cannot be used without Row Filtering Extension. So, initialize Row Filtering Extension instance and add it to <code>extensions</code> property on the grid configuration object. To open the dialog, you can either use <code>iconActivation</code> property or <code>openDialog</code> method from the extension.</p>
<pre><code class="language-js">var rowFilteringExt = new RowFiltering();
var configObj = {
extensions: [
rowFilteringExt
],
rowFiltering:{
iconActivation: "onHover"
},
columns: columns, // Columns config
staticDataRows: records
};
var grid = document.getElementById("grid_id");
grid.config = configObj;
function onClickButton(e) {
rowFilteringExt.openDialog(columnIndex);
}
</code></pre>
<h2 id="advanced-condition-tab">Advanced condition tab</h2>
<p>Filter dialog has three types of condition tabs: generic value condition (default), numeric value condition, and date time value condition. Each type has a different list of available operators. For example, numeric value condition contains only nemeric operators, such as Less than or Greater than operators. To specify the type for the dialog, define <code>fieldDataType</code> property on the column configuration object to one of the following values: <code>number</code>, <code>datetime</code>, and <code>text</code> or nothing (default). </p>
<code-sandbox hash="b99e7b1d"><pre><code class="language-css">efx-grid {
height: 500px;
}
</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 fields = ["companyName", "CF_NETCHNG", "ISODate"];
var records = DataGenerator.generateRecords(fields, { seed: 0, numRows: 20 });
var configObj = {
columns: [
{ name: "Company", field: "companyName" },
{ name: "Company (text)", field: "companyName", fieldDataType: "text" },
{ name: "Date (generic)", field: "ISODate", width: 180 },
{ name: "Date (datetime)", field: "ISODate", width: 180, fieldDataType: "datetime" },
{ name: "Change (generic)", field: "CF_NETCHNG", width: 130 },
{ name: "Change (number)", field: "CF_NETCHNG", width: 130, fieldDataType: "number" }
],
staticDataRows: records,
rowFiltering:{
iconActivation: "onHover"
},
extensions: [
new RowFiltering()
]
};
var grid = document.getElementById("grid");
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="dialog-options">Dialog options</h2>
<p>Filter Dialog can be customized by setting <code>dialogOptions</code> property on the Row Filtering Extension configuration object as shown in the following code snippet:</p>
<pre><code class="language-js">var configObj = {
rowFiltering: {
dialogOptions: {
sortUI: false
}
}
};
</code></pre>
<p>The options will be applied for every column in the grid. The options can be overriden on a column basis by using <code>beforeDialogOpened</code> event. You can specify <code>dialogOptions</code> property on the event argument and override the options set on the grid level as shown in the following code snippet:</p>
<pre><code class="language-js">var configObj = {
rowFiltering: {
dialogOptions: {
sortUI: false
},
beforeDialogOpened: function(e) {
if(e.field === "field A") {
e.dialogOptions = {
sortUI: true
};
}
}
}
};
</code></pre>
<h2 id="customizing-filter-item-list">Customizing filter item list</h2>
<p>By default, the item list in Filter Dialog is generated from existing data on the column, where the dialog is openned. Any duplicate value is automatically removed from the list. If there is formatting applied by Text Formatting Extension on the column, the items will also be formatted. </p>
<p><code>itemList</code> property on the dialog options can be used to replace the autogenerated one. This is useful when you want to prevent some values from being available for filtering. </p>
<p><code>additionalItems</code> property on the dialog options can be used to add more values to the existing list. The property can be used to include some nonexistent values (e.g., you have some server side filtering).</p>
<p><code>formattedDataAccessor</code> property on the dialog options allows you to specify a method for transforming and displaying items on the list. The method will be called on each item and it should return the formatted text you want to display in the dialog. The method can also be used to retrieve data from an object (i.e., data with non-premitive data type).</p>
<p><code>sortLogic</code> property on the dialog options allows you to specify a method for reordering items on the list. The method will be used by <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">Array.sort method</a></p>
<code-sandbox hash="b216fe9c"><pre><code class="language-css">efx-grid {
height: 300px;
}
</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 sortIdInDescendingOrder = function(valA, valB) {
if(valA < valB) {
return 1;
}
if(valB < valA) {
return -1;
}
return 0;
};
var booleanToYesNo = function(val) {
if(val != null) {
return val ? "Yes" : "No";
}
return "";
};
var onBeforeDialogOpened = function(e) {
var colIndex = e.colIndex;
if(colIndex === 0) { // id
e.dialogOptions = {
sortLogic: sortIdInDescendingOrder
};
} else if(colIndex === 2) { // replacement
e.dialogOptions = {
itemList: ["Left", "Center", "Right"]
};
} else if(colIndex === 3) { // addition
e.dialogOptions = {
additionalItems: [1, 0, "N/A"]
};
} else if(colIndex === 4) { // formatted
e.dialogOptions = {
formattedDataAccessor: booleanToYesNo
};
}
};
var fields = ["id", "boolean"];
var records = DataGenerator.generateRecords(fields, { seed: 0, numRows: 10 });
var configObj = {
rowFiltering: {
iconActivation: "onHover",
beforeDialogOpened: onBeforeDialogOpened
},
columns: [
{ name: "Id", field: "id", width: 80 },
{ name: "Boolean (default)", field: "boolean"},
{ name: "Boolean (replacement)", field: "boolean"},
{ name: "Boolean (addition)", field: "boolean"},
{ name: "Boolean (formatted)", field: "boolean"}
],
staticDataRows: records,
extensions: [
new RowFiltering()
]
};
var grid = document.getElementById("grid");
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="changing-dialog-language">Changing dialog language</h2>
<p>For more information about internationalization and how is it applied in different contexts see <a href="#/widgets/language-support">Language Support</a>.</p>
<h2 id="opening-filter-dialog-using-an-api">Opening Filter Dialog using an API</h2>
<p>The dialog can be openned from anywhere, not just from filter icon on the column header. Use <code>openDialog</code> method from Row Filtering extension instance, so that the dialog can be openned for specific column and linked up with grid instance. </p>
<p>The following example illustrates how the dialog can be opened from context menu using <a href="#/extensions/tr-grid-contextmenu">Context Menu Extension</a>. Right click on the column header to see the dialog.</p>
<code-sandbox hash="15d96aec"><pre><code class="language-css">html hr {
margin: 5px;
}
efx-grid {
height: 500px;
}
</code></pre>
<pre><code class="language-html">Language:
<select id="lang_selector">
<option value="en">English</option>
<option value="ja">Japanese</option>
<option value="de">German</option>
<option value="zh">Simplified Chinese</option>
<option value="zh-Hant">Traditional Chinese</option>
</select>
<hr>
<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 rowFilteringExt = new RowFiltering();
var contextMenuExt = new ContextMenu();
var fields = ["companyName", "market", "CF_LAST", "CF_NETCHNG", "ISODate"];
var records = DataGenerator.generateRecords(fields, { numRows: 10 });
var configObj = {
columns: [
{name: "Company", field: fields[0], sortable: true, fieldDataType: "text"},
{name: "Market", field: fields[1], width: 100, sortable: true, fieldDataType: "text"},
{name: "Last", field: fields[2], width: 100, sortable: true, fieldDataType: "number"},
{name: "Net. Chng", field: fields[3], width: 100, sortable: true, fieldDataType: "number"},
{name: "IPO Date", field: fields[4], sortable: true, fieldDataType: "datetime"}
],
staticDataRows: records,
contextMenu: {
items: {
MENU_1: {
text: "Filter",
callback: function (e) {
var colIndex = e.colIndex;
var lang = document.getElementById("lang_selector").value;
var dialogOptions = {
sortUI: true, // Show sorting section
filterUI: true, // Show filtering section
lang: lang,
fieldDataType: grid.api.getColumnDataType(colIndex)
};
rowFilteringExt.openDialog(colIndex, dialogOptions);
}
},
},
onMenu: function (e) {
e.menu.addItem("MENU_1");
}
},
extensions: [
rowFilteringExt,
contextMenuExt
]
};
var grid = document.getElementById("grid");
grid.config = configObj;
</code></pre>
</code-sandbox><h2 id="listening-an-event">Listening an event</h2>
<p>If you want to do a custom task after the dialog has been commited, you can listen for <code>dialogCommitted</code> event from Row Filtering Extension. The change from the dialog will be passed as <code>value</code> property in the event argument. </p>
<pre><code class="language-js">var onDialogCommitted = function (e) {
if(e.value) { // When user confirm dialog
console.log(e)
} else { // When user sort data from dialog
console.log(e);
}
}
var gridConfig = {
rowFiltering: {
dialogCommitted: onDialogCommitted
}
};
// Alternatively
rowFilteringExt.addEventListener("dialogCommitted", onDialogCommitted);
</code></pre>
<h2 style="margin-bottom:5px" id="api-refs">API Reference</h2>
<div id="elf-api-container"><div id="main-template" class="elf-template"> <section><header> <h1 class="subsection-title"><span class="attribs"><span class="type-signature"></span></span>FilterDialog<span class="signature">()</span><span class="type-signature"></span></h1> </header><article> <h3 class="subsection-title" id="type_definitions">Type Definitions</h3>
<div class="item"> <div class="item-type">typedef</div> <h4 class="name" id="~ComboBoxItem">ComboBoxItem</h4> <h5>Type:</h5> <span class="param-type">Object</span> <h5>Properties:</h5> <div class="props"><table> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>label</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">text of item</td> </tr> <tr> <td class="name"><code>value</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="description last">value of item when item is selected</td> </tr> </tbody></table></div><div class="details"> </div></div>
<div class="item"> <div class="item-type">typedef</div> <h4 class="name" id="~Config">Config</h4> <h5>Type:</h5> <span class="param-type">Object</span> <h5>Properties:</h5> <div class="props"><table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>data</code></td> <td class="type"> <span class="param-type">Object</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">Column data</td> </tr> <tr> <td class="name"><code>sortState</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> </td> <td class="description last">"a" for ascending or "d" for descending</td> </tr> <tr> <td class="name"><code>sortUI</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> true </td> <td class="description last">Show Sort area</td> </tr> <tr> <td class="name"><code>filterUI</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> true </td> <td class="description last">Show Filter area</td> </tr> <tr> <td class="name"><code>advancedFilter</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> true </td> <td class="description last">Show advanced tab</td> </tr> <tr> <td class="name"><code>compactMode</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> false </td> <td class="description last">Force compact mode in dialog</td> </tr> <tr> <td class="name"><code>dateTimeFormat</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> "dd-MM-yy" </td> <td class="description last">Specifies the string format for the date time picker in the filter dialog based on date-fns format, follow https://date-fns.org/v3.6.0/docs/format.</td> </tr> <tr> <td class="name"><code>blankValues</code></td> <td class="type"> <span class="param-type">string</span> | <span class="param-type">boolean</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> false </td> <td class="description last">Display a Blanks item in the filter dialog to represent an empty value. If a string is passed, it will be used as the label for the blank item</td> </tr> <tr> <td class="name"><code>filterChanged</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> </td> <td class="description last">Filter changed handler</td> </tr> <tr> <td class="name"><code>confirm</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> </td> <td class="description last">Alias of filterChanged</td> </tr> <tr> <td class="name"><code>cancel</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> </td> <td class="description last">Alias of dialog cancel</td> </tr> <tr> <td class="name"><code>sortChanged</code></td> <td class="type"> <span class="param-type">function</span> </td> <td class="attributes"> <optional><br> </td> <td class="default"> </td> <td class="description last">Sort changed handler</td> </tr> </tbody></table></div><div class="details"> </div></div> <h3 class="subsection-title" id="methods">Methods</h3>
<div class="item"> <div class="item-type">function</div> <h4 class="name" id="hide"><span class="type-signature"></span>hide<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Hide the dialog </div> <div class="details"> </div> </div>
<div class="item"> <div class="item-type">function</div> <h4 class="name" id="hideSortUI"><span class="type-signature"></span>hideSortUI<span class="signature">(val)</span><span class="type-signature"></span></h4> <div class="description"> Hide Sort UI block </div> <h5>Parameters:</h5> <div class="params"> <div class="param"> <div class="name">val</div> <div class="type"> <span class="param-type">boolean</span> </div> <div class="description"> value </div> </div> </div> <div class="details"> </div> </div>
<div class="item"> <div class="item-type">function</div> <h4 class="name" id="init"><span class="type-signature"></span>init<span class="signature">(options)</span><span class="type-signature"></span></h4> <div class="description"> Initialize dialog </div> <h5>Parameters:</h5> <div class="params"> <div class="param"> <div class="name">options</div> <div class="type"> <span class="param-type"><a href="#/widgets/filter-dialog#~Config">FilterDialog~Config</a></span> </div> <div class="description"> initial data </div> </div> </div> <div class="details"> </div> </div>
<div class="item"> <div class="item-type">function</div> <h4 class="name" id="setSortState"><span class="type-signature"></span>setSortState<span class="signature">(val)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <div class="params"> <div class="param"> <div class="name">val</div> <div class="type"> <span class="param-type">string</span> </div> <div class="description"> Sorting state "d" or "a" </div> </div> </div> <div class="details"> </div> </div>
<div class="item"> <div class="item-type">function</div> <h4 class="name" id="show"><span class="type-signature"></span>show<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Show the dialog as a popup </div> <div class="details"> </div> </div> </article></section></div></div>