@syncfusion/ej2-grids
Version:
Feature-rich JavaScript datagrid (datatable) control with built-in support for editing, filtering, grouping, paging, sorting, and exporting to Excel.
1,004 lines • 103 kB
JavaScript
/* tslint:disable-next-line:max-line-length */
import { EventHandler, isNullOrUndefined, extend, classList, addClass, removeClass, Browser, getValue, setValue } from '@syncfusion/ej2-base';
import { parentsUntil, getUid, appendChildren, getDatePredicate, getObject, extendObjWithFn, eventPromise, setChecked, clearReactVueTemplates, padZero, Global } from '../base/util';
import { remove, debounce, Internationalization, SanitizeHtmlHelper } from '@syncfusion/ej2-base';
import { DataUtil, Query, DataManager, Predicate } from '@syncfusion/ej2-data';
import { createCheckBox } from '@syncfusion/ej2-buttons';
import * as events from '../base/constant';
import { ValueFormatter } from '../services/value-formatter';
import { getForeignData, resetDialogAppend } from '../base/util';
import { Dialog } from '@syncfusion/ej2-popups';
import { Input } from '@syncfusion/ej2-inputs';
import { createSpinner, hideSpinner, showSpinner } from '@syncfusion/ej2-popups';
import { getFilterMenuPostion, toogleCheckbox, createCboxWithWrap, removeAddCboxClasses, getColumnByForeignKeyValue, getListHeight, infiniteRemoveElements, infiniteAppendElements } from '../base/util';
/**
* @hidden
* `CheckBoxFilterBase` module is used to handle filtering action.
*/
var CheckBoxFilterBase = /** @class */ (function () {
/**
* Constructor for checkbox filtering module
*
* @param {IXLFilter} parent - specifies the IXLFilter
* @hidden
*/
function CheckBoxFilterBase(parent) {
this.searchInputArgs = null;
this.isExecuteLocal = false;
this.queryFilteredColumn = [];
this.existingPredicate = {};
this.foreignKeyQuery = new Query();
/** @hidden */
this.filterState = true;
this.values = {};
this.renderEmpty = false;
this.isCheckboxFilterTemplate = false;
this.infiniteRenderMod = false;
// for infinite scroll ui
this.infiniteInitialLoad = false;
this.infiniteSearchValChange = false;
this.infinitePermenantLocalData = [];
this.infiniteQueryExecutionPending = false;
this.infiniteSkipCnt = 0;
this.infiniteScrollAppendDiff = 0;
this.prevInfiniteScrollDirection = '';
this.infiniteLoadedElem = [];
this.infiniteDataCount = 0;
this.infiniteLocalSelectAll = true;
this.localInfiniteSelectAllClicked = false;
this.localInfiniteSelectionInteracted = false;
this.infiniteManualSelectMaintainPred = [];
this.parent = parent;
this.id = this.parent.element.id;
this.valueFormatter = new ValueFormatter(this.parent.locale);
this.cBoxTrue = createCheckBox(this.parent.createElement, false, { checked: true, label: ' ' });
this.cBoxFalse = createCheckBox(this.parent.createElement, false, { checked: false, label: ' ' });
this.cBoxTrue.insertBefore(this.parent.createElement('input', {
className: 'e-chk-hidden', attrs: { type: 'checkbox' }
}), this.cBoxTrue.firstChild);
this.cBoxFalse.insertBefore(this.parent.createElement('input', {
className: 'e-chk-hidden', attrs: { 'type': 'checkbox' }
}), this.cBoxFalse.firstChild);
this.cBoxFalse.querySelector('.e-frame').classList.add('e-uncheck');
if (this.parent.enableRtl) {
addClass([this.cBoxTrue, this.cBoxFalse], ['e-rtl']);
}
if (this.parent.cssClass) {
if (this.parent.cssClass.indexOf(' ') !== -1) {
addClass([this.cBoxTrue, this.cBoxFalse], this.parent.cssClass.split(' '));
}
else {
addClass([this.cBoxTrue, this.cBoxFalse], [this.parent.cssClass]);
}
}
}
/**
* @returns {void}
* @hidden
*/
CheckBoxFilterBase.prototype.destroy = function () {
this.closeDialog();
};
CheckBoxFilterBase.prototype.wireEvents = function () {
EventHandler.add(this.dlg, 'click', this.clickHandler, this);
EventHandler.add(this.dlg, 'keyup', this.keyupHandler, this);
this.searchHandler = debounce(this.searchBoxKeyUp, 200);
var elem = this.dialogObj.element.querySelector('.e-searchinput');
if (elem) {
EventHandler.add(elem, 'keyup', this.searchHandler, this);
EventHandler.add(elem, 'input', this.searchHandler, this);
}
};
CheckBoxFilterBase.prototype.unWireEvents = function () {
EventHandler.remove(this.dlg, 'click', this.clickHandler);
EventHandler.remove(this.dlg, 'keyup', this.keyupHandler);
var elem = this.dialogObj.element.querySelector('.e-searchinput');
if (elem) {
EventHandler.remove(elem, 'keyup', this.searchHandler);
EventHandler.remove(elem, 'input', this.searchHandler);
}
};
CheckBoxFilterBase.prototype.foreignKeyFilter = function (args, fColl, mPredicate) {
var _this = this;
var fPredicate = {};
var filterCollection = [];
var query = this.foreignKeyQuery.clone();
this.options.column.dataSource.
executeQuery(query.where(mPredicate)).then(function (e) {
_this.options.column.columnData = e.result;
_this.parent.notify(events.generateQuery, { predicate: fPredicate, column: _this.options.column });
args.ejpredicate = fPredicate.predicate.predicates;
var fpred = fPredicate.predicate.predicates;
for (var i = 0; i < fpred.length; i++) {
filterCollection.push({
field: fpred[parseInt(i.toString(), 10)].field,
predicate: 'or',
matchCase: fpred[parseInt(i.toString(), 10)].ignoreCase,
ignoreAccent: fpred[parseInt(i.toString(), 10)].ignoreAccent,
operator: fpred[parseInt(i.toString(), 10)].operator,
value: fpred[parseInt(i.toString(), 10)].value,
type: _this.options.type
});
}
args.filterCollection = filterCollection.length ? filterCollection :
fColl.filter(function (col) { return col.field = _this.options.field; });
_this.options.handler(args);
});
};
CheckBoxFilterBase.prototype.searchBoxClick = function (e) {
var target = e.target;
if (target.classList.contains('e-searchclear')) {
this.sInput.value = target.classList.contains('e-chkcancel-icon') ? '' : this.sInput.value;
if (this.isCheckboxFilterTemplate) {
this.parent.notify('refreshCheckbox', { event: e });
}
else {
this.refreshCheckboxes();
}
this.updateSearchIcon();
this.sInput.focus();
}
};
CheckBoxFilterBase.prototype.searchBoxKeyUp = function (e) {
if (isNullOrUndefined(this.sInput)) {
return;
}
if (isNullOrUndefined(e) || (e.key !== 'ArrowUp' && e.key !== 'ArrowDown' && e.key !== 'Tab' && !(e.key === 'Tab' && e.shiftKey))) {
if (!isNullOrUndefined(this.parent.loadingIndicator) && this.parent.loadingIndicator.indicatorType === 'Shimmer') {
this.parent.showMaskRow(undefined, this.dialogObj.element);
}
if (this.isCheckboxFilterTemplate) {
this.parent.notify('refreshCheckbox', { event: e });
}
else {
this.refreshCheckboxes();
}
this.updateSearchIcon();
}
};
CheckBoxFilterBase.prototype.updateSearchIcon = function () {
if (this.sInput.value.length) {
classList(this.sIcon, ['e-chkcancel-icon'], ['e-search-icon']);
if (!isNullOrUndefined(document.body.querySelector('.e-chkcancel-icon'))) {
document.body.querySelector('.e-chkcancel-icon').setAttribute('title', this.localeObj.getConstant('Clear'));
}
}
else {
classList(this.sIcon, ['e-search-icon'], ['e-chkcancel-icon']);
if (!isNullOrUndefined(document.body.querySelector('.e-searchclear.e-search-icon'))) {
document.body.querySelector('.e-searchclear.e-search-icon').setAttribute('title', this.localeObj.getConstant('Search'));
}
}
};
/**
* Gets the localized label by locale keyword.
*
* @param {string} key - Defines localization key
* @returns {string} - returns localization label
*/
CheckBoxFilterBase.prototype.getLocalizedLabel = function (key) {
return this.localeObj.getConstant(key);
};
CheckBoxFilterBase.prototype.updateDataSource = function () {
var dataSource = this.options.dataSource;
var str = 'object';
if (!(dataSource instanceof DataManager)) {
for (var i = 0; i < dataSource.length; i++) {
// eslint-disable-next-line valid-typeof
if (typeof dataSource !== str) {
var obj = {};
obj[this.options.field] = dataSource[parseInt(i.toString(), 10)];
dataSource[parseInt(i.toString(), 10)] = obj;
}
}
}
};
CheckBoxFilterBase.prototype.updateModel = function (options) {
this.options = options;
this.existingPredicate = options.actualPredicate || {};
this.options.dataSource = options.dataSource;
this.options.dataManager = options.dataManager ? options.dataManager : options.dataSource;
this.updateDataSource();
this.options.type = options.type;
this.options.format = options.format || '';
this.options.ignoreAccent = options.ignoreAccent || false;
this.options.filteredColumns = options.filteredColumns || this.parent.filterSettings.columns;
this.options.query = options.query || new Query();
this.options.allowCaseSensitive = options.allowCaseSensitive || false;
this.options.uid = options.column.uid;
this.options.disableHtmlEncode = options.column.disableHtmlEncode || false;
this.values = {};
this.localeObj = options.localeObj;
this.isFiltered = options.filteredColumns.length;
this.infiniteRenderMod = this.parent.filterSettings && this.parent.filterSettings.enableInfiniteScrolling ? true : false;
this.infiniteUnloadParentExistPred = this.infiniteRenderMod && this.existingPredicate[this.options.column.field] ? this.existingPredicate[this.options.column.field].slice() : [];
};
CheckBoxFilterBase.prototype.getAndSetChkElem = function (options) {
this.dlg = this.parent.createElement('div', {
id: this.id + this.options.type + '_excelDlg',
attrs: { uid: this.options.column.uid },
className: 'e-checkboxfilter e-filter-popup'
});
this.sBox = this.parent.createElement('div', { className: 'e-searchcontainer' });
if (!options.hideSearchbox) {
this.sInput = this.parent.createElement('input', {
id: this.id + '_SearchBox',
className: 'e-searchinput'
});
this.sIcon = this.parent.createElement('span', {
className: 'e-searchclear e-search-icon e-icons e-input-group-icon', attrs: {
type: 'text', title: this.getLocalizedLabel('Search')
}
});
this.searchBox = this.parent.createElement('span', { className: 'e-searchbox e-fields' });
this.searchBox.appendChild(this.sInput);
this.sBox.appendChild(this.searchBox);
this.searchInputArgs = {
element: this.sInput, floatLabelType: 'Never', properties: {
placeholder: this.getLocalizedLabel('Search'),
cssClass: this.parent.cssClass
}
};
Input.createInput(this.searchInputArgs, this.parent.createElement);
this.searchBox.querySelector('.e-input-group').appendChild(this.sIcon);
}
this.spinner = this.parent.createElement('div', { className: 'e-spinner' }); //for spinner
this.cBox = this.parent.createElement('div', {
id: this.id + this.options.type + '_CheckBoxList',
className: 'e-checkboxlist e-fields'
});
this.spinner.appendChild(this.cBox);
this.sBox.appendChild(this.spinner);
return this.sBox;
};
CheckBoxFilterBase.prototype.showDialog = function (options) {
var args = {
requestType: events.filterBeforeOpen,
columnName: this.options.field, columnType: this.options.type, cancel: false
};
var filterModel = 'filterModel';
args["" + filterModel] = this;
this.parent.notify(events.cBoxFltrBegin, args);
if (args.cancel) {
options.cancel = args.cancel;
return;
}
this.dialogObj = new Dialog({
visible: false, content: this.sBox,
close: this.closeDialog.bind(this),
enableRtl: this.parent.enableRtl,
width: (!isNullOrUndefined(parentsUntil(options.target, 'e-bigger')))
|| this.parent.element.classList.contains('e-device') ? 260 : 255,
target: this.parent.element, animationSettings: { effect: 'None' },
buttons: [{
click: this.btnClick.bind(this),
buttonModel: {
content: this.getLocalizedLabel(this.isExcel ? 'OKButton' : 'FilterButton'),
cssClass: this.parent.cssClass ? 'e-primary' + ' ' + this.parent.cssClass : 'e-primary',
isPrimary: true
}
},
{
click: this.btnClick.bind(this),
buttonModel: { cssClass: this.parent.cssClass ? 'e-flat' + ' ' + this.parent.cssClass : 'e-flat',
content: this.getLocalizedLabel(this.isExcel ? 'CancelButton' : 'ClearButton') }
}],
created: this.dialogCreated.bind(this),
open: this.dialogOpen.bind(this),
cssClass: this.parent.cssClass ? this.parent.cssClass : ''
});
var isStringTemplate = 'isStringTemplate';
this.dialogObj["" + isStringTemplate] = true;
this.renderResponsiveFilter(options);
var dialogLabel = this.parent.filterSettings && this.parent.filterSettings.type === 'CheckBox' ?
this.getLocalizedLabel('CheckBoxFilterDialogARIA') : this.getLocalizedLabel('ExcelFilterDialogARIA');
this.dlg.setAttribute('aria-label', dialogLabel);
if (options.isResponsiveFilter) {
var responsiveCnt = document.querySelector('.e-responsive-dialog > .e-dlg-content > .e-mainfilterdiv');
responsiveCnt.appendChild(this.dlg);
}
else {
this.parent.element.appendChild(this.dlg);
}
this.dialogObj.appendTo(this.dlg);
this.dialogObj.element.style.maxHeight = options.isResponsiveFilter ? 'none' : this.options.height + 'px';
this.dialogObj.show();
if (this.parent && this.parent.filterSettings && (this.parent.filterSettings.type === 'CheckBox'
|| (this.options.column && this.options.column.filter && this.options.column.filter.type === 'CheckBox')) &&
this.parent.getContent().firstElementChild.offsetHeight < this.dialogObj.element.offsetHeight &&
!parentsUntil(this.parent.element, 'e-gantt-dialog')) {
resetDialogAppend(this.parent, this.dialogObj);
}
var content = this.dialogObj.element.querySelector('.e-dlg-content');
content.appendChild(this.sBox);
this.wireEvents();
if (!this.parent.enableAdaptiveUI) {
if (!isNullOrUndefined(this.parent.loadingIndicator) && this.parent.loadingIndicator.indicatorType === 'Shimmer'
&& !this.infiniteRenderMod) {
this.parent.showMaskRow(undefined, this.dialogObj.element);
}
if (this.infiniteRenderMod && this.parent.filterSettings && this.parent.filterSettings.loadingIndicator === 'Shimmer') {
this.showMask();
}
}
else {
if (this.infiniteRenderMod && this.parent.filterSettings && this.parent.filterSettings.loadingIndicator === 'Shimmer') {
this.getAllData();
return;
}
if (this.infiniteRenderMod) {
this.cBox.style.marginTop = getListHeight(this.cBox) + 'px';
}
}
if (!(this.infiniteRenderMod && this.parent.filterSettings && this.parent.filterSettings.loadingIndicator === 'Shimmer')) {
createSpinner({ target: this.spinner, cssClass: this.parent.cssClass ? this.parent.cssClass : null }, this.parent.createElement);
showSpinner(this.spinner);
}
this.getAllData();
};
CheckBoxFilterBase.prototype.renderResponsiveFilter = function (options) {
if (options.isResponsiveFilter) {
this.dialogObj.buttons = [{}];
this.dialogObj.position = { X: '', Y: '' };
this.dialogObj.target = document.querySelector('.e-resfilter > .e-dlg-content > .e-mainfilterdiv');
this.dialogObj.width = '100%';
}
};
CheckBoxFilterBase.prototype.dialogCreated = function (e) {
if (this.options.isResponsiveFilter) {
this.dialogObj.element.style.left = '0px';
}
else {
if (!Browser.isDevice) {
getFilterMenuPostion(this.options.target, this.dialogObj);
}
else {
this.dialogObj.position = { X: 'center', Y: 'center' };
}
}
if (this.options.column.showColumnMenu) {
this.parent.notify(events.filterDialogCreated, e);
}
};
CheckBoxFilterBase.prototype.openDialog = function (options) {
this.updateModel(options);
this.getAndSetChkElem(options);
this.showDialog(options);
};
CheckBoxFilterBase.prototype.closeDialog = function () {
if (this.infiniteRenderMod && this.infinitePermenantLocalData.length && !this.options.isRemote) {
this.options.dataSource.dataSource.json = this.infinitePermenantLocalData;
}
if (this.dialogObj && !this.dialogObj.isDestroyed) {
this.isBlanks = false;
var filterTemplateCol = this.options.columns.filter(function (col) { return col.getFilterItemTemplate(); });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
var registeredTemplate = this.parent.registeredTemplate;
if (filterTemplateCol.length && !isNullOrUndefined(registeredTemplate) && registeredTemplate.filterItemTemplate) {
this.parent.destroyTemplate(['filterItemTemplate']);
}
if ((this.parent.isReact || this.parent.isVue) && this.parent.destroyTemplate !== undefined) {
clearReactVueTemplates(this.parent, ['filterItemTemplate']);
}
this.parent.notify(events.filterMenuClose, { field: this.options.field });
this.unWireEvents();
if (this.searchInputArgs && this.searchInputArgs.element && this.searchInputArgs.element.parentElement) {
Input.destroy(this.searchInputArgs);
remove(this.searchInputArgs.element);
}
this.searchInputArgs = null;
this.sInput = null;
if (this.parent.isReact && this.options.column.filter && typeof (this.options.column.filter.itemTemplate) !== 'string'
&& (this.options.column.filter.type === 'CheckBox' || this.options.column.filter.type === 'Excel')) {
this.dialogObj.element.querySelector('.e-dlg-content').innerHTML = '';
}
this.dialogObj.destroy();
if (this.dialogObj['dlgClosedBy'] === 'escape') {
this.parent.isColumnMenuFilterClosing = true;
}
if (this.dlg && this.dlg.parentElement) {
remove(this.dlg);
var gridPopup = document.getElementById(this.parent.element.id + '_e-popup');
if (!isNullOrUndefined(gridPopup)) {
remove(gridPopup);
gridPopup = null;
}
}
this.dlg = null;
this.parent.notify(events.filterDialogClose, {});
}
};
/**
* @param {Column} col - Defines column details
* @returns {void}
* @hidden
*/
CheckBoxFilterBase.prototype.clearFilter = function (col) {
// eslint-disable-next-line max-len
var args = { instance: this, handler: this.clearFilter, cancel: false };
this.parent.notify(events.fltrPrevent, args);
if (args.cancel) {
return;
}
this.options.handler({ action: 'clear-filter', field: col ? col.field : this.options.field });
};
CheckBoxFilterBase.prototype.btnClick = function (e) {
if (this.filterState) {
if ((e.target.tagName.toLowerCase() === 'input' && e.target.classList.contains('e-searchinput')) ||
e.keyCode === 13) {
if (!this.isCheckboxFilterTemplate) {
this.fltrBtnHandler();
}
}
else {
var text = e.target.firstChild.textContent.toLowerCase();
if (this.getLocalizedLabel(this.isExcel ? 'OKButton' : 'FilterButton').toLowerCase() === text) {
if (!this.isCheckboxFilterTemplate) {
this.fltrBtnHandler();
}
}
else if (this.getLocalizedLabel('ClearButton').toLowerCase() === text) {
this.clearFilter();
}
}
this.closeDialog();
}
else if (e.target && e.target.firstChild &&
e.target.firstChild.textContent.toLowerCase() === this.getLocalizedLabel('CancelButton').toLowerCase()) {
this.closeDialog();
}
else if (!(e.target.tagName.toLowerCase() === 'input')) {
this.clearFilter();
this.closeDialog();
}
if (this.options.column.showColumnMenu) {
this.parent.notify(events.afterFilterColumnMenuClose, {});
}
if (!isNullOrUndefined(this.parent.focusModule)) {
this.parent.focusModule.filterfocus();
}
};
/**
* @returns {void}
* @hidden
*/
CheckBoxFilterBase.prototype.fltrBtnHandler = function () {
var _this = this;
if (this.infiniteRenderMod) {
this.cBox.innerHTML = '';
appendChildren(this.cBox, this.infiniteLoadedElem.slice());
}
var checked = [].slice.call(this.cBox.querySelectorAll('.e-check:not(.e-selectall):not(.e-add-current)'));
var check = checked;
var optr = 'equal';
var ddlValue = this.dialogObj.element.querySelector('.e-dropdownlist');
if (ddlValue) {
this.options.operator = optr = ddlValue.ej2_instances[0].value;
}
this.isMenuNotEqual = this.options.operator === 'notequal';
var searchInput;
if (!this.options.hideSearchbox) {
searchInput = this.searchBox.querySelector('.e-searchinput');
}
var caseSen = this.options.allowCaseSensitive;
var defaults = {
field: this.options.field, predicate: this.isMenuNotEqual ? 'and' : 'or', uid: this.options.uid,
operator: optr, type: this.options.type, matchCase: caseSen, ignoreAccent: this.options.ignoreAccent
};
var isNotEqual = this.itemsCnt !== checked.length && this.itemsCnt - checked.length < checked.length;
if (isNotEqual && searchInput && searchInput.value === '') {
optr = this.isMenuNotEqual ? 'equal' : 'notequal';
checked = [].slice.call(this.cBox.querySelectorAll('.e-uncheck:not(.e-selectall)'));
defaults.predicate = this.isMenuNotEqual ? 'or' : 'and';
defaults.operator = optr;
}
var val;
var length;
var coll = [];
if ((checked.length !== this.itemsCnt || (searchInput && searchInput.value && searchInput.value !== ''))
|| this.infiniteRenderMod) {
if (!this.infiniteRenderMod) {
coll = this.complexQueryPredicate(checked, defaults, isNotEqual);
if (isNullOrUndefined(coll)) {
return;
}
coll = this.filterPreventColumns ? this.filterPreventColumns : coll;
}
else if (this.infiniteRenderMod &&
(!this.infiniteSearchPred || (this.infiniteSearchPred && !this.infiniteSearchPred.isComplex))) {
this.infiniteFltrBtnHandler(coll);
}
else {
if (this.infiniteSearchPred.isComplex) {
coll = this.complexQueryPredicate(checked, defaults, isNotEqual);
}
}
if ((this.options.type === 'date' || this.options.type === 'datetime') && check.length) {
length = check.length - 1;
val = this.values[parentsUntil(check[parseInt(length.toString(), 10)], 'e-ftrchk').getAttribute('uid')];
if (isNullOrUndefined(val) && isNotEqual) {
coll.push({
field: defaults.field, matchCase: defaults.matchCase, operator: 'equal',
predicate: 'or', value: null
});
}
}
var addCurrSelection = this.infiniteRenderMod ? this.sBox.querySelector('.e-add-current') :
this.cBox.querySelector('.e-add-current');
if (addCurrSelection && addCurrSelection.classList.contains('e-check')) {
var existingPredicate_1 = this.existingPredicate[this.options.field];
if (existingPredicate_1) {
var _loop_1 = function (j) {
if (!coll.some(function (data) {
return data
.value === existingPredicate_1[parseInt(j.toString(), 10)].value;
})) {
coll.push(existingPredicate_1[parseInt(j.toString(), 10)]);
}
};
for (var j = 0; j < existingPredicate_1.length; j++) {
_loop_1(j);
}
}
else {
return;
}
}
if (!this.infiniteRenderMod) {
this.initiateFilter(coll);
}
else if (coll.length) {
this.initiateFilter(coll);
}
else if (this.sBox.querySelector('.e-selectall').classList.contains('e-check') && !coll.length) {
var isClearFilter = this.options.filteredColumns.some(function (value) {
return _this.options.field === value.field;
});
if (isClearFilter) {
this.clearFilter();
}
}
}
else {
var isClearFilter = this.options.filteredColumns.some(function (value) {
return _this.options.field === value.field;
});
if (isClearFilter) {
this.clearFilter();
}
}
};
CheckBoxFilterBase.prototype.complexQueryPredicate = function (checkBoxChecked, defaults, isNotEqual) {
var value;
var fObj;
var coll = [];
for (var i = 0; i < checkBoxChecked.length; i++) {
value = this.values[parentsUntil(checkBoxChecked[parseInt(i.toString(), 10)], 'e-ftrchk').getAttribute('uid')];
fObj = extend({}, { value: value }, defaults);
if (value && !value.toString().length) {
fObj.operator = isNotEqual ? 'notequal' : 'equal';
}
if (value === '' || isNullOrUndefined(value)) {
coll = coll.concat(CheckBoxFilterBase.generateNullValuePredicates(defaults));
}
else {
coll.push(fObj);
}
}
var filterColumns = this.filterPreventColumns && this.filterPreventColumns.length ?
this.filterPreventColumns[0] : fObj;
if (filterColumns && !this.notifyFilterPrevEvent(filterColumns)) {
this.filterPreventColumns = coll;
return null;
}
else {
return coll;
}
};
CheckBoxFilterBase.prototype.infiniteFltrBtnHandler = function (coll) {
var value;
if (this.infiniteManualSelectMaintainPred.length) {
for (var i = 0; i < this.infiniteManualSelectMaintainPred.length; i++) {
var pred = this.infiniteManualSelectMaintainPred[i];
value = pred.value + '';
if (value === '' || isNullOrUndefined(value)) {
var dummyDefaults = { predicate: pred.predicate, field: pred.field, type: pred.type, uid: pred.uid, operator: pred.operator,
matchCase: pred.matchCase, ignoreAccent: pred.ignoreAccent };
coll.push.apply(coll, CheckBoxFilterBase.generateNullValuePredicates(dummyDefaults));
}
else {
coll.push(this.infiniteManualSelectMaintainPred[i]);
}
this.notifyFilterPrevEvent(this.infiniteManualSelectMaintainPred[i]);
}
}
if (!this.localInfiniteSelectAllClicked && this.sInput.value === '' && !(!this.options.parentCurrentViewDataCount && coll.length)) {
for (var i = 0; i < this.infiniteUnloadParentExistPred.length; i++) {
coll.unshift(this.infiniteUnloadParentExistPred[i]);
this.notifyFilterPrevEvent(this.existingPredicate[this.options.field][i]);
}
}
if (this.sInput.value !== '' && (!this.localInfiniteSelectAllClicked || this.infiniteLocalSelectAll)) {
this.infiniteSearchPred['predicate'] = 'or';
coll.unshift(this.infiniteSearchPred);
this.notifyFilterPrevEvent(this.infiniteSearchPred);
}
};
CheckBoxFilterBase.prototype.notifyFilterPrevEvent = function (predicate) {
var args = {
instance: this, handler: this.fltrBtnHandler, arg1: predicate.field, arg2: predicate.predicate, arg3: predicate.operator,
arg4: predicate.matchCase, arg5: predicate.ignoreAccent, arg6: predicate.value, cancel: false
};
this.parent.notify(events.fltrPrevent, args);
if (args.cancel) {
return false;
}
return true;
};
// eslint-disable-next-line
/** @hidden */
CheckBoxFilterBase.generateNullValuePredicates = function (defaults) {
var coll = [];
if (defaults.type === 'string') {
coll.push({
field: defaults.field, ignoreAccent: defaults.ignoreAccent, matchCase: defaults.matchCase,
operator: defaults.operator, predicate: defaults.predicate, value: ''
});
}
coll.push({
field: defaults.field,
matchCase: defaults.matchCase, operator: defaults.operator, predicate: defaults.predicate, value: null
});
coll.push({
field: defaults.field, matchCase: defaults.matchCase, operator: defaults.operator,
predicate: defaults.predicate, value: undefined
});
return coll;
};
// eslint-disable-next-line
/** @hidden */
CheckBoxFilterBase.prototype.initiateFilter = function (fColl) {
var firstVal = fColl[0];
var predicate;
if (!isNullOrUndefined(firstVal)) {
predicate = firstVal.ejpredicate ? firstVal.ejpredicate :
new Predicate(firstVal.field, firstVal.operator, firstVal.value, !firstVal.matchCase, firstVal.ignoreAccent);
for (var j = 1; j < fColl.length; j++) {
predicate = fColl[parseInt(j.toString(), 10)].ejpredicate !== undefined ?
predicate[fColl[parseInt(j.toString(), 10)].predicate](fColl[parseInt(j.toString(), 10)].ejpredicate) :
predicate[fColl[parseInt(j.toString(), 10)].predicate](fColl[parseInt(j.toString(), 10)].field, fColl[parseInt(j.toString(), 10)].operator, fColl[parseInt(j.toString(), 10)].value, !fColl[parseInt(j.toString(), 10)].matchCase, fColl[parseInt(j.toString(), 10)].ignoreAccent);
}
var args = {
action: 'filtering', filterCollection: fColl, field: this.options.field,
ejpredicate: Predicate.or(predicate)
};
this.options.handler(args);
}
};
CheckBoxFilterBase.prototype.isForeignColumn = function (col) {
return col.isForeignColumn ? col.isForeignColumn() : false;
};
CheckBoxFilterBase.prototype.refreshCheckboxes = function () {
var _this = this;
var val = this.sInput.value;
var column = this.options.column;
var query = this.isForeignColumn(column) ? this.foreignKeyQuery.clone() : this.options.query.clone();
var foreignQuery = this.options.query.clone();
var pred = query.queries.filter(function (e) { return e && e.fn === 'onWhere'; })[0];
query.queries = [];
foreignQuery.queries = [];
var parsed = (this.options.type !== 'string' && parseFloat(val)) ? parseFloat(val) : val;
var operator = this.options.isRemote ?
(this.options.type === 'string' ? 'contains' : 'equal') : (this.options.type ? 'contains' : 'equal');
var matchCase = true;
var ignoreAccent = this.options.ignoreAccent;
var field = this.isForeignColumn(column) ? column.foreignKeyValue : column.field;
parsed = (parsed === '' || parsed === undefined) ? undefined : parsed;
var coll = [];
var defaults = {
field: field, predicate: 'or', uid: this.options.uid,
operator: 'equal', type: this.options.type, matchCase: matchCase, ignoreAccent: ignoreAccent
};
var predicte;
var moduleName = this.options.dataManager.adaptor.getModuleName;
if (this.options.type === 'boolean') {
if (parsed !== undefined &&
this.getLocalizedLabel('FilterTrue').toLowerCase().indexOf(parsed.toLowerCase()) !== -1) {
parsed = 'true';
}
else if (parsed !== undefined &&
this.getLocalizedLabel('FilterFalse').toLowerCase().indexOf(parsed.toLowerCase()) !== -1) {
parsed = 'false';
}
if (parsed !== undefined &&
this.getLocalizedLabel('FilterTrue').toLowerCase().indexOf(parsed.toLowerCase()) !== -1 && moduleName) {
// eslint-disable-next-line no-constant-condition
parsed = (moduleName() === 'ODataAdaptor' || 'ODataV4Adaptor') ? true : 'true';
}
else if (parsed !== undefined &&
this.getLocalizedLabel('FilterFalse').toLowerCase().indexOf(parsed.toLowerCase()) !== -1 && moduleName) {
// eslint-disable-next-line no-constant-condition
parsed = (moduleName() === 'ODataAdaptor' || 'ODataV4Adaptor') ? false : 'false';
}
operator = 'equal';
}
if ((this.options.type === 'date' || this.options.type === 'datetime' || this.options.type === 'dateonly') && this.options.format) {
var intl = new Internationalization();
var format = typeof (this.options.format) === 'string' ? this.options.format :
this.options.format.format;
if (format) {
parsed = intl.parseDate(val, { format: format }) || new Date(val);
}
else {
parsed = new Date(val);
}
if (this.options.type === 'dateonly') {
parsed = parsed.getFullYear() + '-' + padZero(parsed.getMonth() + 1) + '-' + padZero(parsed.getDate());
}
}
this.infiniteSearchValChange = true;
this.infiniteLoadedElem = [];
this.infiniteLocalSelectAll = true;
this.localInfiniteSelectAllClicked = false;
this.localInfiniteSelectionInteracted = false;
this.infiniteSkipCnt = 0;
this.infiniteDataCount = 0;
this.infiniteManualSelectMaintainPred = [];
if (this.sInput.value === '') {
this.infiniteUnloadParentExistPred = this.infiniteRenderMod && this.existingPredicate[this.options.column.field] ? this.existingPredicate[this.options.column.field].slice() : [];
}
else {
this.infiniteUnloadParentExistPred = [];
}
this.addDistinct(query);
var args = {
requestType: events.filterSearchBegin,
filterModel: this, columnName: field, column: column,
operator: operator, matchCase: matchCase, ignoreAccent: ignoreAccent, filterChoiceCount: null,
query: query, value: parsed
};
if (this.infiniteRenderMod && this.parent.filterSettings.itemsCount) {
args.filterChoiceCount = this.parent.filterSettings.itemsCount;
}
this.parent.trigger(events.actionBegin, args, function (filterargs) {
// eslint-disable-next-line no-self-assign
filterargs.operator = filterargs.operator;
predicte = new Predicate(field, filterargs.operator, args.value, filterargs.matchCase, filterargs.ignoreAccent);
if (_this.options.type === 'date' || _this.options.type === 'datetime' || _this.options.type === 'dateonly') {
operator = 'equal';
var filterObj = {
field: field, operator: operator, value: parsed, matchCase: matchCase,
ignoreAccent: ignoreAccent
};
if (!isNullOrUndefined(parsed)) {
predicte = getDatePredicate(filterObj, _this.options.type);
}
}
if (val && typeof val === 'string' && _this.isBlanks &&
_this.getLocalizedLabel('Blanks').toLowerCase().indexOf(val.toLowerCase()) >= 0) {
coll = coll.concat(CheckBoxFilterBase.generateNullValuePredicates(defaults));
var emptyValPredicte = CheckBoxFilterBase.generatePredicate(coll);
emptyValPredicte.predicates.push(predicte);
predicte = emptyValPredicte;
query.where(emptyValPredicte);
}
else if (val.length) {
predicte = !isNullOrUndefined(pred) ? predicte.and(pred.e) : predicte;
query.where(predicte);
}
else if (!isNullOrUndefined(pred)) {
predicte = pred.e;
query.where(pred.e);
}
_this.infiniteSearchPred = predicte;
filterargs.filterChoiceCount = !isNullOrUndefined(filterargs.filterChoiceCount) ? filterargs.filterChoiceCount : 1000;
if (_this.infiniteRenderMod && _this.parent.filterSettings.itemsCount !== filterargs.filterChoiceCount) {
_this.parent.filterSettings.itemsCount = args.filterChoiceCount;
}
var fPredicate = {};
showSpinner(_this.spinner);
_this.renderEmpty = false;
if (_this.isForeignColumn(column) && val.length) {
var colData = ('result' in column.dataSource) ? new DataManager(column.dataSource.result) :
column.dataSource;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
colData.executeQuery(query).then(function (e) {
var columnData = _this.options.column.columnData;
_this.options.column.columnData = e.result;
_this.parent.notify(events.generateQuery, { predicate: fPredicate, column: column });
if (fPredicate.predicate.predicates.length) {
foreignQuery.where(fPredicate.predicate);
}
else {
_this.renderEmpty = true;
}
_this.options.column.columnData = columnData;
if (_this.infiniteRenderMod) {
_this.infiniteInitialLoad = isNullOrUndefined(_this.fullData) ? true : false;
_this.makeInfiniteScrollRequest(foreignQuery);
foreignQuery.requiresCount();
}
else {
foreignQuery.take(filterargs.filterChoiceCount);
}
_this.search(filterargs, foreignQuery);
});
}
else {
if (_this.infiniteRenderMod && _this.parent.filterSettings.itemsCount) {
_this.infiniteInitialLoad = isNullOrUndefined(_this.fullData) ? true : false;
_this.makeInfiniteScrollRequest(query);
query.requiresCount();
}
else {
query.take(filterargs.filterChoiceCount);
}
_this.search(filterargs, query);
}
});
};
CheckBoxFilterBase.prototype.search = function (args, query) {
if (this.parent.dataSource && 'result' in this.parent.dataSource) {
this.filterEvent(args, query);
}
else {
this.processSearch(query);
}
};
CheckBoxFilterBase.prototype.getPredicateFromCols = function (columns, isExecuteLocal) {
var predicates = CheckBoxFilterBase.getPredicate(columns, isExecuteLocal);
var predicateList = [];
var fPredicate = {};
var isGrid = this.parent.getForeignKeyColumns !== undefined;
var foreignColumn = isGrid ? this.parent.getForeignKeyColumns() : [];
for (var _i = 0, _a = Object.keys(predicates); _i < _a.length; _i++) {
var prop = _a[_i];
var col = void 0;
if (isGrid && !this.parent.getColumnByField(prop)) {
col = getColumnByForeignKeyValue(prop, foreignColumn);
}
if (col) {
this.parent.notify(events.generateQuery, { predicate: fPredicate, column: col });
if (fPredicate.predicate.predicates.length) {
predicateList.push(Predicate.or(fPredicate.predicate.predicates));
}
}
else {
predicateList.push(predicates["" + prop]);
}
}
return predicateList.length && Predicate.and(predicateList);
};
CheckBoxFilterBase.prototype.getQuery = function () {
return this.parent.getQuery ? this.parent.getQuery().clone() : new Query();
};
CheckBoxFilterBase.prototype.getAllData = function () {
var _this = this;
this.customQuery = false;
var query = this.getQuery();
var moduleName = this.options.dataManager.adaptor.getModuleName;
if (!(!isNullOrUndefined(this.parent.getDataModule) && moduleName && moduleName() === 'ODataV4Adaptor')) {
query.requiresCount(); //consider take query
}
this.addDistinct(query);
var args = {
requestType: events.filterChoiceRequest, query: query, filterChoiceCount: null
};
var filterModel = 'filterModel';
args["" + filterModel] = this;
if (this.infiniteRenderMod && this.parent.filterSettings.itemsCount) {
args.filterChoiceCount = this.parent.filterSettings.itemsCount;
}
this.parent.trigger(events.actionBegin, args, function (args) {
args.filterChoiceCount = !isNullOrUndefined(args.filterChoiceCount) ? args.filterChoiceCount : 1000;
if (_this.infiniteRenderMod && _this.parent.filterSettings.itemsCount !== args.filterChoiceCount) {
_this.parent.filterSettings.itemsCount = args.filterChoiceCount;
}
if (!_this.infiniteRenderMod) {
query.take(args.filterChoiceCount);
}
if (!args.query.distincts.length || _this.infiniteRenderMod) {
_this.customQuery = true;
_this.queryGenerate(query);
}
if (_this.infiniteRenderMod) {
_this.infiniteInitialLoad = isNullOrUndefined(_this.fullData) ? true : false;
_this.makeInfiniteScrollRequest(query);
}
if (_this.parent.dataSource && 'result' in _this.parent.dataSource) {
_this.filterEvent(args, query);
}
else {
_this.processDataOperation(query, true);
}
});
};
CheckBoxFilterBase.prototype.addDistinct = function (query) {
var _this = this;
var filteredColumn = DataUtil.distinct(this.options.filteredColumns, 'field');
if (filteredColumn.indexOf(this.options.column.field) <= -1) {
filteredColumn = filteredColumn.concat(this.options.column.field);
}
var moduleName = this.options.dataManager.adaptor.getModuleName;
if (moduleName && moduleName() === 'ODataV4Adaptor' && this.parent &&
this.parent.query instanceof Query) {
var gridQuery = this.parent.query;
for (var i = 0; i < gridQuery.queries.length; i++) {
var queryOptions = gridQuery.queries[parseInt(i.toString(), 10)];
if (queryOptions.fn === 'onWhere') {
this.getPredicateFields(queryOptions.e);
this.queryFilteredColumn.map(function (field) {
if (filteredColumn.indexOf(field) === -1) {
filteredColumn.push(field);
}
});
this.queryFilteredColumn = [];
}
}
}
if (!this.infiniteRenderMod) {
query.distinct(filteredColumn);
}
if (this.infiniteRenderMod && !this.options.isRemote && this.sInput.value === '') {
this.options.dataSource = this.options.dataSource instanceof DataManager ?
this.options.dataSource : new DataManager(this.options.dataSource);
this.infinitePermenantLocalData = this.options.dataSource.dataSource.json.slice();
var query1 = new Query();
this.queryGenerate(query1);
var result = new DataManager(this.options.dataSource.dataSource).executeLocal(query1);
this.options.dataSource.dataSource.json = DataUtil.distinct(result, this.options.column.field, true);
if (this.isForeignColumn(this.options.column)) {
this.options.column.dataSource = this.options.column.dataSource instanceof DataManager ?
this.options.column.dataSource : new DataManager(this.options.column.dataSource);
this.options.dataSource.dataSource.json = this.options.dataSource.dataSource.json.map(function (item, i) {
return Object.assign({}, item, _this.options.column.dataSource.dataSource.json[i]);
});
}
}
else if (this.infiniteRenderMod && this.options.isRemote) {
query.select(this.options.column.field);
query.sortBy(this.options.column.field, 'ascending');
var moduleName_1 = this.options.dataManager.adaptor.getModuleName;
if (moduleName_1 && moduleName_1() && (moduleName_1() === 'ODataV4Adaptor' || moduleName_1() === 'WebApiAdaptor'
|| moduleName_1() === 'CustomDataAdaptor' || moduleName_1() === 'GraphQLAdaptor' || moduleName_1() === 'ODataAdaptor')) {
query.distinct(filteredColumn);
}
}
return query;
};
CheckBoxFilterBase.prototype.getPredicateFields = function (query) {
var _this = this;
if (query.isComplex && query.predicates) {
query.predicates.forEach(function (predicate) {
if (Array.isArray(predicate)) {
predicate.forEach(function (p) { return _this.getPredicateFields(p); });
}
else {
_this.getPredicateFields(predicate);
}
});
}
else {
if (query.field && !query.isComplex) {
if (this.queryFilteredColumn.indexOf(query.field) <= -1) {
this.queryFilteredColumn = this.queryFilteredColumn.concat(DataUtil.distinct([query.field], 'field'));
}
}
}
};
CheckBoxFilterBase.prototype.filterEvent = function (args, query) {
var _this = this;
var defObj = eventPromise(args, query);
this.parent.trigger(events.dataStateChange, defObj.state);
this.addInfiniteScrollEvent(query);
var def = defObj.deffered;
def.promise.then(function (e) {
_this.infiniteDataCount = _this.infiniteRenderMod && !_this.infiniteDataCount ? e['count'] : _this.infiniteDataCount;
var dataResult = _this.infiniteRenderMod ? e['result'] : e;
_this.dataSuccess(dataResult);
});
};
CheckBoxFilterBase.prototype.addInfiniteScrollEvent = function (query) {
if (this.infiniteRenderMod) {
this.infiniteQuery = query.clone();
if (this.infiniteIn