@refinitiv-ui/efx-grid 6.0.42 → 6.0.43

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. package/lib/column-format-dialog/lib/column-format-dialog.d.ts +1 -0
  2. package/lib/column-format-dialog/lib/column-format-dialog.js +3 -24
  3. package/lib/column-format-dialog/lib/preview-table.d.ts +1 -1
  4. package/lib/column-format-dialog/lib/preview-table.js +15 -27
  5. package/lib/core/dist/core.js +7 -1
  6. package/lib/core/dist/core.min.js +1 -1
  7. package/lib/core/es6/grid/Core.js +1 -1
  8. package/lib/core/es6/grid/plugins/SortableTitlePlugin.js +6 -0
  9. package/lib/formatters/es6/CoralButtonFormatter.d.ts +2 -2
  10. package/lib/formatters/es6/CoralCheckboxFormatter.d.ts +1 -1
  11. package/lib/formatters/es6/CoralComboBoxFormatter.d.ts +4 -4
  12. package/lib/formatters/es6/CoralIconFormatter.d.ts +3 -3
  13. package/lib/formatters/es6/CoralInputFormatter.d.ts +1 -1
  14. package/lib/formatters/es6/CoralRadioButtonFormatter.d.ts +2 -2
  15. package/lib/formatters/es6/CoralSelectFormatter.d.ts +4 -4
  16. package/lib/formatters/es6/CoralToggleFormatter.d.ts +1 -1
  17. package/lib/formatters/es6/DuplexEmeraldDateTimePickerFormatter.d.ts +1 -1
  18. package/lib/formatters/es6/EFButtonFormatter.d.ts +2 -2
  19. package/lib/formatters/es6/EFCheckboxFormatter.d.ts +1 -1
  20. package/lib/formatters/es6/EFComboBoxFormatter.d.ts +4 -4
  21. package/lib/formatters/es6/EFDateTimePickerFormatter.d.ts +1 -1
  22. package/lib/formatters/es6/EFIconFormatter.d.ts +3 -3
  23. package/lib/formatters/es6/EFNumberFieldFormatter.d.ts +1 -1
  24. package/lib/formatters/es6/EFRadioButtonFormatter.d.ts +2 -2
  25. package/lib/formatters/es6/EFSelectFormatter.d.ts +4 -4
  26. package/lib/formatters/es6/EFTextFieldFormatter.d.ts +1 -1
  27. package/lib/formatters/es6/EFToggleFormatter.d.ts +1 -1
  28. package/lib/formatters/es6/EmeraldDateTimePickerFormatter.d.ts +1 -1
  29. package/lib/formatters/es6/FormatterBuilder.d.ts +6 -2
  30. package/lib/formatters/es6/FormatterBuilder.js +328 -178
  31. package/lib/formatters/es6/NumericInputFormatter.d.ts +1 -1
  32. package/lib/formatters/es6/PercentBarFormatter.d.ts +6 -6
  33. package/lib/formatters/es6/SimpleImageFormatter.d.ts +3 -3
  34. package/lib/formatters/es6/SimpleInputFormatter.d.ts +1 -1
  35. package/lib/formatters/es6/SimpleLinkFormatter.d.ts +3 -3
  36. package/lib/formatters/es6/SimpleTickerFormatter.d.ts +3 -3
  37. package/lib/formatters/es6/SimpleToggleFormatter.d.ts +3 -3
  38. package/lib/formatters/es6/TextFormatter.d.ts +1 -1
  39. package/lib/grid/index.js +1 -1
  40. package/lib/rt-grid/dist/rt-grid.js +1 -0
  41. package/lib/rt-grid/es6/Grid.d.ts +2 -1
  42. package/lib/rt-grid/es6/Grid.js +1 -0
  43. package/lib/tr-grid-column-stack/es6/ColumnStack.js +35 -25
  44. package/lib/tr-grid-filter-input/es6/FilterInput.d.ts +17 -17
  45. package/lib/tr-grid-filter-input/es6/FilterInput.js +146 -33
  46. package/lib/types/es6/CoralButtonFormatter.d.ts +2 -2
  47. package/lib/types/es6/CoralCheckboxFormatter.d.ts +1 -1
  48. package/lib/types/es6/CoralComboBoxFormatter.d.ts +4 -4
  49. package/lib/types/es6/CoralIconFormatter.d.ts +3 -3
  50. package/lib/types/es6/CoralInputFormatter.d.ts +1 -1
  51. package/lib/types/es6/CoralRadioButtonFormatter.d.ts +2 -2
  52. package/lib/types/es6/CoralSelectFormatter.d.ts +4 -4
  53. package/lib/types/es6/CoralToggleFormatter.d.ts +1 -1
  54. package/lib/types/es6/DuplexEmeraldDateTimePickerFormatter.d.ts +1 -1
  55. package/lib/types/es6/EFButtonFormatter.d.ts +2 -2
  56. package/lib/types/es6/EFCheckboxFormatter.d.ts +1 -1
  57. package/lib/types/es6/EFComboBoxFormatter.d.ts +4 -4
  58. package/lib/types/es6/EFDateTimePickerFormatter.d.ts +1 -1
  59. package/lib/types/es6/EFIconFormatter.d.ts +3 -3
  60. package/lib/types/es6/EFNumberFieldFormatter.d.ts +1 -1
  61. package/lib/types/es6/EFRadioButtonFormatter.d.ts +2 -2
  62. package/lib/types/es6/EFSelectFormatter.d.ts +4 -4
  63. package/lib/types/es6/EFTextFieldFormatter.d.ts +1 -1
  64. package/lib/types/es6/EFToggleFormatter.d.ts +1 -1
  65. package/lib/types/es6/EmeraldDateTimePickerFormatter.d.ts +1 -1
  66. package/lib/types/es6/FilterInput.d.ts +17 -17
  67. package/lib/types/es6/FormatterBuilder.d.ts +6 -2
  68. package/lib/types/es6/NumericInputFormatter.d.ts +1 -1
  69. package/lib/types/es6/PercentBarFormatter.d.ts +6 -6
  70. package/lib/types/es6/RealtimeGrid/Grid.d.ts +22 -0
  71. package/lib/types/es6/SimpleImageFormatter.d.ts +3 -3
  72. package/lib/types/es6/SimpleInputFormatter.d.ts +1 -1
  73. package/lib/types/es6/SimpleLinkFormatter.d.ts +3 -3
  74. package/lib/types/es6/SimpleTickerFormatter.d.ts +3 -3
  75. package/lib/types/es6/SimpleToggleFormatter.d.ts +3 -3
  76. package/lib/types/es6/TextFormatter.d.ts +1 -1
  77. package/lib/versions.json +4 -4
  78. package/package.json +1 -1
