@refinitiv-ui/efx-grid 6.0.94 → 6.0.96

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,8 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- import { Ext } from "../../tr-grid-util/es6/Ext.js";
3
- import { GridPlugin } from "../../tr-grid-util/es6/GridPlugin.js";
4
- import { FilterBuilder, stringToDateObject } from "../../tr-grid-util/es6/FilterBuilder.js";
5
- import { FilterOperators } from "../../tr-grid-util/es6/FilterOperators.js";
6
- import { ElfUtil } from "../../tr-grid-util/es6/ElfUtil.js";
1
+ import {Ext} from "../../tr-grid-util/es6/Ext.js";
2
+ import {GridPlugin} from "../../tr-grid-util/es6/GridPlugin.js";
3
+ import {FilterBuilder, stringToDateObject} from "../../tr-grid-util/es6/FilterBuilder.js";
4
+ import {FilterOperators} from "../../tr-grid-util/es6/FilterOperators.js";
5
+ import {ElfUtil} from "../../tr-grid-util/es6/ElfUtil.js";
7
6
  import { injectCss, prettifyCss, cloneObject } from "../../tr-grid-util/es6/Util.js";
8
7
 
9
8
  /** @event RowFilteringPlugin#click
@@ -112,14 +111,14 @@ The expression can take various forms:<br>
112
111
  * @param {Object} cfo
113
112
  * @return {!RowFilteringPlugin~FilterExpression}
114
113
  */