@@ -1,152 +1,235 @@
1
-
2
-
3
1
  /** @typedef {Object} FormatterBuilder~Options
4
2
  * @description FormatterBuilder options
3
+ * @property {string=} field
5
4
  * @property {Object=} attributes
6
5
  * @property {Object=} styles
7
6
  * @property {Object=} events
7
+ * @property {Function=} changeHandler
8
+ * @property {Array.<Function>=} changeHandlers
9
+ * @property {Function=} onElementRendered
8
10
  */
9
11
 
10
12
  /** Dictionary that contain reserved attribute to context element
11
- * @type {object}
13
+ * @type {!Object}
12
14
  * @private
15
+ * @constant
13
16
  */
14
- var _reservedAttributesDict = {
17
+ var ReservedAttributes = {
15
18
  "api": true,
16
- "wrapper": true,
19
+ "wrapper": true, // wrapper is generated during runtime binding
17
20
  "grid": true,
18
21
  "field": true,
19
22
  "rowIndex": true,
20
23
  "value": true,
21
24
  "setData": true,
22
25
  "getData": true,
26
+ "disableElement": true,
27
+ "isElementDisabled": true,
28
+ "setError": true,
29
+ "getError": true,
23
30
  "styles": true,
24
31
  "attributes": true,
25
- "tagName": true,
32
+ "tagName": true, // for internal use only
33
+ "refName": true, // for internal use only
26
34
  "events": true,
27
- "userEvents": true,
28
- "defaultEvents": true,
29
- "onContextCreated": true,
30
- "onElementCreated": true,
31
- "onElementUpdated": true,
32
- "changeHook": true,
33
- "changeHooks": true
35
+ "userEvents": true, // for internal use only
36
+ "defaultEvents": true, // for internal use only
37
+ "onContextCreated": true, // for internal use only
38
+ "onElementCreated": true, // for internal use only
39
+ "onElementUpdated": true, // for internal use only
40
+ "onElementRendered": true,
41
+ "changeHook": true, // for internal use only
42
+ "changeHooks": true, // for internal use only
43
+ "changeHandler": true,
44
+ "changeHandlers": true
34
45
  };
35
46
 
36
- function convertPxToString(px) {
37
- return px + (typeof px === "number" ? "px" : "");
47
+ /** Clone all non-reserved properties from master to base
48
+ * @private
49
+ * @function
50
+ * @param {Object} base Base object
51
+ * @param {Object} master Master object. There will be no modification on this object
52
+ */
53
+ function _assignProperties(base, master) {
54
+ for (var key in master) {
55
+ if (!ReservedAttributes[key]) {
56
+ base[key] = master[key];
57
+ }
58
+ }
38
59
  }
60
+ /** Clone a property with Object map from master to base
61
+ * @private
62
+ * @function
63
+ * @param {Object} base Base object
64
+ * @param {Object} master Master object. There will be no modification on this object
65
+ * @returns {boolean} Returns true, if there is any change
66
+ */
67
+ function _assignAttributes(base, master) {
68
+ var mObj = master.attributes;
69
+ if(!mObj) {
70
+ return false;
71
+ }
39
72
 
40
- function positionLocator(ctx, userFunc, e) { // eslint-disable-line
41
- if (!ctx.grid.isBinding()) {
42
- ctx.grid.getRelativePosition(e, ctx);
43
- userFunc(e, ctx);
73
+ var dirty = false;
74
+ var bObj = base.attributes;
75
+ if(!bObj) {
76
+ bObj = {};
77
+ }
78
+ for(var key in mObj) {
79
+ dirty = true;
80
+ bObj[key] = mObj[key];
81
+ }
82
+ if(!dirty) {
83
+ return false;
44
84
  }
85
+
86
+ if(!base.attributes) {
87
+ base.attributes = bObj;
88
+ }
89
+ return true;
45
90
  }
91
+ /** Clone a property with Object map from master to base
92
+ * @private
93
+ * @function
94
+ * @param {Object} base Base object
95
+ * @param {Object} master Master object. There will be no modification on this object
96
+ * @returns {boolean} Returns true, if there is any change
97
+ */
98
+ function _assignStyles(base, master) {
99
+ var mObj = master.styles;
100
+ if(!mObj) {
101
+ return false;
102
+ }
46
103
 
47
- function forEachSetProperties(attrs, fn) {
48
- if (typeof attrs === "object" && typeof fn === "function") {
49
- for (var name in attrs) {
50
- var val = attrs[name];
51
- if (name === "height" || name === "width") {
52
- val = convertPxToString(val);
53
- } else {
54
- val += ""; // force to string
104
+ var dirty = false;
105
+ var bObj = base.styles;
106
+ if(!bObj) {
107
+ bObj = {};
108
+ }
109
+ for(var key in mObj) {
110
+ dirty = true;
111
+ var val = mObj[key];
112
+ if(key === "width" || key === "height") {
113
+ if(typeof val === "number") {
114
+ val = val + "px";
55
115
  }
56
- fn(name, val);
57
116
  }
117
+ bObj[key] = val;
118
+ }
119
+ if(!dirty) {
120
+ return false;
58
121
  }
59
- }
60
-
61
- function assignAttribute(text, options, defaultOpt) {
62
- forEachSetProperties(defaultOpt.attributes, function (name, val) {
63
- text.push(' element.setAttribute("' + name + '", "' + val + '");');
64
- });
65
122
 
66
- forEachSetProperties(options.attributes, function (name, val) {
67
- text.push(' element.setAttribute("' + name + '", "' + val + '");');
68
- });
123
+ if(!base.styles) {
124
+ base.styles = bObj;
125
+ }
126
+ return true;
69
127
  }
70
128
 
71
- function assignStyle(text, options, defaultOpt) {
72
- forEachSetProperties(defaultOpt.styles, function (name, val) {
73
- text.push(' element.style["' + name + '"] = "' + val + '";');
74
- });
75
-
76
- forEachSetProperties(options.styles, function (name, val) {
77
- text.push(' element.style["' + name + '"] = "' + val + '";');
78
- });
129
+ /** @private
130
+ * @function
131
+ * @param {Object} ctx
132
+ * @param {Function} userFunc
133
+ * @param {Object} e
134
+ */
135
+ function _positionLocator(ctx, userFunc, e) {
136
+ if (!ctx.grid.isBinding()) {
137
+ ctx.grid.getRelativePosition(e, ctx);
138
+ userFunc(e, ctx);
139
+ }
79
140
  }
80
-
81
- function assignListener(text, options, defaultOpt) {
82
- var name;
83
- var events = defaultOpt.events || {};
84
- for (name in events) {
85
- if (typeof events[name] === "function") {
86
- text.push(' element.addEventListener("' + name + '", positionLocator.bind(null, ctx, ctx.defaultEvents["' + name + '"]));');
87
- }
141
+ /** Clone event listerners from master to base
142
+ * @private
143
+ * @function
144
+ * @param {Object} base Base object
145
+ * @param {Object} master Master object. There will be no modification on this object
146
+ * @param {string} optionType
147
+ * @returns {boolean} Returns true, if there is any change
148
+ */
149
+ function _assignListener(base, master, optionType) {
150
+ var mObj = master.events;
151
+ if(!mObj) {
152
+ return false;
88
153
  }
89
154
 
90
- events = options.events || {};
91
- for (name in events) {
92
- if (typeof events[name] === "function") {
93
- text.push(' element.addEventListener("' + name + '", positionLocator.bind(null, ctx, ctx.userEvents["' + name + '"]));');
155
+ var dirty = false;
156
+ var bObj = base[optionType];
157
+ if(!bObj) {
158
+ bObj = {};
159
+ }
160
+ for (var key in mObj) {
161
+ var func = mObj[key];
162
+ if (typeof func === "function") {
163
+ dirty = true;
164
+ bObj[key] = _positionLocator.bind(null, base, func);
94
165
  }
95
166
  }
167
+ if(!dirty) {
168
+ return false;
169
+ }
170
+ if(!base[optionType]) {
171
+ base[optionType] = bObj;
172
+ }
173
+ return true;
96
174
  }
97
175
 
98
-
99
176
  /** @private
100
- * @this ContextObject
177
+ * @param {Object} ctx
101
178
  * @param {Object} colDef User's column definition object
102
179
  * @param {tr.Grid} grid Core grid instance
103
180
  */
104
- function _onInitContextObject(colDef, grid) { // Executed once per column
105
- this.grid = grid; // WARNING: using ctx as closure variable
106
- if (!this.field) {
107
- this.field = colDef.field;
108
- if(this.disablingField === null) {
109
- this.disablingField = this.field ? this.field + "_DISABLED" : null;
181
+ function _onInitContextObject(ctx, colDef, grid) { // Executed once per column
182
+ ctx.grid = grid; // WARNING: using ctx as closure variable
183
+ if (!ctx.field) {
184
+ ctx.field = colDef.field;
185
+ if(ctx.disablingField == null) {
186
+ ctx.disablingField = ctx.field ? ctx.field + "_DISABLED" : null;
110
187
  }
111
- if(this.errorField === null) {
112
- this.errorField = this.field ? this.field + "_ERROR" : null;
188
+ if(ctx.errorField == null) {
189
+ ctx.errorField = ctx.field ? ctx.field + "_ERROR" : null;
113
190
  }
114
191
  }
115
192
 
116
- this.setData = _setData;
117
- this.getData = _getData;
118
- this.disableElement = _disableElement;
119
- this.isElementDisabled = _isElementDisabled;
120
- this.setError = _setError;
121
- this.getError = _getError;
193
+ ctx.disableElement = _disableElement;
194
+ ctx.isElementDisabled = _isElementDisabled;
195
+ ctx.setError = _setError;
196
+ ctx.getError = _getError;
122
197
  }
123
198
  /** @private
124
199
  * @this ContextObject
125
200
  * @param {string} field
126
201
  * @param {*} value
127
202
  */
128
- function _setData(field, value) {
129
- if(this.wrapper === "real-time-grid") {
130
- var rowDef = this.api.getRowDefinition(this.rowIndex);
131
- if(rowDef) {
132
- rowDef.setStaticData(field, value);
133
- }
134
- } else {
135
- this.api.getDataView().setDataAt(this.rowIndex, field, value); // WARNING: Use of closure variable
203
+ function _setRtGridData(field, value) {
204
+ var rowDef = this.api.getRowDefinition(this.rowIndex);
205
+ if(rowDef) {
206
+ rowDef.setStaticData(field, value);
136
207
  }
137
208
  }
138
209
  /** @private
139
210
  * @this ContextObject
140
211
  * @param {boolean} field
141
- * @return {*} Value
212
+ * @returns {*} Value
142
213
  */
143
- function _getData(field) {
144
- if(this.wrapper === "real-time-grid") {
145
- var rowDef = this.api.getRowDefinition(this.rowIndex);
146
- return rowDef ? rowDef.getData(field) : null;
147
- } else {
148
- return this.api.getDataView().getDataAt(this.rowIndex, field);
149
- }
214
+ function _getRtGridData(field) {
215
+ var rowDef = this.api.getRowDefinition(this.rowIndex);
216
+ return rowDef ? rowDef.getData(field) : null;
217
+ }
218
+ /** @private
219
+ * @this ContextObject
220
+ * @param {string} field
221
+ * @param {*} value
222
+ */
223
+ function _setCoreGridData(field, value) {
224
+ this.api.getDataView().setDataAt(this.rowIndex, field, value);
225
+ }
226
+ /** @private
227
+ * @this ContextObject
228
+ * @param {boolean} field
229
+ * @returns {*} Value
230
+ */
231
+ function _getCoreGridData(field) {
232
+ return this.api.getDataView().getDataAt(this.rowIndex, field);
150
233
  }
151
234
  /** @private
152
235
  * @this ContextObject
@@ -159,7 +242,7 @@ function _disableElement(bool) {
159
242
  }
160
243
  /** @private
161
244
  * @this ContextObject
162
- * @return {boolean}
245
+ * @returns {boolean}
163
246
  */
164
247
  function _isElementDisabled() {
165
248
  return this.getData(this.disablingField);
@@ -175,104 +258,181 @@ function _setError(val) {
175
258
  }
176
259
  /** @private
177
260
  * @this ContextObject
178
- * @return {*}
261
+ * @returns {*}
179
262
  */
180
263
  function _getError() {
181
264
  return this.getData(this.errorField);
182
265
  }
183
266
 
267
+ /** @private
268
+ * @function
269
+ * @param {Object} ctx
270
+ * @param {Object} e
271
+ */
272
+ function _predefinedBinding(ctx, e) {
273
+ ctx.api = e["grid"];
274
+ if(!ctx.wrapper) {
275
+ ctx.wrapper = "real-time-grid";
276
+ ctx.setData = _setRtGridData;
277
+ ctx.getData = _getRtGridData;
278
+ }
279
+ var rowData = ctx.rowData = e["rowData"];
280
+ if(ctx.field) {
281
+ ctx.value = rowData ? rowData[ctx.field] : null;
282
+ } else {
283
+ ctx.value = e["data"];
284
+ }
285
+ ctx.rowIndex = e["rowIndex"];
286
+ ctx.colIndex = e["colIndex"];
287
+ ctx.cell = e["cell"];
184
288
 
185
- function buildFnText(wrapper, ctx, options, defaultOpt) {
186
- for (var defKey in defaultOpt) {
187
- if (!_reservedAttributesDict[defKey]) {
188
- ctx[defKey] = defaultOpt[defKey];
189
- }
289
+ _commonBinding(ctx);
290
+ }
291
+ /** @private
292
+ * @function
293
+ * @param {Object} ctx
294
+ * @param {number} rowIndex
295
+ * @param {number} columnIndex
296
+ * @param {*} value
297
+ * @param {Object} cell
298
+ * @param {Object} colDef
299
+ * @param {Object} dataRow
300
+ * @param {Object} dataTable
301
+ * @param {Object} dataView
302
+ * @param {Object} cgrid
303
+ */
304
+ function _predefinedFormatter(ctx, rowIndex, columnIndex, value, cell, colDef, dataRow, dataTable, dataView, cgrid) {
305
+ ctx.api = cgrid;
306
+ if(!ctx.wrapper) {
307
+ ctx.wrapper = "composite-grid";
308
+ ctx.setData = _setCoreGridData;
309
+ ctx.getData = _getCoreGridData;
190
310
  }
191
- for (var optKey in options) {
192
- if (!_reservedAttributesDict[optKey]) {
193
- ctx[optKey] = options[optKey];
194
- }
311
+ var rowData = ctx.rowData = dataRow;
312
+ if (ctx.field) {
313
+ ctx.value = rowData ? rowData[ctx.field] : null;
314
+ } else {
315
+ ctx.value = value;
195
316
  }
317
+ ctx.rowIndex = rowIndex;
318
+ ctx.colIndex = columnIndex;
319
+ ctx.cell = cell;
196
320
 
197
- if (defaultOpt.onContextCreated) {
198
- defaultOpt.onContextCreated(ctx, options);
321
+ _commonBinding(ctx);
322
+ }
323
+ /** @private
324
+ * @function
325
+ * @param {Object} ctx
326
+ */
327
+ function _commonBinding(ctx) {
328
+ var elem = ctx.cell.getContent();
329
+ if(!elem || (elem._formatterName !== ctx.refName)) {
330
+ elem = document.createElement(ctx.tagName);
331
+ elem._formatterName = ctx.refName;
332
+ if (ctx.onElementCreated) {
333
+ ctx.onElementCreated(elem, ctx);
334
+ }
335
+
336
+ var attrs = ctx.attributes;
337
+ if(attrs) {
338
+ for(var attrName in attrs) {
339
+ elem.setAttribute(attrName, attrs[attrName] || "");
340
+ }
341
+ }
342
+
343
+ var stys = ctx.styles;
344
+ if(stys) {
345
+ for(var styName in stys) {
346
+ elem.style[styName] = stys[styName];
347
+ }
348
+ }
349
+
350
+ var evts, evtName;
351
+ evts = ctx.defaultEvents;
352
+ if(evts) {
353
+ for (evtName in evts) {
354
+ elem.addEventListener(
355
+ evtName,
356
+ evts[evtName]
357
+ );
358
+ }
359
+ }
360
+ evts = ctx.userEvents;
361
+ if(evts) {
362
+ for (evtName in evts) {
363
+ elem.addEventListener(
364
+ evtName,
365
+ evts[evtName]
366
+ );
367
+ }
368
+ }
199
369
  }
200
370
 
201
- var text = [];
202
- // Initial setup based on different types of grid
203
- if(wrapper === "real-time-grid") {
204
- text.push('(function(e) {');
205
- text.push(' ctx.api = e["grid"];');
206
- text.push(' ctx.wrapper = "real-time-grid";');
207
- if (options.field) {
208
- text.push(' ctx.value = e["rowData"][ctx.field];');
371
+ var rowData = ctx.rowData;
372
+ if(ctx.disablingField) {
373
+ if(rowData && rowData[ctx.disablingField]){
374
+ elem.setAttribute("disabled", "");
209
375
  } else {
210
- text.push(' ctx.value = e["data"];');
376
+ elem.removeAttribute("disabled");
211
377
  }
212
- text.push(' ctx.rowIndex = e["rowIndex"];');
213
- text.push(' ctx.colIndex = e["colIndex"];');
214
- text.push(' var cell = ctx.cell = e["cell"];'); // cell is for referencing later
215
- } else {
216
- text.push('(function(rowIndex, columnIndex, value, cell, colDef, dataRow, dataTable, dataView, cgrid) {');
217
- text.push(' ctx.api = cgrid;');
218
- text.push(' ctx.wrapper = "composite-grid";');
219
- if (options.field) {
220
- text.push(' ctx.value = dataRow ? dataRow[ctx.field] : null;');
378
+ }
379
+ if(ctx.errorField) {
380
+ if(rowData && rowData[ctx.errorField]){
381
+ elem.setAttribute("error", "");
221
382
  } else {
222
- text.push(' ctx.value = value;');
383
+ elem.removeAttribute("error");
223
384
  }
224
- text.push(' ctx.rowIndex = rowIndex;');
225
- text.push(' ctx.colIndex = columnIndex;');
226
- text.push(' ctx.cell = cell;');
227
385
  }
228
386
 
229
- // Common setups triggered once per element
230
- text.push(' var element = cell.getContent();');
231
- text.push(' if(!element || (element._formatterName !== "' + defaultOpt.refName + '")) {');
232
- text.push(' element = document.createElement("' + defaultOpt.tagName + '");');
233
- text.push(' element._formatterName = "' + defaultOpt.refName + '";');
234
- if (defaultOpt.onElementCreated) {
235
- ctx.onElementCreated = defaultOpt.onElementCreated;
236
- text.push(' ctx.onElementCreated(element, ctx);');
387
+ if(ctx.onElementUpdated) {
388
+ ctx.onElementUpdated(elem, ctx);
389
+ }
390
+
391
+ if (ctx.onElementRendered) {
392
+ ctx.onElementRendered(elem, ctx);
237
393
  }
238
394
 
239
- assignAttribute(text, options, defaultOpt);
240
- assignStyle(text, options, defaultOpt);
241
- assignListener(text, options, defaultOpt);
395
+ ctx.cell.setContent(elem);
396
+ }
242
397
 
243
- text.push(' }\n'); // End of setup
398
+ /** @private
399
+ * @function
400
+ * @param {Object} ctx Context object
401
+ * @param {Object} userOpt User options
402
+ * @param {Object} defaultOpt Default options
403
+ */
404
+ function _buildContextObject(ctx, userOpt, defaultOpt) {
405
+ _assignProperties(ctx, defaultOpt);
406
+ _assignProperties(ctx, userOpt);
244
407
 
245
- if(typeof options.disablingField === "string" || options.disablingField == null) {
246
- text.push(' if(ctx.isElementDisabled()) {');
247
- text.push(' element.setAttribute("disabled", "");');
248
- text.push(' } else {');
249
- text.push(' element.removeAttribute("disabled");');
250
- text.push(' }');
251
- }
252
- if(typeof options.errorField === "string" || options.errorField == null) {
253
- text.push(' if(ctx.getError()) {');
254
- text.push(' element.setAttribute("error", "");');
255
- text.push(' } else {');
256
- text.push(' element.removeAttribute("error");');
257
- text.push(' }');
258
- }
408
+ _assignAttributes(ctx, defaultOpt);
409
+ _assignAttributes(ctx, userOpt);
410
+
411
+ _assignStyles(ctx, defaultOpt);
412
+ _assignStyles(ctx, userOpt);
413
+
414
+ _assignListener(ctx, defaultOpt, "defaultEvents");
415
+ _assignListener(ctx, userOpt, "userEvents");
259
416
 
260
- // Element binding/updating
417
+ ctx.field = userOpt.field || "";
418
+ ctx.refName = defaultOpt.refName || "_defaultFormatter";
419
+ ctx.tagName = defaultOpt.tagName || "div";
420
+
421
+ if (defaultOpt.onElementCreated) {
422
+ ctx.onElementCreated = defaultOpt.onElementCreated;
423
+ }
261
424
  if (defaultOpt.onElementUpdated) {
262
425
  ctx.onElementUpdated = defaultOpt.onElementUpdated;
263
- text.push(' ctx.onElementUpdated(element, ctx);');
264
426
  }
265
-
266
- if (typeof options.onElementRendered === "function") {
267
- ctx.onElementRendered = options.onElementRendered;
268
- text.push(' ctx.onElementRendered(element, ctx);');
427
+ if (typeof userOpt.onElementRendered === "function") {
428
+ ctx.onElementRendered = userOpt.onElementRendered;
269
429
  }
270
-
271
- text.push(' cell.setContent(element);');
272
- text.push('})');
273
- return text.filter(Boolean).join('\n');
274
430
  }
275
431
 
432
+ /** @private
433
+ */
434
+ function _emptyFunc() {}
435
+
276
436
  /** @constructor
277
437
  * @param {*=} options
278
438
  */
@@ -288,8 +448,6 @@ var FormatterBuilder = function (options) {
288
448
  FormatterBuilder.create = function (userOptions, defaultOpt) {
289
449
  userOptions = userOptions || {};
290
450
  defaultOpt = defaultOpt || {};
291
- var ctx = {}; // WANRING: This object is used as a closure variable
292
- ctx.field = userOptions.field;
293
451
 
294
452
  if (defaultOpt.changeHook) {
295
453
  var changeHandler = userOptions.changeHandler || defaultOpt.changeHandler;
@@ -307,26 +465,18 @@ FormatterBuilder.create = function (userOptions, defaultOpt) {
307
465
  }
308
466
  }
309
467
 
310
- if (defaultOpt.events) {
311
- ctx.defaultEvents = defaultOpt.events;
312
- }
468
+ var ctx = {};
469
+ _buildContextObject(ctx, userOptions, defaultOpt);
313
470
 
314
- if (userOptions.events) {
315
- ctx.userEvents = userOptions.events;
471
+ if (defaultOpt.onContextCreated) {
472
+ defaultOpt.onContextCreated(ctx, userOptions);
316
473
  }
317
474
 
318
- var txt;
319
- txt = buildFnText("composite-grid", ctx, userOptions, defaultOpt);
320
- var compositeGridBinding = eval(txt);
321
-
322
- txt = buildFnText("real-time-grid", ctx, userOptions, defaultOpt);
323
- var rtGridBinding = eval(txt);
324
-
325
475
  return {
326
- render: function () {},
327
- init: _onInitContextObject.bind(ctx),
328
- bind: compositeGridBinding,
329
- binding: rtGridBinding
476
+ render: _emptyFunc,
477
+ init: _onInitContextObject.bind(null, ctx),
478
+ bind: _predefinedFormatter.bind(null, ctx),
479
+ binding: _predefinedBinding.bind(null, ctx)
330
480
  };
331
481
  };
332
482
 
@@ -5,7 +5,7 @@ declare class NumericInputFormatter {
5
5
 
6
6
  constructor(options?: any);
7
7
 
8
- public static create(options?: (FormatterBuilder.Options|any)): any;
8
+ public static create(options?: (FormatterBuilder.Options|any)|null): any;
9
9
 
10
10
  }
11
11
 
@@ -4,11 +4,11 @@ import {PercentBar} from "../../tr-grid-util/es6/PercentBar.js";
4
4
  declare namespace PercentBarFormatter {
5
5
 
6
6
  type Options = {
7
- alignment?: string,
8
- movementColor?: boolean,
9
- barColor?: string,
10
- textHidden?: boolean,
11
- textWidth?: (number|string)
7
+ alignment?: string|null,
8
+ movementColor?: boolean|null,
9
+ barColor?: string|null,
10
+ textHidden?: boolean|null,
11
+ textWidth?: (number|string)|null
12
12
  };
13
13
 
14
14
  }
@@ -17,7 +17,7 @@ declare class PercentBarFormatter {
17
17
 
18
18
  constructor(options?: any);
19
19
 
20
- public static create(options?: (FormatterBuilder.Options|PercentBarFormatter.Options|any)): any;
20
+ public static create(options?: (FormatterBuilder.Options|PercentBarFormatter.Options|any)|null): any;
21
21
 
22
22
  }
23
23
 
@@ -3,8 +3,8 @@ import FormatterBuilder from "./FormatterBuilder.js";
3
3
  declare namespace SimpleImageFormatter {
4
4
 
5
5
  type Options = {
6
- height?: (string|number),
7
- width?: (string|number)
6
+ height?: (string|number)|null,
7
+ width?: (string|number)|null
8
8
  };
9
9
 
10
10
  }
@@ -13,7 +13,7 @@ declare class SimpleImageFormatter {
13
13
 
14
14
  constructor(options?: any);
15
15
 
16
- public static create(options?: (FormatterBuilder.Options|SimpleImageFormatter.Options|any)): any;
16
+ public static create(options?: (FormatterBuilder.Options|SimpleImageFormatter.Options|any)|null): any;
17
17
 
18
18
  }
19
19