115
- var _toFilterExpression = function _toFilterExpression(cfo) {
116
- var ctx = cfo._context[0];
117
- // TODO: Handle rawDataAccessor and formattedDataAccessor (saving and loading of functions)
118
- return {
119
- field: cfo._field || "",
120
- expression: cfo._expressions[0],
121
- context: ctx != null && !ctx._autoGenerated ? ctx : null
122
- };
114
+ let _toFilterExpression = function(cfo) {
115
+ let ctx = cfo._context[0];
116
+ // TODO: Handle rawDataAccessor and formattedDataAccessor (saving and loading of functions)
117
+ return {
118
+ field: cfo._field || "",
119
+ expression: cfo._expressions[0],
120
+ context: (ctx != null && !ctx._autoGenerated) ? ctx : null
121
+ };
123
122
  };
124
123
  /** @private
125
124
  * @function
@@ -127,47 +126,53 @@ var _toFilterExpression = function _toFilterExpression(cfo) {
127
126
  * @param {*} val
128
127
  * @return {Array}
129
128
  */
130
- var _arrayConcat = function _arrayConcat(ary, val) {
131
- if (Array.isArray(val) && val.length) {
132
- if (ary) {
133
- return ary.concat(val);
134
- } else {
135
- return val;
136
- }
137
- }
138
- return ary;
129
+ let _arrayConcat = function(ary, val) {
130
+ if(Array.isArray(val) && val.length) {
131
+ if(ary) {
132
+ return ary.concat(val);
133
+ } else {
134
+ return val;
135
+ }
136
+ }
137
+ return ary;
139
138
  };
140
139
 
141
140
  /** @type {string}
142
141
  * @private
143
142
  * @const
144
143
  */
145
- var BLANKS = "(Blanks)";
144
+ const BLANKS = "(Blanks)";
146
145
 
147
146
  /** @constructor
148
147
  * @extends {GridPlugin}
149
148
  */
150
- var RowFilteringPlugin = function RowFilteringPlugin() {
151
- var t = this;
152
- t._onPreSectionRender = t._onPreSectionRender.bind(t);
153
- t._onColumnAdded = t._onColumnAdded.bind(t);
154
- t._onColumnRemoved = t._onColumnRemoved.bind(t);
155
- t._onPreLoadedDialog = t._onPreLoadedDialog.bind(t);
156
- t._onIconClicked = t._onIconClicked.bind(t);
157
- t._filterLogic = t._filterLogic.bind(t);
158
- t._updateAllColumnIcons = t._updateAllColumnIcons.bind(t);
159
- t.refresh = t.refresh.bind(t);
160
- t._requestFilterRefresh = t._requestFilterRefresh.bind(t);
161
- t._globalFilters = [];
162
- t._globalContexts = [];
163
- t._columnFilters = [];
164
- t._hosts = [];
165
- t._dvs = [];
166
- t._funcMap = {};
167
- t._nameMap = {};
149
+ let RowFilteringPlugin = function () {
150
+ let t = this;
151
+
152
+ t._onPreSectionRender = t._onPreSectionRender.bind(t);
153
+ t._onColumnAdded = t._onColumnAdded.bind(t);
154
+ t._onColumnRemoved = t._onColumnRemoved.bind(t);
155
+ t._onPreLoadedDialog = t._onPreLoadedDialog.bind(t);
156
+
157
+ t._onIconClicked = t._onIconClicked.bind(t);
158
+ t._filterLogic = t._filterLogic.bind(t);
159
+ t._updateAllColumnIcons = t._updateAllColumnIcons.bind(t);
160
+ t.refresh = t.refresh.bind(t);
161
+ t._requestFilterRefresh = t._requestFilterRefresh.bind(t);
162
+
163
+
164
+ t._globalFilters = [];
165
+ t._globalContexts = [];
166
+ t._columnFilters = [];
167
+ t._hosts = [];
168
+ t._dvs = [];
169
+
170
+ t._funcMap = {};
171
+ t._nameMap = {};
168
172
  };
169
173
  Ext.inherits(RowFilteringPlugin, GridPlugin);
170
174
 
175
+
171
176
  /** @type {!Object.<string, Function>}
172
177
  * @private
173
178
  */
@@ -257,245 +262,295 @@ RowFilteringPlugin._dialogTagName; // intentionally left undefined
257
262
  */
258
263
  RowFilteringPlugin.prototype._dvs;
259
264
 
265
+
260
266
  /** @public
261
267
  * @return {string}
262
268
  */
263
269
  RowFilteringPlugin.prototype.getName = function () {
264
- return "RowFilteringPlugin"; // Read Only
270
+ return "RowFilteringPlugin"; // Read Only
265
271
  };
266
272
  /** @public
267
273
  * @param {Object} host core grid instance
268
274
  * @param {Object=} options
269
275
  */
270
276
  RowFilteringPlugin.prototype.initialize = function (host, options) {
271
- if (this._hosts.indexOf(host) >= 0) {
272
- return;
273
- }
274
- this._hosts.push(host);
275
- if (!RowFilteringPlugin._styles) {
276
- RowFilteringPlugin._styles = prettifyCss([".hovering-filter-icon .cell:not(.active-filter):hover .floating-panel .title-filter-icon", ["display: flex;"], ".hovering-filter-icon .cell:not(.active-filter) .floating-panel .title-filter-icon", ["display: none;"], ".floating-panel", ["position:relative;"], ".floating-panel .title-filter-icon", ["color: var(--grid-title-filter-icon-color,inherit);"], ".title .floating-panel .title-filter-icon:hover", ["color: var(--grid-title-filter-icon-hover-color,inherit);"], ".always-on-filter .floating-panel .title-filter-icon", ["color: var(--grid-header-txtcolor,inherit);"], ".always-on-filter .active-filter .floating-panel .title-filter-icon", ["color: var(--grid-title-filter-icon-hover-color,inherit);"], ".hovering-filter-icon .tiny-col .cell:hover, .tr-grid .tiny-col .cell.active-filter", ["padding-left:0px;"], ".tiny-col.movable .cell .floating-panel .title-filter-icon:before", ["content: '.';", "position: absolute;", "margin-left: auto;", "margin-right: auto;", "left: 0;", "right: 0;", "top: -10px;", "font-size: 10px;", "font-family: monospace;", "color: var(--grid-title-dot-icon,inherit);", "text-align:center;"]]);
277
- }
278
- if (!host._rowFilteringStyles) {
279
- host._rowFilteringStyles = true;
280
- injectCss(RowFilteringPlugin._styles, host.getElement());
281
- }
282
- host.unloadPlugin("ColumnFilterPlugin");
283
- host.listen("preSectionRender", this._onPreSectionRender);
284
- host.listen("postDataSourceChanged", this._requestFilterRefresh); // TODO: Check if this is necessary
285
- host.listen("columnAdded", this._onColumnAdded);
286
- host.listen("columnRemoved", this._onColumnRemoved);
287
- this.config(options);
288
- // In case of lazy loading
289
- // TODO
277
+ if(this._hosts.indexOf(host) >= 0) { return; }
278
+ this._hosts.push(host);
279
+
280
+ if(!RowFilteringPlugin._styles) {
281
+ RowFilteringPlugin._styles = prettifyCss([
282
+ ".hovering-filter-icon .cell:not(.active-filter):hover .floating-panel .title-filter-icon", [
283
+ "display: flex;"
284
+ ],
285
+ ".hovering-filter-icon .cell:not(.active-filter) .floating-panel .title-filter-icon", [
286
+ "display: none;"
287
+ ],
288
+ ".floating-panel", [
289
+ "position:relative;"
290
+ ],
291
+ ".floating-panel .title-filter-icon", [
292
+ "color: var(--grid-title-filter-icon-color,inherit);"
293
+ ],
294
+ ".title .floating-panel .title-filter-icon:hover", [
295
+ "color: var(--grid-title-filter-icon-hover-color,inherit);"
296
+ ],
297
+ ".always-on-filter .floating-panel .title-filter-icon", [
298
+ "color: var(--grid-header-txtcolor,inherit);"
299
+ ],
300
+ ".always-on-filter .active-filter .floating-panel .title-filter-icon", [
301
+ "color: var(--grid-title-filter-icon-hover-color,inherit);"
302
+ ],
303
+ ".hovering-filter-icon .tiny-col .cell:hover, .tr-grid .tiny-col .cell.active-filter", [
304
+ "padding-left:0px;"
305
+ ],
306
+ ".tiny-col.movable .cell .floating-panel .title-filter-icon:before", [
307
+ "content: '.';",
308
+ "position: absolute;",
309
+ "margin-left: auto;",
310
+ "margin-right: auto;",
311
+ "left: 0;",
312
+ "right: 0;",
313
+ "top: -10px;",
314
+ "font-size: 10px;",
315
+ "font-family: monospace;",
316
+ "color: var(--grid-title-dot-icon,inherit);",
317
+ "text-align:center;"
318
+ ]
319
+ ]);
320
+ }
321
+
322
+ if(!host._rowFilteringStyles){
323
+ host._rowFilteringStyles = true;
324
+ injectCss(RowFilteringPlugin._styles, host.getElement());
325
+ }
326
+
327
+
328
+ host.unloadPlugin("ColumnFilterPlugin");
329
+ host.listen("preSectionRender", this._onPreSectionRender);
330
+ host.listen("postDataSourceChanged", this._requestFilterRefresh); // TODO: Check if this is necessary
331
+ host.listen("columnAdded", this._onColumnAdded);
332
+ host.listen("columnRemoved", this._onColumnRemoved);
333
+
334
+ this.config(options);
335
+ // In case of lazy loading
336
+ // TODO
290
337
  };
291
338
  /** @public
292
339
  * @param {Object} host core grid instance
293
340
  */
294
341
  RowFilteringPlugin.prototype.unload = function (host) {
295
- var at = this._hosts.indexOf(host);
296
- if (at < 0) {
297
- return;
298
- }
299
- this._hosts.splice(at, 1);
300
- host.unlisten("preSectionRender", this._onPreSectionRender);
301
- host.unlisten("postDataSourceChanged", this._requestFilterRefresh);
302
- host.unlisten("columnAdded", this._onColumnAdded);
303
- host.unlisten("columnRemoved", this._onColumnRemoved);
304
- if (!this._hosts.length) {
305
- if (this._uiTimerId) {
306
- clearTimeout(this._uiTimerId);
307
- this._uiTimerId = 0;
308
- }
309
- if (this._filterTimerId) {
310
- clearTimeout(this._filterTimerId);
311
- this._filterTimerId = 0;
312
- }
313
- this._hasPendingFilter = false;
314
- if (this._filterDialog) {
315
- this._filterDialog.hide(); // Remove the dialog from document
316
- this._filterDialog = null;
317
- this._dialogInitialized = false;
318
- }
319
- }
320
- this._dispose();
342
+ let at = this._hosts.indexOf(host);
343
+ if(at < 0) { return; }
344
+
345
+ this._hosts.splice(at, 1);
346
+
347
+ host.unlisten("preSectionRender", this._onPreSectionRender);
348
+ host.unlisten("postDataSourceChanged", this._requestFilterRefresh);
349
+ host.unlisten("columnAdded", this._onColumnAdded);
350
+ host.unlisten("columnRemoved", this._onColumnRemoved);
351
+
352
+ if(!this._hosts.length) {
353
+ if(this._uiTimerId) {
354
+ clearTimeout(this._uiTimerId);
355
+ this._uiTimerId = 0;
356
+ }
357
+ if(this._filterTimerId) {
358
+ clearTimeout(this._filterTimerId);
359
+ this._filterTimerId = 0;
360
+ }
361
+
362
+ this._hasPendingFilter = false;
363
+ if(this._filterDialog) {
364
+ this._filterDialog.hide(); // Remove the dialog from document
365
+ this._filterDialog = null;
366
+ this._dialogInitialized = false;
367
+ }
368
+ }
369
+
370
+ this._dispose();
321
371
  };
322
372
  /**
323
373
  * @protected
324
374
  * @ignore
325
375
  */
326
- RowFilteringPlugin.prototype._afterInit = function () {
327
- if (!this._filterDialog) {
328
- this._filterDialog = RowFilteringPlugin._createDialog();
329
- this._dialogInitialized = false;
330
- if (this._filterDialog) {
331
- this._filterDialog.style.display = "none";
332
- document.body.appendChild(this._filterDialog);
333
- setTimeout(this._onPreLoadedDialog, 10);
334
- }
335
- }
336
- this._applyPendingFilter();
376
+ RowFilteringPlugin.prototype._afterInit = function() {
377
+ if(!this._filterDialog) {
378
+ this._filterDialog = RowFilteringPlugin._createDialog();
379
+ this._dialogInitialized = false;
380
+ if(this._filterDialog) {
381
+ this._filterDialog.style.display = "none";
382
+ document.body.appendChild(this._filterDialog);
383
+ setTimeout(this._onPreLoadedDialog, 10);
384
+ }
385
+ }
386
+ this._applyPendingFilter();
337
387
  };
338
388
 
339
389
  /** @private
340
390
  */
341
- RowFilteringPlugin.prototype._applyPendingFilter = function () {
342
- if (!this._initializedGrid) {
343
- return;
344
- }
345
- if (!this._hasPendingFilter) {
346
- return;
347
- }
348
- this._hasPendingFilter = false;
349
- var colCount = this.getColumnCount();
350
- for (var c = 0; c < colCount; ++c) {
351
- var colSettings = this._getUserColumnSettings(c);
352
- if (colSettings.expression) {
353
- this.addColumnFilter(c, colSettings.expression, colSettings.filterState);
354
- } else {
355
- this._removeColumnFilters(c);
356
- }
357
- }
391
+ RowFilteringPlugin.prototype._applyPendingFilter = function() {
392
+ if(!this._initializedGrid) {
393
+ return;
394
+ }
395
+ if(!this._hasPendingFilter) {
396
+ return;
397
+ }
398
+
399
+ this._hasPendingFilter = false;
400
+ let colCount = this.getColumnCount();
401
+ for(let c = 0; c < colCount; ++c) {
402
+ let colSettings = this._getUserColumnSettings(c);
403
+ if(colSettings.expression) {
404
+ this.addColumnFilter(c, colSettings.expression, colSettings.filterState);
405
+ } else {
406
+ this._removeColumnFilters(c);
407
+ }
408
+ }
358
409
  };
359
410
  /** @private
360
411
  */
361
- RowFilteringPlugin.prototype._onPreLoadedDialog = function () {
362
- if (this._filterDialog) {
363
- this._filterDialog.style.display = "";
364
- var pn = this._filterDialog.parentNode;
365
- if (pn) {
366
- pn.removeChild(this._filterDialog);
367
- }
368
- }
412
+ RowFilteringPlugin.prototype._onPreLoadedDialog = function() {
413
+ if(this._filterDialog) {
414
+ this._filterDialog.style.display = "";
415
+ let pn = this._filterDialog.parentNode;
416
+ if(pn) {
417
+ pn.removeChild(this._filterDialog);
418
+ }
419
+ }
369
420
  };
370
421
 
371
422
  /** @public
372
423
  * @param {Object=} options
373
424
  */
374
425
  RowFilteringPlugin.prototype.config = function (options) {
375
- if (!options) {
376
- return;
377
- }
378
- var rowFiltering = options["rowFiltering"];
379
- if (rowFiltering) {
380
- if (rowFiltering["disabledUI"] || rowFiltering["uiDisabled"]) {
381
- this._iconActivation = "none";
382
- }
383
- if (rowFiltering["emptySegmentFiltering"] != null) {
384
- // TODO: there is a chance that there is no DataView during the configuration
385
- this.enableEmptySegmentFiltering(rowFiltering["emptySegmentFiltering"] ? true : false);
386
- }
387
- if (rowFiltering["separatorFiltering"] != null) {
388
- // TODO: there is a chance that there is no DataView during the configuration
389
- this.enableSeparatorFiltering(rowFiltering["separatorFiltering"] ? true : false);
390
- }
391
- if (rowFiltering["iconActivation"]) {
392
- this._iconActivation = rowFiltering["iconActivation"];
393
- for (var index = 0; index < this._hosts.length; index++) {
394
- if (this._iconActivation === "onHover") {
395
- this._hosts[index].enableClass("hovering-filter-icon", true);
396
- } else {
397
- this._hosts[index].enableClass("hovering-filter-icon", false);
398
- }
399
- if (this._iconActivation === "always") {
400
- this._hosts[index].enableClass("always-on-filter", true);
401
- } else {
402
- this._hosts[index].enableClass("always-on-filter", false);
403
- }
404
- }
405
- }
406
- if (rowFiltering["dialogOptions"]) {
407
- this._dialogOptions = rowFiltering["dialogOptions"];
408
- }
409
- if (rowFiltering["clicked"]) {
410
- rowFiltering["click"] = rowFiltering["clicked"];
411
- }
412
- this.addListener(rowFiltering, "click");
413
- this.addListener(rowFiltering, "beforeDialogOpened");
414
- this.addListener(rowFiltering, "dialogCommitted");
415
- this.addListener(rowFiltering, "iconCreated");
416
- this.addListener(rowFiltering, "filterChanged");
417
- this.addListener(rowFiltering, "refreshed");
418
- }
419
- var columns = options["columns"];
420
- if (!columns) {
421
- return;
422
- }
423
-
424
- // let host = this._hosts[0];
425
- var len = columns.length;
426
- for (var i = 0; i < len; ++i) {
427
- var column = columns[i];
428
- this._setColumnOptions(i, column);
429
- }
430
- this._applyPendingFilter();
426
+ if(!options) { return; }
427
+
428
+ let rowFiltering = options["rowFiltering"];
429
+ if(rowFiltering) {
430
+ if(rowFiltering["disabledUI"] || rowFiltering["uiDisabled"]) {
431
+ this._iconActivation = "none";
432
+ }
433
+ if(rowFiltering["emptySegmentFiltering"] != null) {
434
+ // TODO: there is a chance that there is no DataView during the configuration
435
+ this.enableEmptySegmentFiltering(rowFiltering["emptySegmentFiltering"] ? true : false);
436
+ }
437
+ if(rowFiltering["separatorFiltering"] != null) {
438
+ // TODO: there is a chance that there is no DataView during the configuration
439
+ this.enableSeparatorFiltering(rowFiltering["separatorFiltering"] ? true : false);
440
+ }
441
+ if(rowFiltering["iconActivation"]){
442
+ this._iconActivation = rowFiltering["iconActivation"];
443
+
444
+ for(let index = 0; index < this._hosts.length; index++){
445
+ if(this._iconActivation === "onHover"){
446
+ this._hosts[index].enableClass("hovering-filter-icon", true);
447
+ }else{
448
+ this._hosts[index].enableClass("hovering-filter-icon", false);
449
+ }
450
+ if(this._iconActivation === "always"){
451
+ this._hosts[index].enableClass("always-on-filter", true);
452
+ } else {
453
+ this._hosts[index].enableClass("always-on-filter", false);
454
+ }
455
+ }
456
+ }
457
+ if(rowFiltering["dialogOptions"]){
458
+ this._dialogOptions = rowFiltering["dialogOptions"];
459
+ }
460
+ if(rowFiltering["clicked"]) {
461
+ rowFiltering["click"] = rowFiltering["clicked"];
462
+ }
463
+
464
+ this.addListener(rowFiltering, "click");
465
+ this.addListener(rowFiltering, "beforeDialogOpened");
466
+ this.addListener(rowFiltering, "dialogCommitted");
467
+ this.addListener(rowFiltering, "iconCreated");
468
+ this.addListener(rowFiltering, "filterChanged");
469
+ this.addListener(rowFiltering, "refreshed");
470
+ }
471
+
472
+ let columns = options["columns"];
473
+ if(!columns) { return; }
474
+
475
+ // let host = this._hosts[0];
476
+ let len = columns.length;
477
+ for(let i = 0; i < len; ++i) {
478
+ let column = columns[i];
479
+ this._setColumnOptions(i, column);
480
+ }
481
+ this._applyPendingFilter();
431
482
  };
432
483
  /** @public
433
484
  * @param {Object=} gridOptions
434
485
  * @return {!Object}
435
486
  */
436
487
  RowFilteringPlugin.prototype.getConfigObject = function (gridOptions) {
437
- var obj = gridOptions || {};
438
- var columns = obj.columns;
439
- if (!columns) {
440
- columns = obj.columns = [];
441
- }
442
- var len = this.getColumnCount();
443
- for (var i = 0; i < len; ++i) {
444
- var column = columns[i];
445
- if (!column) {
446
- column = columns[i] = {};
447
- }
448
- var colSettings = this._getUserColumnSettings(i);
449
- var exp = colSettings.expression;
450
- if (exp && typeof exp !== "function") {
451
- // TODO: Accept function type
452
- if (_typeof(exp) === "object" && !Array.isArray(exp)) {
453
- var expClone = cloneObject(exp);
454
- if (expClone[""] || expClone["null"] || expClone["undefined"] || expClone["NaN"]) {
455
- delete expClone[""];
456
- delete expClone["null"];
457
- delete expClone["undefined"];
458
- delete expClone["NaN"];
459
- expClone[BLANKS] = true;
460
- column.filter = expClone; // This could be only object
461
- } else {
462
- column.filter = exp;
463
- }
464
- } else {
465
- column.filter = exp; // This could be string or array
466
- }
467
- }
468
-
469
- var ctx = colSettings.filterState;
470
- if (ctx != null) {
471
- if (_typeof(ctx) !== "object" || !ctx._autoGenerated) {
472
- column.filterState = ctx;
473
- }
474
- }
475
- var filterIcon = colSettings.filterIcon;
476
- if (!filterIcon) {
477
- column.filterIcon = false;
478
- }
479
- }
480
- var extOptions = obj.rowFiltering;
481
- var dirty = false;
482
- if (!extOptions) {
483
- extOptions = {};
484
- }
485
- if (this._iconActivation !== "onActiveFilter") {
486
- extOptions.iconActivation = this._iconActivation;
487
- dirty = true;
488
- }
489
- if (this._dialogOptions) {
490
- extOptions.dialogOptions = this._dialogOptions; // TODO: dialogOptions should not contain any function
491
- dirty = true;
492
- }
493
- // TODO: get emptySegmentFiltering setting from DataView
494
- // TODO: get separatorFiltering setting from DataView
495
- if (dirty) {
496
- obj.rowFiltering = extOptions;
497
- }
498
- return obj;
488
+ let obj = gridOptions || {};
489
+
490
+ let columns = obj.columns;
491
+ if(!columns) {
492
+ columns = obj.columns = [];
493
+ }
494
+
495
+ let len = this.getColumnCount();
496
+ for(let i = 0; i < len; ++i) {
497
+ let column = columns[i];
498
+ if(!column) {
499
+ column = columns[i] = {};
500
+ }
501
+
502
+ let colSettings = this._getUserColumnSettings(i);
503
+ let exp = colSettings.expression;
504
+ if(exp && typeof exp !== "function") { // TODO: Accept function type
505
+ if(typeof exp === "object" && !Array.isArray(exp)) {
506
+ let expClone = cloneObject(exp);
507
+ if(expClone[""] || expClone["null"] || expClone["undefined"] || expClone["NaN"]) {
508
+ delete expClone[""];
509
+ delete expClone["null"];
510
+ delete expClone["undefined"];
511
+ delete expClone["NaN"];
512
+ expClone[BLANKS] = true;
513
+ column.filter = expClone; // This could be only object
514
+ } else {
515
+ column.filter = exp;
516
+ }
517
+ } else {
518
+ column.filter = exp; // This could be string or array
519
+ }
520
+ }
521
+ let ctx = colSettings.filterState;
522
+ if(ctx != null) {
523
+ if(typeof ctx !== "object" || !ctx._autoGenerated) {
524
+ column.filterState = ctx;
525
+ }
526
+ }
527
+
528
+ let filterIcon = colSettings.filterIcon;
529
+ if(!filterIcon) {
530
+ column.filterIcon = false;
531
+ }
532
+ }
533
+
534
+ let extOptions = obj.rowFiltering;
535
+ let dirty = false;
536
+ if(!extOptions) {
537
+ extOptions = {};
538
+ }
539
+ if(this._iconActivation !== "onActiveFilter") {
540
+ extOptions.iconActivation = this._iconActivation;
541
+ dirty = true;
542
+ }
543
+ if(this._dialogOptions) {
544
+ extOptions.dialogOptions = this._dialogOptions; // TODO: dialogOptions should not contain any function
545
+ dirty = true;
546
+ }
547
+ // TODO: get emptySegmentFiltering setting from DataView
548
+ // TODO: get separatorFiltering setting from DataView
549
+ if(dirty) {
550
+ obj.rowFiltering = extOptions;
551
+ }
552
+
553
+ return obj;
499
554
  };
500
555
 
501
556
  /** All filter logics in DataView will be temporarily removed until re-enabling. This is useful when trying to insert an item at the specified index. After re-enabling, both logics and icons will be restored.
@@ -503,33 +558,32 @@ RowFilteringPlugin.prototype.getConfigObject = function (gridOptions) {
503
558
  * @param {boolean=} opt_disabled
504
559
  * @param {string=} opt_id For handling nested called
505
560
  */
506
- RowFilteringPlugin.prototype.disable = function (opt_disabled, opt_id) {
507
- var disabled = opt_disabled !== false;
508
- if (!this._disablingIds) {
509
- this._disablingIds = {};
510
- }
511
- if (!opt_id) {
512
- opt_id = "_";
513
- }
514
- this._disablingIds[opt_id] = disabled;
515
- disabled = false;
516
- for (var key in this._disablingIds) {
517
- // Find cumulative state
518
- if (this._disablingIds[key]) {
519
- disabled = true;
520
- break;
521
- }
522
- }
523
- if (this._disabled !== disabled) {
524
- this._disabled = disabled;
525
- if (disabled) {
526
- this.refresh(); // Take an effect immediately
527
- this._updateAllColumnIcons();
528
- } else {
529
- this._requestFilterRefresh(); // Take an effect later
530
- this._setTimerForUpdatingIcons();
531
- }
532
- }
561
+ RowFilteringPlugin.prototype.disable = function(opt_disabled, opt_id) {
562
+ let disabled = opt_disabled !== false;
563
+ if(!this._disablingIds) {
564
+ this._disablingIds = {};
565
+ }
566
+ if(!opt_id) { opt_id = "_"; }
567
+ this._disablingIds[opt_id] = disabled;
568
+
569
+ disabled = false;
570
+ for(let key in this._disablingIds) { // Find cumulative state
571
+ if(this._disablingIds[key]) {
572
+ disabled = true;
573
+ break;
574
+ }
575
+ }
576
+
577
+ if(this._disabled !== disabled) {
578
+ this._disabled = disabled;
579
+ if(disabled) {
580
+ this.refresh(); // Take an effect immediately
581
+ this._updateAllColumnIcons();
582
+ } else {
583
+ this._requestFilterRefresh(); // Take an effect later
584
+ this._setTimerForUpdatingIcons();
585
+ }
586
+ }
533
587
  };
534
588
 
535
589
  /** Add a global filter that is not related to any column. No filter icon is created in this way
@@ -540,30 +594,32 @@ RowFilteringPlugin.prototype.disable = function (opt_disabled, opt_id) {
540
594
  * @return {string} If success, function name is returned, otherwise empty string
541
595
  * @fires RowFilteringPlugin#filterChanged
542
596
  */
543
- RowFilteringPlugin.prototype.addFilter = function (exp, funcName, ctx) {
544
- var func = this._parseFilter(exp, -1);
545
- if (!func) {
546
- return "";
547
- }
548
- if (!funcName) {
549
- funcName = "_" + this._filterId++;
550
- }
551
- if (this._nameMap[funcName] || this._globalFilters.indexOf(func) >= 0) {
552
- return ""; // Function is already exists
553
- }
554
-
555
- ctx = ctx != null ? ctx : null;
556
- this._nameMap[funcName] = func;
557
- this._globalFilters.push(func);
558
- this._globalContexts.push(ctx);
559
- this._dispatch("filterChanged", {
560
- "filterType": "global",
561
- "changeType": "add",
562
- "colIndex": -1,
563
- "field": null
564
- });
565
- this._requestFilterRefresh();
566
- return funcName;
597
+ RowFilteringPlugin.prototype.addFilter = function(exp, funcName, ctx) {
598
+ let func = this._parseFilter(exp, -1);
599
+ if(!func) { return ""; }
600
+
601
+ if(!funcName) {
602
+ funcName = "_" + this._filterId++;
603
+ }
604
+
605
+ if(this._nameMap[funcName] || this._globalFilters.indexOf(func) >= 0) {
606
+ return ""; // Function is already exists
607
+ }
608
+
609
+ ctx = ctx != null ? ctx : null;
610
+ this._nameMap[funcName] = func;
611
+ this._globalFilters.push(func);
612
+ this._globalContexts.push(ctx);
613
+
614
+ this._dispatch("filterChanged", {
615
+ "filterType": "global",
616
+ "changeType": "add",
617
+ "colIndex": -1,
618
+ "field": null
619
+ });
620
+
621
+ this._requestFilterRefresh();
622
+ return funcName;
567
623
  };
568
624
  /** Add a global filter that is not related to any column. No filter icon is created in this way
569
625
  * @public
@@ -572,8 +628,8 @@ RowFilteringPlugin.prototype.addFilter = function (exp, funcName, ctx) {
572
628
  * @return {string} If success, function name is returned, otherwise empty string
573
629
  * @fires RowFilteringPlugin#filterChanged
574
630
  */
575
- RowFilteringPlugin.prototype.addGridFilter = function (exp, ctx) {
576
- return this.addFilter(exp, null, ctx);
631
+ RowFilteringPlugin.prototype.addGridFilter = function(exp, ctx) {
632
+ return this.addFilter(exp, null, ctx);
577
633
  };
578
634
  /** @private
579
635
  * @param {RowFilteringPlugin~Expression} exp
@@ -581,40 +637,40 @@ RowFilteringPlugin.prototype.addGridFilter = function (exp, ctx) {
581
637
  * @param {*=} ctx
582
638
  * @return {Function}
583
639
  */
584
- RowFilteringPlugin.prototype._parseFilter = function (exp, colIndex, ctx) {
585
- if (!exp) {
586
- return null;
587
- }
588
- if (typeof exp === "function") {
589
- return exp;
590
- }
591
- var filterBuilder = RowFilteringPlugin._getFilterBuilder();
592
- var validIdx = colIndex || colIndex === 0;
593
- var field = validIdx ? this._getField(colIndex) : "";
594
- var formatter = validIdx ? this._getFormatter(colIndex) : null;
595
- var func = null;
596
- if (typeof exp === "string") {
597
- // Free text does not need data accessors
598
- func = this._funcMap[exp];
599
- if (func == null) {
600
- func = this._funcMap[exp] = filterBuilder.parse(exp, field, formatter, field);
601
- }
602
- } else {
603
- var rawDataAccessor = null;
604
- var formattedDataAccessor = null;
605
- if (ctx) {
606
- rawDataAccessor = ctx.rawDataAccessor || null;
607
- formattedDataAccessor = ctx.formattedDataAccessor || null;
608
- }
609
- if (!Array.isArray(exp)) {
610
- if (exp[BLANKS] || ctx && ctx.blankValues) {
611
- exp[""] = exp["null"] = exp["undefined"] = exp["NaN"] = true;
612
- delete exp[BLANKS];
613
- }
614
- }
615
- func = filterBuilder.parse(exp, field, formatter, field, rawDataAccessor, formattedDataAccessor);
616
- }
617
- return func;
640
+ RowFilteringPlugin.prototype._parseFilter = function(exp, colIndex, ctx) {
641
+ if(!exp) {
642
+ return null;
643
+ }
644
+ if(typeof exp === "function") {
645
+ return exp;
646
+ }
647
+ let filterBuilder = RowFilteringPlugin._getFilterBuilder();
648
+ let validIdx = (colIndex || colIndex === 0);
649
+ let field = validIdx ? this._getField(colIndex) : "";
650
+ let formatter = validIdx ? this._getFormatter(colIndex) : null;
651
+
652
+ let func = null;
653
+ if(typeof exp === "string") { // Free text does not need data accessors
654
+ func = this._funcMap[exp];
655
+ if(func == null) {
656
+ func = this._funcMap[exp] = filterBuilder.parse(exp, field, formatter, field);
657
+ }
658
+ } else {
659
+ let rawDataAccessor = null;
660
+ let formattedDataAccessor = null;
661
+ if(ctx) {
662
+ rawDataAccessor = ctx.rawDataAccessor || null;
663
+ formattedDataAccessor = ctx.formattedDataAccessor || null;
664
+ }
665
+ if(!Array.isArray(exp)) {
666
+ if(exp[BLANKS] || (ctx && ctx.blankValues)) {
667
+ exp[""] = exp["null"] = exp["undefined"] = exp["NaN"] = true;
668
+ delete exp[BLANKS];
669
+ }
670
+ }
671
+ func = filterBuilder.parse(exp, field, formatter, field, rawDataAccessor, formattedDataAccessor);
672
+ }
673
+ return func;
618
674
  };
619
675
  /** If you want the column to always have one single filter, please use {@link RowFilteringPlugin#setColumnFilter} instead. This method allow a single column to have multiple filters.
620
676
  * @public
@@ -624,60 +680,65 @@ RowFilteringPlugin.prototype._parseFilter = function (exp, colIndex, ctx) {
624
680
  * @return {boolean} True if success
625
681
  * @fires RowFilteringPlugin#filterChanged
626
682
  */
627
- RowFilteringPlugin.prototype.addColumnFilter = function (colIndex, exp, ctx) {
628
- if (colIndex < 0 || colIndex >= this.getColumnCount()) {
629
- return false;
630
- }
631
- var cfo = this._getColumnFilterOption(colIndex);
632
- if (cfo) {
633
- if (cfo._expressions[0] === exp) {
634
- return false; // The same expression is getting added on the same column twice
635
- }
636
- }
637
-
638
- var func = null;
639
- if (typeof exp === "function") {
640
- func = /** @type{Function} */exp;
641
- if (ctx && typeof ctx === "string") {
642
- exp = ctx;
643
- }
644
- } else {
645
- func = this._parseFilter(exp, colIndex, ctx);
646
- }
647
- if (!func) {
648
- return false;
649
- }
650
- var colSettings = this._getUserColumnSettings(colIndex);
651
- colSettings.expression = exp; // WARNING: Only the last expression are saved (previous one is overwritten)
652
- colSettings.filterState = ctx;
653
- if (ctx == null) {
654
- ctx = {
655
- "_autoGenerated": true
656
- };
657
- }
658
- var field = this._getField(colIndex);
659
- if (ctx && _typeof(ctx) === "object") {
660
- ctx["field"] = field;
661
- }
662
- cfo = this._initColumnFilterOption(colIndex);
663
- cfo._field = field; // TODO: Handle fieldDataType
664
- cfo._filters.push(func);
665
- cfo._expressions.push(exp);
666
- cfo._context.push(ctx);
667
- cfo._rawDataAccessor = ctx.rawDataAccessor || null;
668
- cfo._formattedDataAccessor = ctx.formattedDataAccessor || null;
669
- this._columnFilters.push(cfo);
670
- this._dispatch("filterChanged", {
671
- "filterType": "column",
672
- "changeType": "add",
673
- "colIndex": colIndex,
674
- "field": field
675
- });
676
-
677
- // UI
678
- this._requestFilterRefresh();
679
- this._updateColumnIcon(colIndex);
680
- return true;
683
+ RowFilteringPlugin.prototype.addColumnFilter = function(colIndex, exp, ctx) {
684
+ if(colIndex < 0 || colIndex >= this.getColumnCount()) {
685
+ return false;
686
+ }
687
+
688
+ let cfo = this._getColumnFilterOption(colIndex);
689
+ if(cfo) {
690
+ if(cfo._expressions[0] === exp) {
691
+ return false; // The same expression is getting added on the same column twice
692
+ }
693
+ }
694
+
695
+ let func = null;
696
+ if(typeof exp === "function") {
697
+ func = /** @type{Function} */(exp);
698
+ if(ctx && typeof ctx === "string") {
699
+ exp = ctx;
700
+ }
701
+ } else {
702
+ func = this._parseFilter(exp, colIndex, ctx);
703
+ }
704
+
705
+ if(!func) {
706
+ return false;
707
+ }
708
+
709
+ let colSettings = this._getUserColumnSettings(colIndex);
710
+ colSettings.expression = exp; // WARNING: Only the last expression are saved (previous one is overwritten)
711
+ colSettings.filterState = ctx;
712
+
713
+ if(ctx == null) {
714
+ ctx = {"_autoGenerated": true};
715
+ }
716
+
717
+ let field = this._getField(colIndex);
718
+ if(ctx && typeof ctx === "object") {
719
+ ctx["field"] = field;
720
+ }
721
+
722
+ cfo = this._initColumnFilterOption(colIndex);
723
+ cfo._field = field; // TODO: Handle fieldDataType
724
+ cfo._filters.push(func);
725
+ cfo._expressions.push(exp);
726
+ cfo._context.push(ctx);
727
+ cfo._rawDataAccessor = ctx.rawDataAccessor || null;
728
+ cfo._formattedDataAccessor = ctx.formattedDataAccessor || null;
729
+ this._columnFilters.push(cfo);
730
+
731
+ this._dispatch("filterChanged", {
732
+ "filterType": "column",
733
+ "changeType": "add",
734
+ "colIndex": colIndex,
735
+ "field": field
736
+ });
737
+
738
+ // UI
739
+ this._requestFilterRefresh();
740
+ this._updateColumnIcon(colIndex);
741
+ return true;
681
742
  };
682
743
  /** This method guarantees that the column can have at most one filter at the time. It performs {@link RowFilteringPlugin#removeColumnFilters} before {@link RowFilteringPlugin#addColumnFilter}
683
744
  * @public
@@ -699,25 +760,27 @@ RowFilteringPlugin.prototype.addColumnFilter = function (colIndex, exp, ctx) {
699
760
  * }
700
761
  * );
701
762
  */
702
- RowFilteringPlugin.prototype.setColumnFilter = function (colIndex, exp, ctx) {
703
- var curExp = this.getColumnFilterExpression(colIndex);
704
- if (curExp === exp) {
705
- return false;
706
- }
707
- var removed = this._removeColumnFilters(colIndex);
708
- var added = this.addColumnFilter(colIndex, exp, ctx);
709
- if (!added && removed) {
710
- this._updateColumnIcon(colIndex);
711
- }
712
- return removed || added;
763
+ RowFilteringPlugin.prototype.setColumnFilter = function(colIndex, exp, ctx) {
764
+ let curExp = this.getColumnFilterExpression(colIndex);
765
+ if(curExp === exp) {
766
+ return false;
767
+ }
768
+
769
+ let removed = this._removeColumnFilters(colIndex);
770
+
771
+ let added = this.addColumnFilter(colIndex, exp, ctx);
772
+ if(!added && removed) {
773
+ this._updateColumnIcon(colIndex);
774
+ }
775
+ return removed || added;
713
776
  };
714
777
  /** @public
715
778
  * @param {number} colIndex
716
779
  * @return {RowFilteringPlugin~Expression}
717
780
  */
718
- RowFilteringPlugin.prototype.getColumnFilterExpression = function (colIndex) {
719
- var colSettings = this._getUserColumnSettings(colIndex);
720
- return colSettings.expression || null;
781
+ RowFilteringPlugin.prototype.getColumnFilterExpression = function(colIndex) {
782
+ let colSettings = this._getUserColumnSettings(colIndex);
783
+ return colSettings.expression || null;
721
784
  };
722
785
  /** Set data to colData["rowFiltering"]
723
786
  * @private
@@ -738,95 +801,96 @@ RowFilteringPlugin.prototype.getColumnFilterExpression = function (colIndex) {
738
801
  * }
739
802
  * };
740
803
  */
741
- RowFilteringPlugin.prototype._setColumnOptions = function (colIndex, userObj) {
742
- var colSettings = this._getUserColumnSettings(colIndex);
743
- var filterIcon = userObj["filterIcon"];
744
-
745
- // TODO: This should not be set here, should retreive data type from Composite/Realtime Grid
746
- var fieldDataType = userObj["fieldDataType"] || userObj["dataType"];
747
- if (fieldDataType) {
748
- colSettings.fieldDataType = fieldDataType; // TODO: This should not be set here, should retreive data type from Composite/Realtime Grid
749
- }
750
-
751
- if (filterIcon != null) {
752
- colSettings.filterIcon = filterIcon;
753
- }
754
- var exp = userObj["filter"];
755
- if (exp != null) {
756
- colSettings.expression = exp;
757
- colSettings.filterState = null;
758
- this._hasPendingFilter = true;
759
- }
760
- var filterState = userObj["filterState"];
761
- if (filterState != null) {
762
- colSettings.filterState = filterState;
763
- }
764
- var iconActivation = filterIcon == false ? "none" : this._iconActivation;
765
- if (iconActivation == "always" || iconActivation == "onHover") {
766
- this._updateColumnIcon(colIndex);
767
- }
768
- return exp != null;
804
+ RowFilteringPlugin.prototype._setColumnOptions = function(colIndex, userObj) {
805
+ let colSettings = this._getUserColumnSettings(colIndex);
806
+ let filterIcon = userObj["filterIcon"];
807
+
808
+ // TODO: This should not be set here, should retreive data type from Composite/Realtime Grid
809
+ let fieldDataType = userObj["fieldDataType"] || userObj["dataType"];
810
+ if(fieldDataType) {
811
+ colSettings.fieldDataType = fieldDataType; // TODO: This should not be set here, should retreive data type from Composite/Realtime Grid
812
+ }
813
+ if(filterIcon != null) {
814
+ colSettings.filterIcon = filterIcon;
815
+ }
816
+ let exp = userObj["filter"];
817
+ if(exp != null) {
818
+ colSettings.expression = exp;
819
+ colSettings.filterState = null;
820
+ this._hasPendingFilter = true;
821
+ }
822
+ let filterState = userObj["filterState"];
823
+ if(filterState != null) {
824
+ colSettings.filterState = filterState;
825
+ }
826
+
827
+ let iconActivation = filterIcon == false ? "none" : this._iconActivation;
828
+ if(iconActivation == "always" || iconActivation == "onHover") {
829
+ this._updateColumnIcon(colIndex);
830
+ }
831
+
832
+ return (exp != null);
769
833
  };
770
834
  /** @private
771
835
  * @param {number} colIndex
772
836
  * @return {!Object} colData["rowFiltering"]
773
837
  */
774
- RowFilteringPlugin.prototype._getUserColumnSettings = function (colIndex) {
775
- var colData = this._newColumnData(colIndex);
776
- var colSettings = colData["rowFiltering"];
777
- if (!colSettings) {
778
- colSettings = colData["rowFiltering"] = {};
779
- }
780
- return colSettings;
838
+ RowFilteringPlugin.prototype._getUserColumnSettings = function(colIndex) {
839
+ let colData = this._newColumnData(colIndex);
840
+ let colSettings = colData["rowFiltering"];
841
+ if(!colSettings) {
842
+ colSettings = colData["rowFiltering"] = {};
843
+ }
844
+ return colSettings;
781
845
  };
782
846
  /** @private
783
847
  * @param {number} colIndex
784
848
  * @return {Object} colData["rowFiltering"]["filterOption"]
785
849
  */
786
- RowFilteringPlugin.prototype._getColumnFilterOption = function (colIndex) {
787
- var colSettings = this._getUserColumnSettings(colIndex);
788
- if (colSettings) {
789
- return colSettings["filterOption"] || null;
790
- } else {
791
- return null;
792
- }
850
+ RowFilteringPlugin.prototype._getColumnFilterOption = function(colIndex) {
851
+ let colSettings = this._getUserColumnSettings(colIndex);
852
+ if(colSettings) {
853
+ return colSettings["filterOption"] || null;
854
+ } else {
855
+ return null;
856
+ }
793
857
  };
794
858
  /** Remove colData["rowFiltering"]["filterOption"]
795
859
  * @private
796
860
  * @param {number} colIndex
797
861
  */
798
- RowFilteringPlugin.prototype._removeActiveFilterStates = function (colIndex) {
799
- var colSettings = this._getUserColumnSettings(colIndex);
800
- colSettings.expression = null;
801
- colSettings.filterState = null;
802
- var cfo = colSettings["filterOption"];
803
- if (cfo) {
804
- colSettings["filterOption"] = null;
805
- if (cfo._filters.length) {
806
- this._dispatch("filterChanged", {
807
- "filterType": "column",
808
- "changeType": "remove",
809
- "colIndex": colIndex,
810
- "field": this._getField(colIndex)
811
- });
812
- }
813
- }
862
+ RowFilteringPlugin.prototype._removeActiveFilterStates = function(colIndex) {
863
+ let colSettings = this._getUserColumnSettings(colIndex);
864
+ colSettings.expression = null;
865
+ colSettings.filterState = null;
866
+ let cfo = colSettings["filterOption"];
867
+ if(cfo) {
868
+ colSettings["filterOption"] = null;
869
+ if(cfo._filters.length) {
870
+ this._dispatch("filterChanged", {
871
+ "filterType": "column",
872
+ "changeType": "remove",
873
+ "colIndex": colIndex,
874
+ "field": this._getField(colIndex)
875
+ });
876
+ }
877
+ }
814
878
  };
815
879
  /** @private
816
880
  * @param {number} colIndex
817
881
  * @return {!Object}
818
882
  */
819
- RowFilteringPlugin.prototype._initColumnFilterOption = function (colIndex) {
820
- var cfo = this._getColumnFilterOption(colIndex);
821
- if (!cfo) {
822
- cfo = {};
823
- cfo._filters = [];
824
- cfo._expressions = [];
825
- cfo._context = [];
826
- var colSettings = this._getUserColumnSettings(colIndex);
827
- colSettings["filterOption"] = cfo;
828
- }
829
- return cfo;
883
+ RowFilteringPlugin.prototype._initColumnFilterOption = function(colIndex) {
884
+ let cfo = this._getColumnFilterOption(colIndex);
885
+ if(!cfo) {
886
+ cfo = {};
887
+ cfo._filters = [];
888
+ cfo._expressions = [];
889
+ cfo._context = [];
890
+ let colSettings = this._getUserColumnSettings(colIndex);
891
+ colSettings["filterOption"] = cfo;
892
+ }
893
+ return cfo;
830
894
  };
831
895
 
832
896
  /** Remove the registered global filter. The column filter cannot be removed
@@ -834,33 +898,32 @@ RowFilteringPlugin.prototype._initColumnFilterOption = function (colIndex) {
834
898
  * @param {Function|string} funcRef Function object or the function name can be used to remove
835
899
  * @return {boolean} True if success
836
900
  */
837
- RowFilteringPlugin.prototype.removeFilter = function (funcRef) {
838
- var func = null;
839
- var funcName = "";
840
- var funcIndex = -1;
841
- if (typeof funcRef === "string") {
842
- funcName = /** @type{string} */funcRef;
843
- func = this._nameMap[funcRef];
844
- funcIndex = this._globalFilters.indexOf(func);
845
- } else {
846
- func = /** @type{Function} */funcRef;
847
- funcIndex = this._globalFilters.indexOf(func);
848
- if (funcIndex >= 0) {
849
- for (var key in this._nameMap) {
850
- if (this._nameMap[key] === func) {
851
- funcName = key;
852
- }
853
- }
854
- }
855
- }
856
- if (funcIndex < 0) {
857
- return false;
858
- }
859
- delete this._nameMap[funcName];
860
- this._globalFilters.splice(funcIndex, 1);
861
- this._globalContexts.splice(funcIndex, 1);
862
- this._requestFilterRefresh();
863
- return true;
901
+ RowFilteringPlugin.prototype.removeFilter = function(funcRef) {
902
+ let func = null;
903
+ let funcName = "";
904
+ let funcIndex = -1;
905
+ if(typeof funcRef === "string") {
906
+ funcName = /** @type{string} */(funcRef);
907
+ func = this._nameMap[funcRef];
908
+ funcIndex = this._globalFilters.indexOf(func);
909
+ } else {
910
+ func = /** @type{Function} */(funcRef);
911
+ funcIndex = this._globalFilters.indexOf(func);
912
+ if(funcIndex >= 0) {
913
+ for(let key in this._nameMap) {
914
+ if(this._nameMap[key] === func) {
915
+ funcName = key;
916
+ }
917
+ }
918
+ }
919
+ }
920
+ if(funcIndex < 0) { return false; }
921
+
922
+ delete this._nameMap[funcName];
923
+ this._globalFilters.splice(funcIndex, 1);
924
+ this._globalContexts.splice(funcIndex, 1);
925
+ this._requestFilterRefresh();
926
+ return true;
864
927
  };
865
928
  /** Remove all filters in from the specified column
866
929
  * @public
@@ -868,35 +931,35 @@ RowFilteringPlugin.prototype.removeFilter = function (funcRef) {
868
931
  * @return {boolean} True if there is any change
869
932
  * @fires RowFilteringPlugin#filterChanged
870
933
  */
871
- RowFilteringPlugin.prototype.removeColumnFilters = function (colIndex) {
872
- if (colIndex == null) {
873
- // Prevent user mistake
874
- return this.removeAllColumnFilters();
875
- }
876
- var dirty = this._removeColumnFilters(colIndex);
877
- if (dirty) {
878
- this._updateColumnIcon(colIndex);
879
- }
880
- return dirty;
934
+ RowFilteringPlugin.prototype.removeColumnFilters = function(colIndex) {
935
+ if(colIndex == null) { // Prevent user mistake
936
+ return this.removeAllColumnFilters();
937
+ }
938
+
939
+ let dirty = this._removeColumnFilters(colIndex);
940
+ if(dirty) {
941
+ this._updateColumnIcon(colIndex);
942
+ }
943
+ return dirty;
881
944
  };
882
945
  /** @private
883
946
  * @param {number} colIndex
884
947
  * @return {boolean} True if there is any change
885
948
  * @fires RowFilteringPlugin#filterChanged
886
949
  */
887
- RowFilteringPlugin.prototype._removeColumnFilters = function (colIndex) {
888
- var cfo = this._getColumnFilterOption(colIndex);
889
- if (cfo) {
890
- var funcIndex = this._columnFilters.indexOf(cfo);
891
- if (funcIndex >= 0) {
892
- this._columnFilters.splice(funcIndex, 1);
893
- }
894
- this._removeActiveFilterStates(colIndex); // filterChanged fired
895
- var inputExt = this._getPlugin("FilterInputPlugin"); // TODO: Use the event instead
896
- inputExt && inputExt.updateUI(colIndex, "");
897
- this._requestFilterRefresh();
898
- }
899
- return cfo ? true : false;
950
+ RowFilteringPlugin.prototype._removeColumnFilters = function(colIndex) {
951
+ let cfo = this._getColumnFilterOption(colIndex);
952
+ if(cfo) {
953
+ let funcIndex = this._columnFilters.indexOf(cfo);
954
+ if(funcIndex >= 0) {
955
+ this._columnFilters.splice(funcIndex, 1);
956
+ }
957
+ this._removeActiveFilterStates(colIndex); // filterChanged fired
958
+ let inputExt = this._getPlugin("FilterInputPlugin"); // TODO: Use the event instead
959
+ inputExt && inputExt.updateUI(colIndex, "");
960
+ this._requestFilterRefresh();
961
+ }
962
+ return cfo ? true : false;
900
963
  };
901
964
  /** Alias to {@link RowFilteringPlugin#removeColumnFilters} Remove all filters from the specified column
902
965
  * @public
@@ -912,155 +975,159 @@ RowFilteringPlugin.prototype.removeColumnFilter = RowFilteringPlugin.prototype.r
912
975
  * @return {boolean} Return true if there is any change
913
976
  * @fires RowFilteringPlugin#filterChanged
914
977
  */
915
- RowFilteringPlugin.prototype.removeAllColumnFilters = function () {
916
- if (this._columnFilters.length) {
917
- this._columnFilters.length = 0;
918
- var inputExt = this._getPlugin("FilterInputPlugin");
919
- var colCount = this._getColumnCount();
920
- for (var i = 0; i < colCount; ++i) {
921
- this._removeActiveFilterStates(i); // filterChanged fired
922
- inputExt && inputExt.updateUI(i, ""); // TODO: Use the event instead
923
- }
924
-
925
- this._updateAllColumnIcons();
926
- this._requestFilterRefresh();
927
- return true;
928
- }
929
- return false;
978
+ RowFilteringPlugin.prototype.removeAllColumnFilters = function() {
979
+ if(this._columnFilters.length) {
980
+ this._columnFilters.length = 0;
981
+
982
+ let inputExt = this._getPlugin("FilterInputPlugin");
983
+ let colCount = this._getColumnCount();
984
+ for(let i = 0; i < colCount; ++i) {
985
+ this._removeActiveFilterStates(i); // filterChanged fired
986
+ inputExt && inputExt.updateUI(i, ""); // TODO: Use the event instead
987
+ }
988
+
989
+ this._updateAllColumnIcons();
990
+
991
+ this._requestFilterRefresh();
992
+ return true;
993
+ }
994
+ return false;
930
995
  };
931
996
  /** Remove all column and global filters. OverridingFilters are not removed by this method
932
997
  * @public
933
998
  */
934
- RowFilteringPlugin.prototype.removeAllFilters = function () {
935
- var totalFilter = this._globalFilters.length + this._columnFilters.length;
936
- if (totalFilter <= 0) {
937
- return;
938
- }
939
- if (this._globalFilters.length) {
940
- this._globalFilters.length = 0;
941
- this._nameMap = {};
942
- this._dispatch("filterChanged", {
943
- "filterType": "global",
944
- "changeType": "remove",
945
- "colIndex": -1,
946
- "field": ""
947
- });
948
- }
949
- this.removeAllColumnFilters();
950
- this._requestFilterRefresh();
999
+ RowFilteringPlugin.prototype.removeAllFilters = function() {
1000
+ let totalFilter = this._globalFilters.length + this._columnFilters.length;
1001
+ if(totalFilter <= 0) { return; }
1002
+ if(this._globalFilters.length) {
1003
+ this._globalFilters.length = 0;
1004
+ this._nameMap = {};
1005
+
1006
+ this._dispatch("filterChanged", {
1007
+ "filterType": "global",
1008
+ "changeType": "remove",
1009
+ "colIndex": -1,
1010
+ "field": ""
1011
+ });
1012
+ }
1013
+
1014
+ this.removeAllColumnFilters();
1015
+
1016
+ this._requestFilterRefresh();
951
1017
  };
952
1018
 
953
1019
  /** Column overriding function is processed before column filters and after global filters. If it returns non-zero, the result will override all other column filter results. If it returns 1, the row will be always included. If it returns -1, the row will be always excluded. If it returns 0, the column filters will be used as normal.
954
1020
  * @public
955
1021
  * @param {Function} func
956
1022
  */
957
- RowFilteringPlugin.prototype.setOverridingFilter = function (func) {
958
- this._overridingFilter = func;
1023
+ RowFilteringPlugin.prototype.setOverridingFilter = function(func) {
1024
+ this._overridingFilter = func;
959
1025
  };
960
1026
  /** PreTransform is used to minimize the same data transformation on multiple filters. Output from the given method will be used on all subsequent filters. Note that it will be used for every existing row, so performance should be critical in here. This is optional setting.
961
1027
  * @public
962
1028
  * @param {Function} func This function must return object with key and value pairs
963
1029
  */
964
- RowFilteringPlugin.prototype.setPreTransform = function (func) {
965
- this._preTransform = func;
1030
+ RowFilteringPlugin.prototype.setPreTransform = function(func) {
1031
+ this._preTransform = func;
966
1032
  };
967
1033
  /** This is the same as preTransform, only it is executed just before column filters and after the global filters. This is optional setting.
968
1034
  * @public
969
1035
  * @param {Function} func This function must return object with key and value pairs
970
1036
  */
971
- RowFilteringPlugin.prototype.setRowTransform = function (func) {
972
- this._rowTransform = func;
1037
+ RowFilteringPlugin.prototype.setRowTransform = function(func) {
1038
+ this._rowTransform = func;
973
1039
  };
974
1040
 
975
1041
  /** @public
976
1042
  * @return {!Array.<Function>} All global filters
977
1043
  */
978
- RowFilteringPlugin.prototype.getFilters = function () {
979
- return this._globalFilters;
1044
+ RowFilteringPlugin.prototype.getFilters = function() {
1045
+ return this._globalFilters;
980
1046
  };
981
1047
  /** Returns filter functions. Use getConfigObject for saving and loading instead of this function
982
1048
  * @public
983
1049
  * @return {!Array.<Function>} All column filters
984
1050
  * @see {@link RowFilteringPlugin.getConfigObject}
985
1051
  */
986
- RowFilteringPlugin.prototype.getAllColumnFilters = function () {
987
- var filters = [];
988
- var len = this._columnFilters.length;
989
- for (var i = 0; i < len; ++i) {
990
- var cfo = this._columnFilters[i];
991
- var jLen = cfo._filters.length;
992
- for (var j = 0; j < jLen; ++j) {
993
- filters.push(cfo._filters[j]);
994
- }
995
- }
996
- return filters;
1052
+ RowFilteringPlugin.prototype.getAllColumnFilters = function() {
1053
+ let filters = [];
1054
+ let len = this._columnFilters.length;
1055
+ for(let i = 0; i < len; ++i) {
1056
+ let cfo = this._columnFilters[i];
1057
+ let jLen = cfo._filters.length;
1058
+ for(let j = 0; j < jLen; ++j) {
1059
+ filters.push(cfo._filters[j]);
1060
+ }
1061
+ }
1062
+ return filters;
997
1063
  };
998
1064
  /** Deprecated in favor of getConfigObject(). Get existing filter expressions for saving and restoring.
999
1065
  * @public
1000
1066
  * @return {Array.<RowFilteringPlugin~FilterExpression>} Return null if there is no column filter
1001
1067
  * @see {@link RowFilteringPlugin.getConfigObject}
1002
1068
  */
1003
- RowFilteringPlugin.prototype.getFilterExpressions = function () {
1004
- if (this._columnFilters.length) {
1005
- // TODO: Provide a way to save rawDataAccessor and formattedDataAccessor
1006
- return this._columnFilters.map(_toFilterExpression);
1007
- }
1008
- return null;
1069
+ RowFilteringPlugin.prototype.getFilterExpressions = function() {
1070
+ if(this._columnFilters.length) {
1071
+ // TODO: Provide a way to save rawDataAccessor and formattedDataAccessor
1072
+ return this._columnFilters.map(_toFilterExpression);
1073
+ }
1074
+ return null;
1009
1075
  };
1010
1076
  /** Deprecated. Clear all existing column filters and restore column filters from the given valid filter expressions. If the parameter is null, the result is equivalent to calling removeAllColumnFilters();
1011
1077
  * @public
1012
1078
  * @param {Array.<RowFilteringPlugin~FilterExpression>} filterExps
1013
1079
  */
1014
- RowFilteringPlugin.prototype.setFilterExpressions = function (filterExps) {
1015
- this.removeAllColumnFilters();
1016
- if (Array.isArray(filterExps)) {
1017
- var api = this.getGridApi();
1018
- var fields = api.getColumnFields();
1019
- var len = filterExps.length;
1020
- for (var i = 0; i < len; ++i) {
1021
- var filterExp = filterExps[i];
1022
- var field = filterExp.field;
1023
- var colIndex = fields.indexOf(field);
1024
- if (colIndex >= 0) {
1025
- this.setColumnFilter(colIndex, filterExp.expression, filterExp.context);
1026
- }
1027
- }
1028
- }
1080
+ RowFilteringPlugin.prototype.setFilterExpressions = function(filterExps) {
1081
+ this.removeAllColumnFilters();
1082
+
1083
+ if(Array.isArray(filterExps)) {
1084
+ let api = this.getGridApi();
1085
+ let fields = api.getColumnFields();
1086
+ let len = filterExps.length;
1087
+ for(let i = 0; i < len; ++i) {
1088
+ let filterExp = filterExps[i];
1089
+ let field = filterExp.field;
1090
+ let colIndex = fields.indexOf(field);
1091
+ if(colIndex >= 0) {
1092
+ this.setColumnFilter(colIndex, filterExp.expression, filterExp.context);
1093
+ }
1094
+ }
1095
+ }
1029
1096
  };
1030
1097
 
1031
1098
  /** @public
1032
1099
  * @return {boolean}
1033
1100
  */
1034
- RowFilteringPlugin.prototype.hasColumnFilter = function () {
1035
- return this._columnFilters.length > 0;
1101
+ RowFilteringPlugin.prototype.hasColumnFilter = function() {
1102
+ return (this._columnFilters.length > 0);
1036
1103
  };
1037
1104
  /** @public
1038
1105
  * @param {number} colIndex
1039
1106
  * @return {Array.<Element>} icons
1040
1107
  */
1041
- RowFilteringPlugin.prototype.getColumnFilterIcons = function (colIndex) {
1042
- var icons = [];
1043
- for (var i = this._hosts.length; --i >= 0;) {
1044
- var host = this._hosts[i];
1045
- var tsect = host.getSection("title");
1046
- if (!tsect) {
1047
- continue;
1048
- }
1049
- var rCount = tsect.getRowCount();
1050
- var cell = tsect.getCell(colIndex, rCount - 1, true); // Get bottom cell
1051
- if (cell && cell._filterIcon) {
1052
- icons.push(cell._filterIcon);
1053
- }
1054
- }
1055
- return icons;
1108
+ RowFilteringPlugin.prototype.getColumnFilterIcons = function(colIndex) {
1109
+ let icons = [];
1110
+ for(let i = this._hosts.length; --i >= 0;) {
1111
+ let host = this._hosts[i];
1112
+ let tsect = host.getSection("title");
1113
+ if(!tsect) {
1114
+ continue;
1115
+ }
1116
+ let rCount = tsect.getRowCount();
1117
+ let cell = tsect.getCell(colIndex, rCount - 1, true); // Get bottom cell
1118
+ if(cell && cell._filterIcon) {
1119
+ icons.push(cell._filterIcon);
1120
+ }
1121
+ }
1122
+ return icons;
1056
1123
  };
1057
1124
  /** @public */
1058
- RowFilteringPlugin.prototype.updateAllColumnIcons = function () {
1059
- if (this._uiTimerId) {
1060
- clearTimeout(this._uiTimerId);
1061
- this._uiTimerId = 0;
1062
- }
1063
- this._updateAllColumnIcons();
1125
+ RowFilteringPlugin.prototype.updateAllColumnIcons = function() {
1126
+ if(this._uiTimerId) {
1127
+ clearTimeout(this._uiTimerId);
1128
+ this._uiTimerId = 0;
1129
+ }
1130
+ this._updateAllColumnIcons();
1064
1131
  };
1065
1132
 
1066
1133
  /** Specify a list of data views to be filtered, excluding default data views used by UI. <br>
@@ -1068,105 +1135,114 @@ RowFilteringPlugin.prototype.updateAllColumnIcons = function () {
1068
1135
  * @public
1069
1136
  * @param {Object} dv DataView
1070
1137
  */
1071
- RowFilteringPlugin.prototype.addDataView = function (dv) {
1072
- var at = this._dvs.indexOf(dv);
1073
- if (at < 0) {
1074
- this._dvs.push(dv);
1075
- this._requestFilterRefresh();
1076
- }
1138
+ RowFilteringPlugin.prototype.addDataView = function(dv) {
1139
+ let at = this._dvs.indexOf(dv);
1140
+ if(at < 0) {
1141
+ this._dvs.push(dv);
1142
+ this._requestFilterRefresh();
1143
+ }
1077
1144
  };
1078
1145
  /** @public
1079
1146
  * @param {Object} dv DataView
1080
1147
  */
1081
- RowFilteringPlugin.prototype.removeDataView = function (dv) {
1082
- var at = this._dvs.indexOf(dv);
1083
- if (at >= 0) {
1084
- this._dvs.splice(at, 1);
1085
- this._requestFilterRefresh(); // This could be unnecessary
1086
- }
1148
+ RowFilteringPlugin.prototype.removeDataView = function(dv) {
1149
+ let at = this._dvs.indexOf(dv);
1150
+ if(at >= 0) {
1151
+ this._dvs.splice(at, 1);
1152
+ this._requestFilterRefresh(); // This could be unnecessary
1153
+ }
1087
1154
  };
1088
1155
 
1156
+
1089
1157
  /** @private
1090
1158
  * @param {Object} e
1091
1159
  */
1092
1160
  RowFilteringPlugin.prototype._onPreSectionRender = function (e) {
1093
- if (e["sectionType"] !== "title") {
1094
- return;
1095
- }
1096
- this._setTimerForUpdatingIcons();
1161
+ if(e["sectionType"] !== "title") { return; }
1162
+
1163
+ this._setTimerForUpdatingIcons();
1097
1164
  };
1098
1165
  /** @private
1099
1166
  * @param {Event} e
1100
1167
  */
1101
- RowFilteringPlugin.prototype._onIconClicked = function (e) {
1102
- var host = this._hosts[0];
1103
- if (!host) {
1104
- return;
1105
- }
1106
- var pos = host.getRelativePosition(e);
1107
- this.openDialog(pos.colIndex);
1108
- e.stopPropagation();
1109
- e.preventDefault();
1110
- this._dispatch("click", e);
1168
+ RowFilteringPlugin.prototype._onIconClicked = function(e) {
1169
+ let host = this._hosts[0];
1170
+ if(!host) { return; }
1171
+
1172
+ let pos = host.getRelativePosition(e);
1173
+ this.openDialog(pos.colIndex);
1174
+
1175
+ e.stopPropagation();
1176
+ e.preventDefault();
1177
+ this._dispatch("click", e);
1111
1178
  };
1112
1179
  /** @private
1113
1180
  * @param {string} rid
1114
1181
  * @param {Object} rowData
1115
1182
  * @return {boolean}
1116
1183
  */
1117
- RowFilteringPlugin.prototype._filterLogic = function (rid, rowData) {
1118
- if (rowData) {
1119
- if (this._rowGetter) {
1120
- rowData = this._rowGetter(rowData);
1121
- }
1122
- if (this._preTransform) {
1123
- rowData = this._preTransform(rowData);
1124
- }
1125
- var i;
1126
- var len = this._globalFilters.length;
1127
- for (i = 0; i < len; ++i) {
1128
- if (!this._globalFilters[i](rowData, rid, this._globalContexts[i])) {
1129
- return false;
1130
- }
1131
- }
1132
- len = this._activeColFilters.length;
1133
- if (len) {
1134
- if (this._overridingFilter) {
1135
- var ret = this._overridingFilter(rowData, rid);
1136
- if (ret) {
1137
- return ret > 0;
1138
- }
1139
- }
1140
- if (this._rowTransform) {
1141
- rowData = this._rowTransform(rowData);
1142
- }
1143
- for (i = 0; i < len; ++i) {
1144
- var cfo = this._activeColFilters[i];
1145
- var jLen = cfo._filters.length;
1146
- for (var j = 0; j < jLen; ++j) {
1147
- if (!cfo._filters[j](rowData, rid, cfo._context[j])) {
1148
- return false;
1149
- }
1150
- }
1151
- }
1152
- }
1153
- }
1154
- return true;
1184
+ RowFilteringPlugin.prototype._filterLogic = function(rid, rowData) {
1185
+ if(rowData) {
1186
+ if(this._rowGetter) {
1187
+ rowData = this._rowGetter(rowData);
1188
+ }
1189
+ if(this._preTransform) {
1190
+ rowData = this._preTransform(rowData);
1191
+ }
1192
+ let i;
1193
+ let len = this._globalFilters.length;
1194
+ for(i = 0; i < len; ++i) {
1195
+ if(!this._globalFilters[i](rowData, rid, this._globalContexts[i])) {
1196
+ return false;
1197
+ }
1198
+ }
1199
+
1200
+ len = this._activeColFilters.length;
1201
+ if(len) {
1202
+ if(this._overridingFilter) {
1203
+ let ret = this._overridingFilter(rowData, rid);
1204
+ if(ret) {
1205
+ return (ret > 0);
1206
+ }
1207
+ }
1208
+
1209
+ if(this._rowTransform) {
1210
+ rowData = this._rowTransform(rowData);
1211
+ }
1212
+
1213
+ for(i = 0; i < len; ++i) {
1214
+ let cfo = this._activeColFilters[i];
1215
+ let jLen = cfo._filters.length;
1216
+ for(let j = 0; j < jLen; ++j) {
1217
+ if(
1218
+ !cfo._filters[j](
1219
+ rowData,
1220
+ rid,
1221
+ cfo._context[j]
1222
+ )
1223
+ ) {
1224
+ return false;
1225
+ }
1226
+ }
1227
+ }
1228
+ }
1229
+ }
1230
+ return true;
1155
1231
  };
1156
1232
  /** @private */
1157
- RowFilteringPlugin.prototype._requestFilterRefresh = function () {
1158
- if (!this._filterTimerId) {
1159
- this._filterTimerId = setTimeout(this.refresh, 10);
1160
- }
1233
+ RowFilteringPlugin.prototype._requestFilterRefresh = function() {
1234
+ if(!this._filterTimerId) {
1235
+ this._filterTimerId = setTimeout(this.refresh, 10);
1236
+ }
1161
1237
  };
1162
1238
  /** @private */
1163
- RowFilteringPlugin.prototype._setTimerForUpdatingIcons = function () {
1164
- if (this._iconActivation === "none") {
1165
- return;
1166
- }
1167
- if (!this._uiTimerId) {
1168
- this._uiTimerId = setTimeout(this._updateAllColumnIcons, 10);
1169
- }
1239
+ RowFilteringPlugin.prototype._setTimerForUpdatingIcons = function() {
1240
+ if(this._iconActivation === "none") {
1241
+ return;
1242
+ }
1243
+ if(!this._uiTimerId) {
1244
+ this._uiTimerId = setTimeout(this._updateAllColumnIcons, 10);
1245
+ }
1170
1246
  };
1171
1247
 
1172
1248
  /** Perform filtering with the same parameters. Do not call this method repeatedly as the operation is quite expensive.
@@ -1174,118 +1250,124 @@ RowFilteringPlugin.prototype._setTimerForUpdatingIcons = function () {
1174
1250
  * @suppress {checkTypes}
1175
1251
  * @fires RowFilteringPlugin#refreshed
1176
1252
  */
1177
- RowFilteringPlugin.prototype.refresh = function () {
1178
- this._filterTimerId = 0;
1179
- this._activeColFilters = this._columnFilters;
1180
- //check cstp
1181
- var cstkp = this._getPlugin("ColumnStackPlugin");
1182
- if (cstkp) {
1183
- var colIndex, cfo;
1184
- var host = this._hosts[0];
1185
- var colCount = this._getColumnCount();
1186
- this._activeColFilters = [];
1187
- for (colIndex = 0; colIndex < colCount; ++colIndex) {
1188
- cfo = this._getColumnFilterOption(colIndex);
1189
- if (cfo && host.getColumnVisibility(colIndex, 2)) {
1190
- this._activeColFilters.push(cfo);
1191
- }
1192
- }
1193
- }
1194
- var totalFilter = this._globalFilters.length + this._activeColFilters.length;
1195
- var logic = !this._disabled && totalFilter ? this._filterLogic : null;
1196
- var dirty = 0;
1197
- var dvs = this._getAvailableDataViews();
1198
- for (var i = dvs.length; --i >= 0;) {
1199
- dirty |= dvs[i].filterIn(logic);
1200
- }
1201
- if (dirty) {
1202
- this._dispatch("refreshed", {});
1203
- }
1253
+ RowFilteringPlugin.prototype.refresh = function() {
1254
+ this._filterTimerId = 0;
1255
+
1256
+ this._activeColFilters = this._columnFilters;
1257
+ //check cstp
1258
+ let cstkp = this._getPlugin("ColumnStackPlugin");
1259
+ if(cstkp) {
1260
+ let colIndex, cfo;
1261
+ let host = this._hosts[0];
1262
+ let colCount = this._getColumnCount();
1263
+
1264
+ this._activeColFilters = [];
1265
+ for(colIndex = 0; colIndex < colCount; ++colIndex) {
1266
+ cfo = this._getColumnFilterOption(colIndex);
1267
+ if(cfo && host.getColumnVisibility(colIndex, 2)) {
1268
+ this._activeColFilters.push(cfo);
1269
+ }
1270
+ }
1271
+ }
1272
+
1273
+ let totalFilter = this._globalFilters.length + this._activeColFilters.length;
1274
+ let logic = (!this._disabled && totalFilter) ? this._filterLogic : null;
1275
+
1276
+ let dirty = 0;
1277
+ let dvs = this._getAvailableDataViews();
1278
+ for(let i = dvs.length; --i >= 0;) {
1279
+ dirty |= dvs[i].filterIn(logic);
1280
+ }
1281
+
1282
+ if(dirty) {
1283
+ this._dispatch("refreshed", {});
1284
+ }
1204
1285
  };
1205
1286
  /** @private
1206
1287
  * @param {number} colIndex
1207
1288
  */
1208
- RowFilteringPlugin.prototype._updateColumnIcon = function (colIndex) {
1209
- var cfo = this._getColumnFilterOption(colIndex); // colData["rowFiltering"]["filterOption"]
1210
- var colSettings = this._getUserColumnSettings(colIndex); // colData["rowFiltering"]
1211
- var iconActivation = colSettings.filterIcon == false ? "none" : this._iconActivation;
1212
- var hasFilter = cfo ? cfo._filters.length : 0;
1213
- for (var i = this._hosts.length; --i >= 0;) {
1214
- var host = this._hosts[i];
1215
- var tsect = host.getSection("title");
1216
- if (!tsect) {
1217
- continue;
1218
- }
1219
- var rCount = tsect.getRowCount();
1220
- var cell = tsect.getCell(colIndex, rCount - 1, true); // Get bottom cell
1221
- var column = tsect.getColumn(colIndex);
1222
- if (!cell) {
1223
- continue;
1224
- }
1225
- // HACK: Update cell padding for all type of icons (sorting and column grouping icons)
1226
- if (cell["updatePadding"]) {
1227
- cell["updatePadding"]();
1228
- }
1229
- var isColumnMovable = host.isColumnMovable(colIndex);
1230
- if (isColumnMovable) {
1231
- column.enableClass("movable", true);
1232
- } else {
1233
- column.enableClass("movable", false);
1234
- }
1235
- var onActiveFilter = iconActivation !== "always" && iconActivation !== "onHover";
1236
- var noFilterIcon = this._disabled || iconActivation === "none" || onActiveFilter && !hasFilter;
1237
- if (!noFilterIcon) {
1238
- if (!cell._filterIcon) {
1239
- var filterIcon = void 0;
1240
- if (ElfUtil.hasComponent("ef-icon") >= 3) {
1241
- filterIcon = document.createElement("ef-icon");
1242
- filterIcon.setAttribute("icon", "filter");
1243
- } else {
1244
- filterIcon = document.createElement("div");
1245
- filterIcon.className = "filter-symbol icon-filter ef-icon";
1246
- }
1247
- filterIcon.classList.add("title-filter-icon"); // Icon reference
1248
- filterIcon.addEventListener("click", this._onIconClicked, false);
1249
- this._dispatch("iconCreated", {
1250
- "icon": filterIcon,
1251
- "colIndex": colIndex,
1252
- "grid": host
1253
- });
1254
- cell.insertFloatingIcon(filterIcon, 10);
1255
- cell._filterIcon = filterIcon;
1256
- }
1257
- if (hasFilter) {
1258
- cell.enableClass("active-filter", true);
1259
- } else {
1260
- cell.enableClass("active-filter", false);
1261
- }
1262
- } else {
1263
- if (cell._filterIcon) {
1264
- cell.removeFloatingIcon(cell._filterIcon);
1265
- cell._filterIcon = null;
1266
- cell.enableClass("active-filter", false);
1267
- }
1268
- }
1269
- }
1289
+ RowFilteringPlugin.prototype._updateColumnIcon = function(colIndex) {
1290
+ let cfo = this._getColumnFilterOption(colIndex); // colData["rowFiltering"]["filterOption"]
1291
+ let colSettings = this._getUserColumnSettings(colIndex); // colData["rowFiltering"]
1292
+ let iconActivation = colSettings.filterIcon == false ? "none" : this._iconActivation;
1293
+ let hasFilter = cfo ? cfo._filters.length : 0;
1294
+
1295
+ for(let i = this._hosts.length; --i >= 0;) {
1296
+ let host = this._hosts[i];
1297
+ let tsect = host.getSection("title");
1298
+ if(!tsect) {
1299
+ continue;
1300
+ }
1301
+ let rCount = tsect.getRowCount();
1302
+ let cell = tsect.getCell(colIndex, rCount - 1, true); // Get bottom cell
1303
+ let column = tsect.getColumn(colIndex);
1304
+ if(!cell) {
1305
+ continue;
1306
+ }
1307
+ // HACK: Update cell padding for all type of icons (sorting and column grouping icons)
1308
+ if(cell["updatePadding"]) {
1309
+ cell["updatePadding"]();
1310
+ }
1311
+
1312
+ let isColumnMovable = host.isColumnMovable(colIndex);
1313
+ if(isColumnMovable) {
1314
+ column.enableClass("movable", true);
1315
+ } else {
1316
+ column.enableClass("movable", false);
1317
+ }
1318
+
1319
+ let onActiveFilter = iconActivation !== "always" && iconActivation !== "onHover";
1320
+ let noFilterIcon = this._disabled || iconActivation === "none" || (onActiveFilter && !hasFilter);
1321
+ if(!noFilterIcon) {
1322
+ if(!cell._filterIcon) {
1323
+ let filterIcon;
1324
+ if(ElfUtil.hasComponent("ef-icon") >= 3) {
1325
+ filterIcon = document.createElement("ef-icon");
1326
+ filterIcon.setAttribute("icon", "filter");
1327
+ } else {
1328
+ filterIcon = document.createElement("div");
1329
+ filterIcon.className = "filter-symbol icon-filter ef-icon";
1330
+ }
1331
+ filterIcon.classList.add("title-filter-icon"); // Icon reference
1332
+ filterIcon.addEventListener("click", this._onIconClicked, false);
1333
+ this._dispatch("iconCreated", {"icon": filterIcon, "colIndex": colIndex, "grid": host});
1334
+ cell.insertFloatingIcon(filterIcon, 10);
1335
+ cell._filterIcon = filterIcon;
1336
+ }
1337
+ if(hasFilter){
1338
+ cell.enableClass("active-filter", true);
1339
+ }else{
1340
+ cell.enableClass("active-filter", false);
1341
+ }
1342
+ } else {
1343
+ if(cell._filterIcon) {
1344
+ cell.removeFloatingIcon(cell._filterIcon);
1345
+ cell._filterIcon = null;
1346
+ cell.enableClass("active-filter", false);
1347
+ }
1348
+ }
1349
+ }
1270
1350
  };
1271
1351
  /** @private */
1272
- RowFilteringPlugin.prototype._updateAllColumnIcons = function () {
1273
- this._uiTimerId = 0;
1274
- var colCount = this._getColumnCount();
1275
- for (var i = 0; i < colCount; ++i) {
1276
- this._updateColumnIcon(i);
1277
- }
1352
+ RowFilteringPlugin.prototype._updateAllColumnIcons = function() {
1353
+ this._uiTimerId = 0;
1354
+
1355
+ let colCount = this._getColumnCount();
1356
+ for(let i = 0; i < colCount; ++i) {
1357
+ this._updateColumnIcon(i);
1358
+ }
1278
1359
  };
1279
1360
 
1361
+
1280
1362
  /** @private
1281
1363
  * @return {number}
1282
1364
  */
1283
- RowFilteringPlugin.prototype._getColumnCount = function () {
1284
- var grid = this._hosts[0];
1285
- if (grid) {
1286
- return grid.getColumnCount();
1287
- }
1288
- return 0;
1365
+ RowFilteringPlugin.prototype._getColumnCount = function() {
1366
+ let grid = this._hosts[0];
1367
+ if(grid) {
1368
+ return grid.getColumnCount();
1369
+ }
1370
+ return 0;
1289
1371
  };
1290
1372
 
1291
1373
  /** Update existing filter state by replacing the old one. Note that filtering will be performed asynchronously after executing this method.
@@ -1294,70 +1376,70 @@ RowFilteringPlugin.prototype._getColumnCount = function () {
1294
1376
  * @param {*} ctx Context object that will be passed as the third parameter for the filter logic
1295
1377
  * @return {boolean} Returns true if there is any change
1296
1378
  */
1297
- RowFilteringPlugin.prototype.setColumnFilterState = function (colIndex, ctx) {
1298
- var cfo = this._getColumnFilterOption(colIndex);
1299
- if (cfo) {
1300
- cfo._context[0] = ctx;
1301
- this._requestFilterRefresh();
1302
- return true;
1303
- }
1304
- return false;
1379
+ RowFilteringPlugin.prototype.setColumnFilterState = function(colIndex, ctx) {
1380
+ let cfo = this._getColumnFilterOption(colIndex);
1381
+ if(cfo) {
1382
+ cfo._context[0] = ctx;
1383
+ this._requestFilterRefresh();
1384
+ return true;
1385
+ }
1386
+ return false;
1305
1387
  };
1306
1388
  /** Get the stored user context from the specified column
1307
1389
  * @public
1308
1390
  * @param {number} colIndex
1309
1391
  * @return {*} Context object that is passed as the third parameter for the filter logic
1310
1392
  */
1311
- RowFilteringPlugin.prototype.getColumnFilterState = function (colIndex) {
1312
- var cfo = this._getColumnFilterOption(colIndex);
1313
- if (cfo) {
1314
- return cfo._context[0];
1315
- }
1316
- return null;
1393
+ RowFilteringPlugin.prototype.getColumnFilterState = function(colIndex) {
1394
+ let cfo = this._getColumnFilterOption(colIndex);
1395
+ if(cfo) {
1396
+ return cfo._context[0];
1397
+ }
1398
+ return null;
1317
1399
  };
1318
1400
  /** Deprecated in favor of getConfigObject(). Get the stored user context from all columns. The column with no filter will return null value
1319
1401
  * @public
1320
1402
  * @return {!Array} Array of context objects
1321
1403
  * @see {@link RowFilteringPlugin.getConfigObject}
1322
1404
  */
1323
- RowFilteringPlugin.prototype.getColumnFilterStates = function () {
1324
- var colCount = this._hosts[0] ? this._hosts[0].getColumnCount() : 0;
1325
- var states = new Array(colCount);
1326
- for (var c = 0; c < colCount; ++c) {
1327
- states[c] = this.getColumnFilterState(c);
1328
- }
1329
- return states;
1405
+ RowFilteringPlugin.prototype.getColumnFilterStates = function() {
1406
+ let colCount = this._hosts[0] ? this._hosts[0].getColumnCount() : 0;
1407
+ let states = new Array(colCount);
1408
+ for(let c = 0; c < colCount; ++c) {
1409
+ states[c] = this.getColumnFilterState(c);
1410
+ }
1411
+ return states;
1330
1412
  };
1331
1413
 
1332
1414
  /** @private
1333
1415
  * @return {!Array.<Object>} array of DataView
1334
1416
  */
1335
- RowFilteringPlugin.prototype._getAvailableDataViews = function () {
1336
- if (this._dvs.length) {
1337
- return this._dvs;
1338
- } else {
1339
- var len = this._hosts.length;
1340
- var ary = [];
1341
- for (var i = 0; i < len; ++i) {
1342
- var host = this._hosts[i];
1343
- var dv = host.getDataSource();
1344
- if (dv) {
1345
- ary.push(dv);
1346
- }
1347
- }
1348
- return ary;
1349
- }
1417
+ RowFilteringPlugin.prototype._getAvailableDataViews = function() {
1418
+ if(this._dvs.length) {
1419
+ return this._dvs;
1420
+ } else {
1421
+ let len = this._hosts.length;
1422
+ let ary = [];
1423
+ for(let i = 0; i < len; ++i) {
1424
+ let host = this._hosts[i];
1425
+ let dv = host.getDataSource();
1426
+ if(dv) {
1427
+ ary.push(dv);
1428
+ }
1429
+ }
1430
+ return ary;
1431
+ }
1350
1432
  };
1351
1433
  /** @private
1352
1434
  * @param {Object} dv DataView
1353
1435
  * @return {Object} DataTable
1354
1436
  */
1355
- RowFilteringPlugin.prototype._getDataTable = function (dv) {
1356
- var dt = dv ? dv.getDataSource() : null;
1357
- while (dt && dt.getDataSource()) {
1358
- dt = dt.getDataSource();
1359
- }
1360
- return dt;
1437
+ RowFilteringPlugin.prototype._getDataTable = function(dv) {
1438
+ let dt = dv ? dv.getDataSource() : null;
1439
+ while(dt && dt.getDataSource()) {
1440
+ dt = dt.getDataSource();
1441
+ }
1442
+ return dt;
1361
1443
  };
1362
1444
 
1363
1445
  /** @public
@@ -1372,12 +1454,12 @@ RowFilteringPlugin.prototype._getDataTable = function (dv) {
1372
1454
  * @param {Object=} selectedItems
1373
1455
  * @return {Object} Object that maps formatted value to array of raw values
1374
1456
  */
1375
- RowFilteringPlugin.prototype.getUniqueValues = function (field, formatter, fmtField, rawDataAccessor, formattedDataAccessor, filterFuncs, selectedItems) {
1376
- var dialogConfig = {
1377
- rawDataAccessor: rawDataAccessor,
1378
- formattedDataAccessor: formattedDataAccessor
1379
- };
1380
- return this._getUniqueValues(field, dialogConfig, formatter, filterFuncs, selectedItems);
1457
+ RowFilteringPlugin.prototype.getUniqueValues = function(field, formatter, fmtField, rawDataAccessor, formattedDataAccessor, filterFuncs, selectedItems) {
1458
+ let dialogConfig = {
1459
+ rawDataAccessor: rawDataAccessor,
1460
+ formattedDataAccessor: formattedDataAccessor
1461
+ };
1462
+ return this._getUniqueValues(field, dialogConfig, formatter, filterFuncs, selectedItems);
1381
1463
  };
1382
1464
 
1383
1465
  /** @private
@@ -1385,25 +1467,24 @@ RowFilteringPlugin.prototype.getUniqueValues = function (field, formatter, fmtFi
1385
1467
  * @param {*} rawVal
1386
1468
  * @returns {string}
1387
1469
  */
1388
- var _valueToString = function _valueToString(formattedVal, rawVal) {
1389
- if (typeof formattedVal === "string") {
1390
- return formattedVal;
1391
- }
1392
- if (formattedVal) {
1393
- if (_typeof(formattedVal) != "object") {
1394
- return rawVal + "";
1395
- } else if (formattedVal instanceof Date) {
1396
- return formattedVal.toLocaleString("en-GB");
1397
- } else {
1398
- // Object type cannot be converted to string
1399
- return "";
1400
- }
1401
- } else if (formattedVal === 0) {
1402
- return "0";
1403
- } else if (formattedVal === false) {
1404
- return "false";
1405
- }
1406
- return "";
1470
+ let _valueToString = function(formattedVal, rawVal) {
1471
+ if(typeof formattedVal === "string") {
1472
+ return formattedVal;
1473
+ }
1474
+ if(formattedVal) {
1475
+ if(typeof formattedVal != "object") {
1476
+ return rawVal + "";
1477
+ } else if(formattedVal instanceof Date) {
1478
+ return formattedVal.toLocaleString("en-GB");
1479
+ } else { // Object type cannot be converted to string
1480
+ return"";
1481
+ }
1482
+ } else if(formattedVal === 0) {
1483
+ return "0";
1484
+ } else if(formattedVal === false) {
1485
+ return "false";
1486
+ }
1487
+ return "";
1407
1488
  };
1408
1489
  /** @private
1409
1490
  * @param {Object} selectedItems
@@ -1412,36 +1493,34 @@ var _valueToString = function _valueToString(formattedVal, rawVal) {
1412
1493
  * @param {!Array.<Function>} filterFuncs A selector function that execute on each item to determine the selection
1413
1494
  * @return {boolean}
1414
1495
  */
1415
- var _collectSelectedItem = function _collectSelectedItem(selectedItems, formattedVal, row, filterFuncs) {
1416
- if (filterFuncs) {
1417
- if (!selectedItems[formattedVal]) {
1418
- for (var i = filterFuncs.length; --i >= 0;) {
1419
- if (!filterFuncs[i](row)) {
1420
- return false;
1421
- }
1422
- }
1423
- selectedItems[formattedVal] = true;
1424
- return true;
1425
- }
1426
- }
1427
- return false;
1496
+ let _collectSelectedItem = function(selectedItems, formattedVal, row, filterFuncs) {
1497
+ if(filterFuncs) {
1498
+ if(!selectedItems[formattedVal]) {
1499
+ for(let i = filterFuncs.length; --i >= 0;) {
1500
+ if(!filterFuncs[i](row)) {
1501
+ return false;
1502
+ }
1503
+ }
1504
+ selectedItems[formattedVal] = true;
1505
+ return true;
1506
+ }
1507
+ }
1508
+ return false;
1428
1509
  };
1429
1510
  /** @private
1430
1511
  * @param {Object} uniqueValues
1431
1512
  * @param {string} formattedVal
1432
1513
  * @param {*} rawVal
1433
1514
  */
1434
- var _collectUniqueValue = function _collectUniqueValue(uniqueValues, formattedVal, rawVal) {
1435
- var rawValues = uniqueValues[formattedVal];
1436
- if (rawValues) {
1437
- if (rawValues.indexOf(rawVal) < 0) {
1438
- // Check for unique raw values
1439
- rawValues.push(rawVal);
1440
- }
1441
- } else {
1442
- // The first unique formatted value detected
1443
- uniqueValues[formattedVal] = [rawVal];
1444
- }
1515
+ let _collectUniqueValue = function(uniqueValues, formattedVal, rawVal) {
1516
+ let rawValues = uniqueValues[formattedVal];
1517
+ if(rawValues) {
1518
+ if(rawValues.indexOf(rawVal) < 0) { // Check for unique raw values
1519
+ rawValues.push(rawVal);
1520
+ }
1521
+ } else { // The first unique formatted value detected
1522
+ uniqueValues[formattedVal] = [rawVal];
1523
+ }
1445
1524
  };
1446
1525
  /** @private
1447
1526
  * @param {string} field A field name for getting raw value from row data
@@ -1451,94 +1530,101 @@ var _collectUniqueValue = function _collectUniqueValue(uniqueValues, formattedVa
1451
1530
  * @param {Object} selectedItems
1452
1531
  * @return {Object} Object that maps formatted value to array of raw values
1453
1532
  */
1454
- RowFilteringPlugin.prototype._getUniqueValues = function (field, dialogConfig, formatter, filterFuncs, selectedItems) {
1455
- if (!field) {
1456
- return null;
1457
- }
1458
- var rawDataAccessor = dialogConfig.rawDataAccessor || null;
1459
- var formattedDataAccessor = dialogConfig.formattedDataAccessor || null;
1460
- var userItemList = dialogConfig.itemList;
1461
- var uniqueValues = {};
1462
- var formattedVal = null;
1463
- var rawVal = null;
1464
- if (!Array.isArray(userItemList)) {
1465
- userItemList = null;
1466
- var dvs = this._getAvailableDataViews();
1467
- var dts = dvs.map(this._getDataTable);
1468
- var tblCount = dts.length;
1469
- for (var t = 0; t < tblCount; ++t) {
1470
- var rows = dts[t].getAllRowData();
1471
- var rowCount = rows.length;
1472
- for (var r = 0; r < rowCount; ++r) {
1473
- var row = rows[r];
1474
- if (this._rowGetter) {
1475
- row = this._rowGetter(row);
1476
- }
1477
- if (this._rowTransform) {
1478
- row = this._rowTransform(row);
1479
- }
1480
- var fieldVal = row[field];
1481
- rawVal = fieldVal;
1482
- if (rawDataAccessor) {
1483
- rawVal = rawDataAccessor(rawVal);
1484
- }
1485
- if (!rawVal) {
1486
- // Only valid values are accepted
1487
- if (rawVal !== 0 && rawVal !== false) {
1488
- continue;
1489
- }
1490
- }
1491
- formattedVal = rawVal;
1492
- if (formattedDataAccessor) {
1493
- formattedVal = formattedDataAccessor(fieldVal); // The function takes data value
1494
- } else if (formatter) {
1495
- formattedVal = formatter(row); // The function takes row data
1496
- }
1497
-
1498
- formattedVal = _valueToString(formattedVal, rawVal);
1499
- if (formattedVal) {
1500
- _collectSelectedItem(selectedItems, formattedVal, row, filterFuncs);
1501
- _collectUniqueValue(uniqueValues, formattedVal, rawVal);
1502
- }
1503
- }
1504
- }
1505
- }
1506
- userItemList = _arrayConcat(userItemList, dialogConfig.additionalItems);
1507
- var dummyRow = {};
1508
- var userItemCount = userItemList ? userItemList.length : 0;
1509
- for (var i = 0; i < userItemCount; ++i) {
1510
- rawVal = dummyRow[field] = userItemList[i];
1511
- formattedVal = rawVal;
1512
- if (formattedDataAccessor) {
1513
- formattedVal = formattedDataAccessor(rawVal);
1514
- } else if (formatter) {
1515
- formattedVal = formatter(dummyRow);
1516
- }
1517
- formattedVal = _valueToString(formattedVal, rawVal);
1518
- if (formattedVal) {
1519
- _collectSelectedItem(selectedItems, formattedVal, dummyRow, filterFuncs);
1520
- _collectUniqueValue(uniqueValues, formattedVal, rawVal);
1521
- }
1522
- }
1523
- return uniqueValues;
1533
+ RowFilteringPlugin.prototype._getUniqueValues = function(field, dialogConfig, formatter, filterFuncs, selectedItems) {
1534
+ if(!field) {
1535
+ return null;
1536
+ }
1537
+
1538
+ let rawDataAccessor = (dialogConfig.rawDataAccessor || null);
1539
+ let formattedDataAccessor = (dialogConfig.formattedDataAccessor || null);
1540
+ let userItemList = dialogConfig.itemList;
1541
+
1542
+ let uniqueValues = {};
1543
+ let formattedVal = null;
1544
+ let rawVal = null;
1545
+ if(!Array.isArray(userItemList)) {
1546
+ userItemList = null;
1547
+ let dvs = this._getAvailableDataViews();
1548
+ let dts = dvs.map(this._getDataTable);
1549
+ let tblCount = dts.length;
1550
+ for(let t = 0; t < tblCount; ++t) {
1551
+ let rows = dts[t].getAllRowData();
1552
+ let rowCount = rows.length;
1553
+ for(let r = 0; r < rowCount; ++r) {
1554
+ let row = rows[r];
1555
+ if(this._rowGetter) {
1556
+ row = this._rowGetter(row);
1557
+ }
1558
+ if(this._rowTransform) {
1559
+ row = this._rowTransform(row);
1560
+ }
1561
+ let fieldVal = row[field];
1562
+ rawVal = fieldVal;
1563
+ if(rawDataAccessor) {
1564
+ rawVal = rawDataAccessor(rawVal);
1565
+ }
1566
+
1567
+ if(!rawVal) { // Only valid values are accepted
1568
+ if(rawVal !== 0 && rawVal !== false) {
1569
+ continue;
1570
+ }
1571
+ }
1572
+
1573
+ formattedVal = rawVal;
1574
+ if(formattedDataAccessor) {
1575
+ formattedVal = formattedDataAccessor(fieldVal); // The function takes data value
1576
+ } else if(formatter) {
1577
+ formattedVal = formatter(row); // The function takes row data
1578
+ }
1579
+
1580
+ formattedVal = _valueToString(formattedVal, rawVal);
1581
+ if(formattedVal) {
1582
+ _collectSelectedItem(selectedItems, formattedVal, row, filterFuncs);
1583
+ _collectUniqueValue(uniqueValues, formattedVal, rawVal);
1584
+ }
1585
+ }
1586
+ }
1587
+ }
1588
+
1589
+ userItemList = _arrayConcat(userItemList, dialogConfig.additionalItems);
1590
+
1591
+ let dummyRow = {};
1592
+ let userItemCount = userItemList ? userItemList.length : 0;
1593
+ for(let i = 0; i < userItemCount; ++i) {
1594
+ rawVal = dummyRow[field] = userItemList[i];
1595
+ formattedVal = rawVal;
1596
+ if(formattedDataAccessor) {
1597
+ formattedVal = formattedDataAccessor(rawVal);
1598
+ } else if(formatter) {
1599
+ formattedVal = formatter(dummyRow);
1600
+ }
1601
+
1602
+ formattedVal = _valueToString(formattedVal, rawVal);
1603
+ if(formattedVal) {
1604
+ _collectSelectedItem(selectedItems, formattedVal, dummyRow, filterFuncs);
1605
+ _collectUniqueValue(uniqueValues, formattedVal, rawVal);
1606
+ }
1607
+ }
1608
+ return uniqueValues;
1524
1609
  };
1525
1610
 
1611
+
1526
1612
  /** @private
1527
1613
  * @function
1528
1614
  * @returns {Element}
1529
1615
  */
1530
- RowFilteringPlugin._createDialog = function () {
1531
- var tag = RowFilteringPlugin._dialogTagName;
1532
- if (tag == null) {
1533
- var dialogVersion = ElfUtil.hasComponent("filter-dialog"); // WARNING: this cannot detect version 2 or less
1534
- if (dialogVersion) {
1535
- RowFilteringPlugin._dialogTagName = dialogVersion >= 3 ? "filter-dialog" : "tr-grid-filter-dialog";
1536
- } else {
1537
- RowFilteringPlugin._dialogTagName = "";
1538
- }
1539
- tag = RowFilteringPlugin._dialogTagName;
1540
- }
1541
- return tag ? document.createElement(tag) : null;
1616
+ RowFilteringPlugin._createDialog = function() {
1617
+ let tag = RowFilteringPlugin._dialogTagName;
1618
+ if(tag == null) {
1619
+ let dialogVersion = ElfUtil.hasComponent("filter-dialog"); // WARNING: this cannot detect version 2 or less
1620
+ if(dialogVersion) {
1621
+ RowFilteringPlugin._dialogTagName = (dialogVersion >= 3) ? "filter-dialog" : "tr-grid-filter-dialog";
1622
+ } else {
1623
+ RowFilteringPlugin._dialogTagName = "";
1624
+ }
1625
+ tag = RowFilteringPlugin._dialogTagName;
1626
+ }
1627
+ return tag ? document.createElement(tag) : null;
1542
1628
  };
1543
1629
  /** @private
1544
1630
  * @function
@@ -1547,508 +1633,531 @@ RowFilteringPlugin._createDialog = function () {
1547
1633
  * @param {Function} formatter
1548
1634
  * @returns {Array}
1549
1635
  */
1550
- RowFilteringPlugin._formatArrayExpression = function (exp, field, formatter) {
1551
- if (Array.isArray(exp)) {
1552
- var ary = exp.slice(); // Clone to avoid modifying original data
1553
- var formattedVal = ary[1];
1554
- var val = stringToDateObject(formattedVal);
1555
- if (val !== formattedVal) {
1556
- ary.rawValue = val;
1557
- ary.formattedValue = formattedVal;
1558
- }
1559
- if (field && formatter && typeof val !== "string") {
1560
- if (val != null) {
1561
- var dummyRow = {};
1562
- dummyRow[field] = val;
1563
- formattedVal = formatter(dummyRow);
1564
- if (formattedVal) {
1565
- ary.rawValue = val;
1566
- ary.formattedValue = formattedVal;
1567
- val = formattedVal;
1568
- }
1569
- }
1570
- }
1571
- ary[1] = val;
1572
- return ary;
1573
- }
1574
- return null;
1636
+ RowFilteringPlugin._formatArrayExpression = function(exp, field, formatter) {
1637
+ if(Array.isArray(exp)) {
1638
+ let ary = exp.slice(); // Clone to avoid modifying original data
1639
+ let formattedVal = ary[1];
1640
+ let val = stringToDateObject(formattedVal);
1641
+ if(val !== formattedVal) {
1642
+ ary.rawValue = val;
1643
+ ary.formattedValue = formattedVal;
1644
+ }
1645
+ if(field && formatter && typeof val !== "string") {
1646
+ if(val != null) {
1647
+ let dummyRow = {};
1648
+ dummyRow[field] = val;
1649
+ formattedVal = formatter(dummyRow);
1650
+ if(formattedVal) {
1651
+ ary.rawValue = val;
1652
+ ary.formattedValue = formattedVal;
1653
+ val = formattedVal;
1654
+ }
1655
+ }
1656
+ }
1657
+ ary[1] = val;
1658
+ return ary;
1659
+ }
1660
+ return null;
1575
1661
  };
1576
1662
  /** @public
1577
1663
  * @param {number} colIndex
1578
1664
  * @param {RowFilteringPlugin~FilterDialogOptions=} runtimeDialogOptions
1579
1665
  */
1580
- RowFilteringPlugin.prototype.openDialog = function (colIndex, runtimeDialogOptions) {
1581
- var stp = this._getPlugin("SortableTitlePlugin");
1582
- if (!this._filterDialog || !this._dialogInitialized) {
1583
- if (!this._filterDialog) {
1584
- this._filterDialog = RowFilteringPlugin._createDialog();
1585
- }
1586
- if (this._filterDialog) {
1587
- this._dialogInitialized = true;
1588
- if (!stp) {
1589
- this._filterDialog.hideSortUI();
1590
- } else {
1591
- this._filterDialog.addEventListener("sortChanged", this._onDialogSortChanged.bind(this));
1592
- }
1593
- this._filterDialog.addEventListener("filterChanged", this._onDialogFilterChanged.bind(this));
1594
- }
1595
- }
1596
- if (!this._filterDialog) {
1597
- console.log("Filter dialog does not exist");
1598
- return;
1599
- }
1600
- if (this._filterDialog.isShown) {
1601
- this._filterDialog.hide(); // Hide previously opened dialog
1602
- if (this._filterDialog._colIndex === colIndex) {
1603
- // The dialog is already openned
1604
- return; // Toggle open state
1605
- }
1606
- }
1607
-
1608
- var host = this._hosts[0];
1609
- if (!host) {
1610
- return;
1611
- }
1612
-
1613
- // Find target cell for positioning filter dialog
1614
- var tsect = host.getSection("title");
1615
- if (!tsect) {
1616
- return;
1617
- }
1618
- var rCount = tsect.getRowCount();
1619
- var cell = tsect.getCell(colIndex, rCount - 1, true); // Get bottom cell
1620
- if (!cell || !cell.getElement()) {
1621
- return;
1622
- }
1623
-
1624
- // TODO: Handle newly inserted/added columns
1625
- var field = this._getField(colIndex);
1626
- if (!field) {
1627
- return; // The specified column has no field
1628
- }
1629
-
1630
- if (this.hasListener("beforeDialogOpened")) {
1631
- var arg = {
1632
- colIndex: colIndex,
1633
- field: field,
1634
- grid: host
1635
- };
1636
- if (runtimeDialogOptions) {
1637
- arg["dialogOptions"] = runtimeDialogOptions;
1638
- }
1639
- this._dispatch("beforeDialogOpened", arg);
1640
- if (arg["cancel"]) {
1641
- return;
1642
- }
1643
- if (arg["dialogOptions"]) {
1644
- runtimeDialogOptions = arg["dialogOptions"];
1645
- }
1646
- }
1647
- if (_typeof(runtimeDialogOptions) !== "object") {
1648
- runtimeDialogOptions = null;
1649
- }
1650
- if (stp) {
1651
- this._filterDialog.setSortState(stp.getSortOrder(colIndex)); // This is for ELF v3
1652
- }
1653
-
1654
- // Setting up dialog configuration
1655
- var colData = host.getColumnData(colIndex);
1656
- var formatOptions = colData.formatOptions;
1657
- var useUTCTime = false;
1658
- if (formatOptions) {
1659
- if (formatOptions.formatType) {
1660
- useUTCTime = true;
1661
- if (formatOptions.useUTCTime != null) {
1662
- useUTCTime = formatOptions.useUTCTime;
1663
- }
1664
- }
1665
- }
1666
- var dialogConfig = {
1667
- // default config
1668
- sortUI: true,
1669
- filterUI: true,
1670
- fieldDataType: "",
1671
- lang: "",
1672
- rawDataAccessor: null,
1673
- formattedDataAccessor: null,
1674
- sortLogic: null,
1675
- blankValues: false,
1676
- blankValuesChecked: false
1677
- };
1678
- var columnDialogOptions = null;
1679
- var colSettings = this._getUserColumnSettings(colIndex); // colData["rowFiltering"]
1680
- if (colSettings.fieldDataType) {
1681
- // TODO: Use data type from Composite Grid (getColumnDataType) or Realtime Grid (getDataType) instead
1682
- columnDialogOptions = {
1683
- fieldDataType: colSettings.fieldDataType
1684
- };
1685
- }
1686
- RowFilteringPlugin._overrideConfig(dialogConfig, this._dialogOptions);
1687
- RowFilteringPlugin._overrideConfig(dialogConfig, columnDialogOptions);
1688
- RowFilteringPlugin._overrideConfig(dialogConfig, runtimeDialogOptions);
1689
-
1690
- // cfo is required for storing unique entries in the dialog, even though no filter is active
1691
- // TODO: move rawDataAccessor and other settings to colSettings
1692
- var cfo = this._initColumnFilterOption(colIndex); // colData["rowFiltering"]["filterOption"]
1693
- cfo._rawDataAccessor = dialogConfig.rawDataAccessor || null;
1694
- cfo._formattedDataAccessor = dialogConfig.formattedDataAccessor || null;
1695
- var sortLogic = dialogConfig.sortLogic || null;
1696
-
1697
- // Populate data for filter dialog based on existing states
1698
- var formatter = this._getFormatter(colIndex);
1699
- var condition2D = null;
1700
- var filterMode = ""; // default
1701
- var filterFuncs = null;
1702
- var exp = colSettings.expression;
1703
- if (exp) {
1704
- if (Array.isArray(exp)) {
1705
- if (exp.length) {
1706
- condition2D = Array.isArray(exp[0]) ? exp.slice() : [exp]; // Guaranteed condition2D to be a 2D array
1707
- condition2D[0] = RowFilteringPlugin._formatArrayExpression(condition2D[0], field, formatter);
1708
- condition2D[1] = RowFilteringPlugin._formatArrayExpression(condition2D[1], field, formatter);
1709
- filterMode = "advanced";
1710
- }
1711
- } else if (typeof exp === "function" || typeof exp === "string" || _typeof(exp) === "object") {
1712
- if (cfo._filters && cfo._filters.length) {
1713
- filterFuncs = cfo._filters;
1714
- }
1715
- if (_typeof(exp) === "object") {
1716
- dialogConfig.additionalItems = _arrayConcat(dialogConfig.additionalItems, Object.keys(exp));
1717
- }
1718
- }
1719
- }
1720
- var selectedItems = {};
1721
- var uniqueValues = cfo.uniqueValues = this._getUniqueValues(field, dialogConfig, formatter, filterFuncs, selectedItems);
1722
- if (dialogConfig.blankValues) {
1723
- delete uniqueValues[BLANKS];
1724
- var dunmmySelectItem = {};
1725
- var blkVals = ["", null, undefined, NaN]; // eslint-disable-line
1726
- var dummyRow = {};
1727
- for (var i = 0; i < blkVals.length; i++) {
1728
- var blkVal = blkVals[i];
1729
- dummyRow[field] = blkVal;
1730
- if (_collectSelectedItem(dunmmySelectItem, BLANKS, dummyRow, filterFuncs)) {
1731
- dialogConfig.blankValuesChecked = true;
1732
- break;
1733
- }
1734
- }
1735
- }
1736
- var keys = Object.keys(uniqueValues);
1737
- if (sortLogic) {
1738
- keys.sort(function (a, b) {
1739
- var rawValueA = uniqueValues[a][0];
1740
- var rawValueB = uniqueValues[b][0];
1741
- return sortLogic(rawValueA, rawValueB); // Compare with rawValue
1742
- });
1743
- }
1744
-
1745
- var items = keys.map(function (formattedVal, idx) {
1746
- return {
1747
- id: idx,
1748
- title: formattedVal,
1749
- nodes: [],
1750
- checked: selectedItems[formattedVal] ? true : false
1751
- };
1752
- });
1753
-
1754
- // Adding inputs from conditions to uniqueValues for mapping back from the dialog
1755
- if (condition2D) {
1756
- var cond = condition2D[0];
1757
- if (cond && cond.formattedValue) {
1758
- if (!uniqueValues[cond.formattedValue]) {
1759
- uniqueValues[cond.formattedValue] = [cond.rawValue];
1760
- }
1761
- }
1762
- cond = condition2D[1];
1763
- if (cond && cond.formattedValue) {
1764
- if (!uniqueValues[cond.formattedValue]) {
1765
- uniqueValues[cond.formattedValue] = [cond.rawValue];
1766
- }
1767
- }
1768
- }
1769
-
1770
- // Initialize dialog
1771
- if (this._filterDialog.init) {
1772
- // TODO: support initiailization in v1
1773
- this._filterDialog.init(dialogConfig);
1774
- }
1775
-
1776
- // TODO: Move all settings to configuration object
1777
- this._filterDialog.useUTCTime = useUTCTime;
1778
- this._filterDialog.target = cell.getElement();
1779
- this._filterDialog._colIndex = colIndex;
1780
- this._filterDialog.data = items; // TODO: Move all settings to configuration object
1781
- this._filterDialog.filterMode = filterMode;
1782
- this._filterDialog.conditions = condition2D;
1783
- this._filterDialog.show();
1666
+ RowFilteringPlugin.prototype.openDialog = function(colIndex, runtimeDialogOptions) {
1667
+ let stp = this._getPlugin("SortableTitlePlugin");
1668
+
1669
+ if(!this._filterDialog || !this._dialogInitialized) {
1670
+ if(!this._filterDialog) {
1671
+ this._filterDialog = RowFilteringPlugin._createDialog();
1672
+ }
1673
+
1674
+ if(this._filterDialog) {
1675
+ this._dialogInitialized = true;
1676
+ if(!stp) {
1677
+ this._filterDialog.hideSortUI();
1678
+ } else {
1679
+ this._filterDialog.addEventListener("sortChanged", this._onDialogSortChanged.bind(this));
1680
+ }
1681
+ this._filterDialog.addEventListener("filterChanged", this._onDialogFilterChanged.bind(this));
1682
+ }
1683
+ }
1684
+
1685
+ if(!this._filterDialog) {
1686
+ console.log("Filter dialog does not exist");
1687
+ return;
1688
+ }
1689
+
1690
+ if(this._filterDialog.isShown) {
1691
+ this._filterDialog.hide(); // Hide previously opened dialog
1692
+ if(this._filterDialog._colIndex === colIndex) { // The dialog is already openned
1693
+ return; // Toggle open state
1694
+ }
1695
+ }
1696
+
1697
+ let host = this._hosts[0];
1698
+ if(!host) {
1699
+ return;
1700
+ }
1701
+
1702
+ // Find target cell for positioning filter dialog
1703
+ let tsect = host.getSection("title");
1704
+ if(!tsect) {
1705
+ return;
1706
+ }
1707
+ let rCount = tsect.getRowCount();
1708
+ let cell = tsect.getCell(colIndex, rCount - 1, true); // Get bottom cell
1709
+ if(!cell || !cell.getElement()) {
1710
+ return;
1711
+ }
1712
+
1713
+ // TODO: Handle newly inserted/added columns
1714
+ let field = this._getField(colIndex);
1715
+ if(!field) {
1716
+ return; // The specified column has no field
1717
+ }
1718
+
1719
+ if(this.hasListener("beforeDialogOpened")) {
1720
+ let arg = {
1721
+ colIndex: colIndex,
1722
+ field: field,
1723
+ grid: host
1724
+ };
1725
+ if(runtimeDialogOptions) {
1726
+ arg["dialogOptions"] = runtimeDialogOptions;
1727
+ }
1728
+ this._dispatch("beforeDialogOpened", arg);
1729
+ if(arg["cancel"]) {
1730
+ return;
1731
+ }
1732
+ if(arg["dialogOptions"]) {
1733
+ runtimeDialogOptions = arg["dialogOptions"];
1734
+ }
1735
+ }
1736
+
1737
+ if(typeof runtimeDialogOptions !== "object") {
1738
+ runtimeDialogOptions = null;
1739
+ }
1740
+
1741
+ if(stp) {
1742
+ this._filterDialog.setSortState(stp.getSortOrder(colIndex)); // This is for ELF v3
1743
+ }
1744
+
1745
+ // Setting up dialog configuration
1746
+ let colData = host.getColumnData(colIndex);
1747
+ let formatOptions = colData.formatOptions;
1748
+ let useUTCTime = false;
1749
+ if(formatOptions){
1750
+ if(formatOptions.formatType){
1751
+ useUTCTime = true;
1752
+ if(formatOptions.useUTCTime != null){
1753
+ useUTCTime = formatOptions.useUTCTime;
1754
+ }
1755
+ }
1756
+ }
1757
+
1758
+ let dialogConfig = { // default config
1759
+ sortUI: true,
1760
+ filterUI: true,
1761
+ fieldDataType: "",
1762
+ lang: "",
1763
+ rawDataAccessor: null,
1764
+ formattedDataAccessor: null,
1765
+ sortLogic: null,
1766
+ blankValues: false,
1767
+ blankValuesChecked: false
1768
+ };
1769
+
1770
+ let columnDialogOptions = null;
1771
+ let colSettings = this._getUserColumnSettings(colIndex); // colData["rowFiltering"]
1772
+ if(colSettings.fieldDataType){
1773
+ // TODO: Use data type from Composite Grid (getColumnDataType) or Realtime Grid (getDataType) instead
1774
+ columnDialogOptions = {
1775
+ fieldDataType: colSettings.fieldDataType
1776
+ };
1777
+ }
1778
+
1779
+ RowFilteringPlugin._overrideConfig(dialogConfig, this._dialogOptions);
1780
+ RowFilteringPlugin._overrideConfig(dialogConfig, columnDialogOptions);
1781
+ RowFilteringPlugin._overrideConfig(dialogConfig, runtimeDialogOptions);
1782
+
1783
+ // cfo is required for storing unique entries in the dialog, even though no filter is active
1784
+ // TODO: move rawDataAccessor and other settings to colSettings
1785
+ let cfo = this._initColumnFilterOption(colIndex); // colData["rowFiltering"]["filterOption"]
1786
+ cfo._rawDataAccessor = (dialogConfig.rawDataAccessor || null);
1787
+ cfo._formattedDataAccessor = (dialogConfig.formattedDataAccessor || null);
1788
+ let sortLogic = dialogConfig.sortLogic || null;
1789
+
1790
+ // Populate data for filter dialog based on existing states
1791
+ let formatter = this._getFormatter(colIndex);
1792
+ let condition2D = null;
1793
+ let filterMode = ""; // default
1794
+ let filterFuncs = null;
1795
+ let exp = colSettings.expression;
1796
+ if(exp) {
1797
+ if(Array.isArray(exp)) {
1798
+ if(exp.length) {
1799
+ condition2D = Array.isArray(exp[0]) ? exp.slice() : [exp]; // Guaranteed condition2D to be a 2D array
1800
+ condition2D[0] = RowFilteringPlugin._formatArrayExpression(condition2D[0], field, formatter);
1801
+ condition2D[1] = RowFilteringPlugin._formatArrayExpression(condition2D[1], field, formatter);
1802
+ filterMode = "advanced";
1803
+ }
1804
+ } else if(typeof exp === "function" || typeof exp === "string" || typeof exp === "object") {
1805
+ if(cfo._filters && cfo._filters.length) {
1806
+ filterFuncs = cfo._filters;
1807
+ }
1808
+ if(typeof exp === "object") {
1809
+ dialogConfig.additionalItems = _arrayConcat(dialogConfig.additionalItems, Object.keys(exp));
1810
+ }
1811
+ }
1812
+ }
1813
+
1814
+ let selectedItems = {};
1815
+ let uniqueValues = cfo.uniqueValues = this._getUniqueValues(
1816
+ field,
1817
+ dialogConfig,
1818
+ formatter,
1819
+ filterFuncs,
1820
+ selectedItems
1821
+ );
1822
+
1823
+ if(dialogConfig.blankValues) {
1824
+ delete uniqueValues[BLANKS];
1825
+ let dunmmySelectItem = {};
1826
+ let blkVals = ["", null, undefined, NaN]; // eslint-disable-line
1827
+ let dummyRow = {};
1828
+ for(let i = 0; i < blkVals.length; i++) {
1829
+ let blkVal = blkVals[i];
1830
+ dummyRow[field] = blkVal;
1831
+
1832
+ if(_collectSelectedItem(dunmmySelectItem, BLANKS, dummyRow, filterFuncs)) {
1833
+ dialogConfig.blankValuesChecked = true;
1834
+ break;
1835
+ }
1836
+ }
1837
+ }
1838
+
1839
+ let keys = Object.keys(uniqueValues);
1840
+ if(sortLogic) {
1841
+ keys.sort(function (a, b) {
1842
+ let rawValueA = uniqueValues[a][0];
1843
+ let rawValueB = uniqueValues[b][0];
1844
+ return sortLogic(rawValueA, rawValueB); // Compare with rawValue
1845
+ });
1846
+ }
1847
+
1848
+ let items = keys.map(function(formattedVal, idx) {
1849
+ return {
1850
+ id: idx,
1851
+ title: formattedVal,
1852
+ nodes: [],
1853
+ checked: selectedItems[formattedVal] ? true : false
1854
+ };
1855
+ });
1856
+
1857
+ // Adding inputs from conditions to uniqueValues for mapping back from the dialog
1858
+ if(condition2D) {
1859
+ let cond = condition2D[0];
1860
+ if(cond && cond.formattedValue) {
1861
+ if(!uniqueValues[cond.formattedValue]) {
1862
+ uniqueValues[cond.formattedValue] = [cond.rawValue];
1863
+ }
1864
+ }
1865
+ cond = condition2D[1];
1866
+ if(cond && cond.formattedValue) {
1867
+ if(!uniqueValues[cond.formattedValue]) {
1868
+ uniqueValues[cond.formattedValue] = [cond.rawValue];
1869
+ }
1870
+ }
1871
+ }
1872
+
1873
+ // Initialize dialog
1874
+ if(this._filterDialog.init) { // TODO: support initiailization in v1
1875
+ this._filterDialog.init(dialogConfig);
1876
+ }
1877
+
1878
+ // TODO: Move all settings to configuration object
1879
+ this._filterDialog.useUTCTime = useUTCTime;
1880
+ this._filterDialog.target = cell.getElement();
1881
+ this._filterDialog._colIndex = colIndex;
1882
+ this._filterDialog.data = items; // TODO: Move all settings to configuration object
1883
+ this._filterDialog.filterMode = filterMode;
1884
+ this._filterDialog.conditions = condition2D;
1885
+ this._filterDialog.show();
1784
1886
  };
1785
1887
  /** @private
1786
1888
  * @function
1787
1889
  * @param {Object} config
1788
1890
  * @param {RowFilteringPlugin~FilterDialogOptions=} userConfig
1789
1891
  */
1790
- RowFilteringPlugin._overrideConfig = function (config, userConfig) {
1791
- if (!userConfig) {
1792
- return;
1793
- }
1794
- var sortUI = userConfig["sortUI"];
1795
- if (sortUI != null) {
1796
- config.sortUI = sortUI;
1797
- }
1798
- var filterUI = userConfig["filterUI"];
1799
- if (filterUI != null) {
1800
- config.filterUI = filterUI;
1801
- }
1802
- var fieldDataType = userConfig["fieldDataType"];
1803
- if (fieldDataType != null) {
1804
- config.fieldDataType = fieldDataType;
1805
- }
1806
- var lang = userConfig["lang"];
1807
- if (lang != null) {
1808
- config.lang = lang;
1809
- }
1810
- var rawDataAccessor = userConfig["rawDataAccessor"];
1811
- if (typeof rawDataAccessor === "function" || rawDataAccessor === null) {
1812
- // Allow null value
1813
- config.rawDataAccessor = rawDataAccessor;
1814
- }
1815
- var formattedDataAccessor = userConfig["formattedDataAccessor"];
1816
- if (typeof formattedDataAccessor === "function" || formattedDataAccessor === null) {
1817
- // Allow null value
1818
- config.formattedDataAccessor = formattedDataAccessor;
1819
- }
1820
- var sortLogic = userConfig["sortLogic"];
1821
- if (typeof sortLogic === "function" || sortLogic === null) {
1822
- // Allow null value
1823
- config.sortLogic = sortLogic;
1824
- }
1825
- var itemList = userConfig["itemList"];
1826
- if (itemList != null) {
1827
- config.itemList = itemList;
1828
- }
1829
- var additionalItems = userConfig["additionalItems"];
1830
- if (additionalItems != null) {
1831
- config.additionalItems = additionalItems;
1832
- }
1833
- var blankValues = userConfig["blankValues"];
1834
- if (blankValues) {
1835
- if (typeof blankValues === "string") {
1836
- config.blankValues = blankValues;
1837
- } else {
1838
- config.blankValues = BLANKS;
1839
- }
1840
- }
1892
+ RowFilteringPlugin._overrideConfig = function(config, userConfig) {
1893
+ if(!userConfig) {
1894
+ return;
1895
+ }
1896
+
1897
+ let sortUI = userConfig["sortUI"];
1898
+ if(sortUI != null) {
1899
+ config.sortUI = sortUI;
1900
+ }
1901
+
1902
+ let filterUI = userConfig["filterUI"];
1903
+ if(filterUI != null) {
1904
+ config.filterUI = filterUI;
1905
+ }
1906
+
1907
+ let fieldDataType = userConfig["fieldDataType"];
1908
+ if(fieldDataType != null) {
1909
+ config.fieldDataType = fieldDataType;
1910
+ }
1911
+
1912
+ let lang = userConfig["lang"];
1913
+ if(lang != null) {
1914
+ config.lang = lang;
1915
+ }
1916
+
1917
+ let rawDataAccessor = userConfig["rawDataAccessor"];
1918
+ if(typeof rawDataAccessor === "function" || rawDataAccessor === null) { // Allow null value
1919
+ config.rawDataAccessor = rawDataAccessor;
1920
+ }
1921
+
1922
+ let formattedDataAccessor = userConfig["formattedDataAccessor"];
1923
+ if(typeof formattedDataAccessor === "function" || formattedDataAccessor === null) { // Allow null value
1924
+ config.formattedDataAccessor = formattedDataAccessor;
1925
+ }
1926
+
1927
+ let sortLogic = userConfig["sortLogic"];
1928
+ if(typeof sortLogic === "function" || sortLogic === null) { // Allow null value
1929
+ config.sortLogic = sortLogic;
1930
+ }
1931
+
1932
+ let itemList = userConfig["itemList"];
1933
+ if(itemList != null) {
1934
+ config.itemList = itemList;
1935
+ }
1936
+
1937
+ let additionalItems = userConfig["additionalItems"];
1938
+ if(additionalItems != null) {
1939
+ config.additionalItems = additionalItems;
1940
+ }
1941
+ let blankValues = userConfig["blankValues"];
1942
+ if(blankValues) {
1943
+ if(typeof blankValues === "string") {
1944
+ config.blankValues = blankValues;
1945
+ } else {
1946
+ config.blankValues = BLANKS;
1947
+ }
1948
+ }
1841
1949
  };
1842
1950
  /** @private
1843
1951
  * @param {number} colIndex
1844
1952
  * @return {Function}
1845
1953
  */
1846
- RowFilteringPlugin.prototype._getFormatter = function (colIndex) {
1847
- var tfp = this._getPlugin("TextFormattingPlugin");
1848
- if (tfp) {
1849
- var formatter = tfp.getFormatter(colIndex);
1850
- if (formatter) {
1851
- return formatter.format || null;
1852
- }
1853
- }
1854
- return null;
1954
+ RowFilteringPlugin.prototype._getFormatter = function(colIndex) {
1955
+ let tfp = this._getPlugin("TextFormattingPlugin");
1956
+ if(tfp) {
1957
+ let formatter = tfp.getFormatter(colIndex);
1958
+ if(formatter) {
1959
+ return formatter.format || null;
1960
+ }
1961
+ }
1962
+ return null;
1855
1963
  };
1856
1964
  /** @private
1857
1965
  * @return {!FilterBuilder}
1858
1966
  */
1859
- RowFilteringPlugin._getFilterBuilder = function () {
1860
- if (!RowFilteringPlugin._filterBuilder) {
1861
- RowFilteringPlugin._filterBuilder = new FilterBuilder();
1862
- }
1863
- return RowFilteringPlugin._filterBuilder;
1967
+ RowFilteringPlugin._getFilterBuilder = function() {
1968
+ if(!RowFilteringPlugin._filterBuilder) {
1969
+ RowFilteringPlugin._filterBuilder = new FilterBuilder();
1970
+ }
1971
+ return RowFilteringPlugin._filterBuilder;
1864
1972
  };
1865
1973
 
1866
1974
  /** @public
1867
1975
  * @ignore
1868
1976
  * @param {*} val
1869
1977
  */
1870
- RowFilteringPlugin.prototype.mockDialogFilterChange = function (val) {
1871
- if (this._filterDialog) {
1872
- var arg = {
1873
- detail: {}
1874
- };
1875
- if (Array.isArray(val)) {
1876
- if (Array.isArray(val[0])) {
1877
- arg.detail.conditions = val;
1878
- } else {
1879
- arg.detail.value = val;
1880
- }
1881
- } else {
1882
- arg.detail.value = val;
1883
- }
1884
- this._onDialogFilterChanged(arg);
1885
- }
1978
+ RowFilteringPlugin.prototype.mockDialogFilterChange = function(val) {
1979
+ if(this._filterDialog) {
1980
+ let arg = {
1981
+ detail: {}
1982
+ };
1983
+ if(Array.isArray(val)) {
1984
+ if(Array.isArray(val[0])) {
1985
+ arg.detail.conditions = val;
1986
+ } else {
1987
+ arg.detail.value = val;
1988
+ }
1989
+ } else {
1990
+ arg.detail.value = val;
1991
+ }
1992
+ this._onDialogFilterChanged(arg);
1993
+ }
1886
1994
  };
1887
1995
  /** @private
1888
1996
  * @param {Object} e
1889
1997
  */
1890
- RowFilteringPlugin.prototype._onDialogFilterChanged = function (e) {
1891
- var colIndex = this._filterDialog._colIndex;
1892
- var cfo = this._getColumnFilterOption(colIndex);
1893
- var uniqueValues = cfo.uniqueValues; // Unique values have to be stored before the removal of the filter
1894
- var rawDataAccessor = cfo._rawDataAccessor;
1895
- var formattedDataAccessor = cfo._formattedDataAccessor;
1896
- var ctx = null;
1897
- if (rawDataAccessor || formattedDataAccessor) {
1898
- ctx = {
1899
- "rawDataAccessor": rawDataAccessor || null,
1900
- "formattedDataAccessor": formattedDataAccessor || null
1901
- };
1902
- }
1903
- this.removeColumnFilters(colIndex);
1904
-
1905
- // Check inputs from advanced filter UIs
1906
- var conditions = e.detail.conditions;
1907
- if (Array.isArray(conditions)) {
1908
- // Advanced condition filtering. Expecting 2D-Array
1909
- // Ensure rawValue input for number field data type
1910
- var condCount = conditions.length;
1911
- for (var m = 0; m < condCount; ++m) {
1912
- var cond = conditions[m];
1913
- var opDef = FilterOperators[cond[0]];
1914
- // string type has no need for formatted data or raw data. What is in display is the most important
1915
- if (opDef && opDef.type !== "string") {
1916
- var inputVal = cond[1]; // inputVal is hardcoded at index 1
1917
- var rawValues = uniqueValues[inputVal];
1918
- if (rawValues != null) {
1919
- cond[1] = rawValues[0];
1920
- }
1921
- }
1922
- }
1923
- if (ctx) {
1924
- ctx["_autoGenerated"] = true;
1925
- }
1926
- this.addColumnFilter(colIndex, conditions, ctx);
1927
- return;
1928
- }
1929
-
1930
- // Check input from free text input
1931
- var selVal = e.detail.value;
1932
- var selAry = null;
1933
- if (selVal) {
1934
- if (typeof selVal === "string") {
1935
- // Custom filter mode (free style text).
1936
- // WARNING: Free style text is no longer available anymore from the newer dialog
1937
- this.addColumnFilter(colIndex, selVal);
1938
- return;
1939
- } else {
1940
- selAry = /** @type{Array} */selVal; // Expecting Array of object
1941
- }
1942
- }
1943
-
1944
- var selCount = selAry ? selAry.length : 0;
1945
- if (!selCount) {
1946
- return;
1947
- }
1948
-
1949
- // The given input is from simple text filter selector
1950
- // Validate if the input is correct and prepare selected items for building filter
1951
- var itemMap = {};
1952
- var selectedItems = {};
1953
- var atLeastOne = false;
1954
- for (var i = 0; i < selCount; ++i) {
1955
- var formattedVal = selAry[i].title; // title is defined by the multi-select element
1956
- // let selIdx = selAry[i].index; // index cannot be used due to filtering
1957
- if (selAry[i].value === BLANKS) {
1958
- if (!ctx) {
1959
- ctx = {};
1960
- }
1961
- ctx.blankValues = true;
1962
- atLeastOne = true;
1963
- continue;
1964
- }
1965
- var rawVals = uniqueValues[formattedVal];
1966
- if (!rawVals) {
1967
- continue;
1968
- }
1969
- atLeastOne = true;
1970
- selectedItems[formattedVal] = true;
1971
- var jLen = rawVals.length;
1972
- for (var j = 0; j < jLen; ++j) {
1973
- itemMap[rawVals[j]] = true;
1974
- }
1975
- }
1976
- if (atLeastOne) {
1977
- this.addColumnFilter(colIndex, itemMap, ctx);
1978
- }
1979
- this._dispatch("dialogCommitted", {
1980
- "value": e.detail.value,
1981
- "fieldDataType": e.detail.fieldDataType,
1982
- "colIndex": colIndex
1983
- });
1998
+ RowFilteringPlugin.prototype._onDialogFilterChanged = function(e) {
1999
+ let colIndex = this._filterDialog._colIndex;
2000
+ let cfo = this._getColumnFilterOption(colIndex);
2001
+ let uniqueValues = cfo.uniqueValues; // Unique values have to be stored before the removal of the filter
2002
+ let rawDataAccessor = cfo._rawDataAccessor;
2003
+ let formattedDataAccessor = cfo._formattedDataAccessor;
2004
+ let ctx = null;
2005
+ if(rawDataAccessor || formattedDataAccessor) {
2006
+ ctx = {
2007
+ "rawDataAccessor": rawDataAccessor || null,
2008
+ "formattedDataAccessor": formattedDataAccessor || null
2009
+ };
2010
+ }
2011
+ this.removeColumnFilters(colIndex);
2012
+
2013
+ // Check inputs from advanced filter UIs
2014
+ let conditions = e.detail.conditions;
2015
+ if(Array.isArray(conditions)) { // Advanced condition filtering. Expecting 2D-Array
2016
+ // Ensure rawValue input for number field data type
2017
+ let condCount = conditions.length;
2018
+ for(let m = 0; m < condCount; ++m) {
2019
+ let cond = conditions[m];
2020
+ let opDef = FilterOperators[cond[0]];
2021
+ // string type has no need for formatted data or raw data. What is in display is the most important
2022
+ if(opDef && opDef.type !== "string") {
2023
+ let inputVal = cond[1]; // inputVal is hardcoded at index 1
2024
+ let rawValues = uniqueValues[inputVal];
2025
+ if(rawValues != null) {
2026
+ cond[1] = rawValues[0];
2027
+ }
2028
+ }
2029
+ }
2030
+
2031
+ if(ctx) {
2032
+ ctx["_autoGenerated"] = true;
2033
+ }
2034
+ this.addColumnFilter(colIndex, conditions, ctx);
2035
+ return;
2036
+ }
2037
+
2038
+ // Check input from free text input
2039
+ let selVal = e.detail.value;
2040
+ let selAry = null;
2041
+ if(selVal) {
2042
+ if(typeof selVal === "string") { // Custom filter mode (free style text).
2043
+ // WARNING: Free style text is no longer available anymore from the newer dialog
2044
+ this.addColumnFilter(colIndex, selVal);
2045
+ return;
2046
+ } else {
2047
+ selAry = /** @type{Array} */(selVal); // Expecting Array of object
2048
+ }
2049
+ }
2050
+
2051
+ let selCount = selAry ? selAry.length : 0;
2052
+ if(!selCount) { return; }
2053
+
2054
+ // The given input is from simple text filter selector
2055
+ // Validate if the input is correct and prepare selected items for building filter
2056
+ let itemMap = {};
2057
+ let selectedItems = {};
2058
+ let atLeastOne = false;
2059
+ for(let i = 0; i < selCount; ++i) {
2060
+ let formattedVal = selAry[i].title; // title is defined by the multi-select element
2061
+ // let selIdx = selAry[i].index; // index cannot be used due to filtering
2062
+ if(selAry[i].value === BLANKS) {
2063
+ if(!ctx) {
2064
+ ctx = {};
2065
+ }
2066
+ ctx.blankValues = true;
2067
+ atLeastOne = true;
2068
+ continue;
2069
+ }
2070
+ let rawVals = uniqueValues[formattedVal];
2071
+ if(!rawVals) {
2072
+ continue;
2073
+ }
2074
+ atLeastOne = true;
2075
+ selectedItems[formattedVal] = true;
2076
+
2077
+ let jLen = rawVals.length;
2078
+ for(let j = 0; j < jLen; ++j) {
2079
+ itemMap[rawVals[j]] = true;
2080
+ }
2081
+ }
2082
+ if(atLeastOne) {
2083
+ this.addColumnFilter(colIndex, itemMap, ctx);
2084
+ }
2085
+ this._dispatch("dialogCommitted", {
2086
+ "value": e.detail.value,
2087
+ "fieldDataType": e.detail.fieldDataType,
2088
+ "colIndex": colIndex
2089
+ });
1984
2090
  };
1985
2091
 
1986
2092
  /** @public
1987
2093
  * @ignore
1988
2094
  * @param {string} sortOrder
1989
2095
  */
1990
- RowFilteringPlugin.prototype.mockDialogSortChange = function (sortOrder) {
1991
- if (this._filterDialog) {
1992
- var arg = {
1993
- detail: {}
1994
- };
1995
- arg.detail.value = sortOrder;
1996
- this._onDialogSortChanged(arg);
1997
- }
2096
+ RowFilteringPlugin.prototype.mockDialogSortChange = function(sortOrder) {
2097
+ if(this._filterDialog) {
2098
+ let arg = {
2099
+ detail: {}
2100
+ };
2101
+ arg.detail.value = sortOrder;
2102
+ this._onDialogSortChanged(arg);
2103
+ }
1998
2104
  };
1999
2105
  /** @private
2000
2106
  * @param {Object} e
2001
2107
  */
2002
- RowFilteringPlugin.prototype._onDialogSortChanged = function (e) {
2003
- var stp = this._getPlugin("SortableTitlePlugin");
2004
- if (stp) {
2005
- var colIndex = this._filterDialog._colIndex;
2006
- var eDetail = e.detail.value ? e.detail.value : e.detail;
2007
- if (stp.getSortOrder(colIndex) === eDetail) {
2008
- stp.sortColumn(colIndex, "n");
2009
- } else {
2010
- stp.sortColumn(colIndex, eDetail);
2011
- }
2012
- this._dispatch("dialogCommitted", {
2013
- "sortOrder": e.detail.value,
2014
- "colIndex": colIndex
2015
- });
2016
- }
2108
+ RowFilteringPlugin.prototype._onDialogSortChanged = function(e) {
2109
+ let stp = this._getPlugin("SortableTitlePlugin");
2110
+ if(stp) {
2111
+ let colIndex = this._filterDialog._colIndex;
2112
+ let eDetail = e.detail.value ? e.detail.value : e.detail;
2113
+
2114
+ if(stp.getSortOrder(colIndex) === eDetail) {
2115
+ stp.sortColumn(colIndex, "n");
2116
+ } else {
2117
+ stp.sortColumn(colIndex, eDetail);
2118
+ }
2119
+ this._dispatch("dialogCommitted", {
2120
+ "sortOrder": e.detail.value,
2121
+ "colIndex": colIndex
2122
+ });
2123
+ }
2017
2124
  };
2018
2125
  /** @private
2019
2126
  * @param {Object} e
2020
2127
  */
2021
- RowFilteringPlugin.prototype._onColumnAdded = function (e) {
2022
- if (e["context"]) {
2023
- var hasFilter = this._setColumnOptions(e["colIndex"], e["context"]);
2024
- if (hasFilter) {
2025
- this._applyPendingFilter();
2026
- }
2027
- }
2128
+ RowFilteringPlugin.prototype._onColumnAdded = function(e) {
2129
+ if(e["context"]) {
2130
+ let hasFilter = this._setColumnOptions(e["colIndex"], e["context"]);
2131
+
2132
+ if(hasFilter) {
2133
+ this._applyPendingFilter();
2134
+ }
2135
+ }
2028
2136
  };
2029
2137
  /** @private
2030
2138
  * @param {Object} e
2031
2139
  */
2032
- RowFilteringPlugin.prototype._onColumnRemoved = function (e) {
2033
- var colData = /** @type{Object} */e.columnData;
2034
- if (!colData) {
2035
- return;
2036
- }
2037
- var crf = colData["rowFiltering"];
2038
- var cfo = crf["filterOption"];
2039
- if (cfo) {
2040
- var funcIndex = this._columnFilters.indexOf(cfo);
2041
- if (funcIndex >= 0) {
2042
- this._columnFilters.splice(funcIndex, 1);
2043
- }
2044
- this._dispatch("filterChanged", {
2045
- "filterType": "column",
2046
- "changeType": "remove",
2047
- "colIndex": e.colIndex,
2048
- "field": cfo._field || ""
2049
- });
2050
- this._requestFilterRefresh();
2051
- }
2140
+ RowFilteringPlugin.prototype._onColumnRemoved = function(e) {
2141
+ let colData = /** @type{Object} */(e.columnData);
2142
+ if(!colData) { return; }
2143
+
2144
+ let crf = colData["rowFiltering"];
2145
+ let cfo = crf["filterOption"];
2146
+ if(cfo) {
2147
+ let funcIndex = this._columnFilters.indexOf(cfo);
2148
+ if(funcIndex >= 0) {
2149
+ this._columnFilters.splice(funcIndex, 1);
2150
+ }
2151
+
2152
+ this._dispatch("filterChanged", {
2153
+ "filterType": "column",
2154
+ "changeType": "remove",
2155
+ "colIndex": e.colIndex,
2156
+ "field": cfo._field || ""
2157
+ });
2158
+
2159
+ this._requestFilterRefresh();
2160
+ }
2052
2161
  };
2053
2162
 
2054
2163
  /** the filter will automatically hide empty segment when all of its member are filtered out. If there is no active filter, any empty segment will not be hidden. Collapsed segment does not count as having a filter. A segment with no child is treated the same way as an empty segment.
@@ -2056,22 +2165,25 @@ RowFilteringPlugin.prototype._onColumnRemoved = function (e) {
2056
2165
  * @param {boolean=} enabled=true
2057
2166
  */
2058
2167
  RowFilteringPlugin.prototype.enableEmptySegmentFiltering = function (enabled) {
2059
- var host = this._hosts[0];
2060
- var dv = host ? host.getDataSource() : null;
2061
- if (dv && dv.enableEmptySegmentFiltering) {
2062
- dv.enableEmptySegmentFiltering(enabled);
2063
- }
2168
+ let host = this._hosts[0];
2169
+ let dv = host ? host.getDataSource() : null;
2170
+ if(dv && dv.enableEmptySegmentFiltering) {
2171
+ dv.enableEmptySegmentFiltering(enabled);
2172
+ }
2064
2173
  };
2065
2174
  /** the filter will automatically hide empty segment when all of its member are filtered out. If there is no active filter, any empty segment will not be hidden. Collapsed segment does not count as having a filter.
2066
2175
  * @public
2067
2176
  * @param {boolean=} enabled=true
2068
2177
  */
2069
2178
  RowFilteringPlugin.prototype.enableSeparatorFiltering = function (enabled) {
2070
- var host = this._hosts[0];
2071
- var dv = host ? host.getDataSource() : null;
2072
- if (dv && dv.enableSeparatorFiltering) {
2073
- dv.enableSeparatorFiltering(enabled);
2074
- }
2179
+ let host = this._hosts[0];
2180
+ let dv = host ? host.getDataSource() : null;
2181
+ if(dv && dv.enableSeparatorFiltering) {
2182
+ dv.enableSeparatorFiltering(enabled);
2183
+ }
2075
2184
  };
2185
+
2186
+
2187
+
2076
2188
  export default RowFilteringPlugin;
2077
- export { RowFilteringPlugin, RowFilteringPlugin as RowFiltering, RowFilteringPlugin as RowFilteringExtension };
2189
+ export { RowFilteringPlugin, RowFilteringPlugin as RowFiltering, RowFilteringPlugin as RowFilteringExtension };