all files / grid/renderer/ filter-cell-renderer.js

95.49% Statements 127/133
88.3% Branches 83/94
100% Functions 15/15
95.38% Lines 124/130
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226          246× 246× 246×   2008×   2008× 2008× 2008× 2008× 2008× 2008× 2008× 2008×                               2005× 2000×                                 1995×     1995×             1995× 1995×           1995× 1995×   2000×   2000× 2000× 1995×   2000× 122×   2000× 2000×   32×   2000×                 2008× 359×   2008×   2000× 2000×   32× 32× 32×       32× 32×   30×             25×   32×     32×                                 32× 32× 32× 32×          
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "./cell-renderer", "@syncfusion/ej2-inputs", "../base/util", "@syncfusion/ej2-dropdowns", "../base/constant"], function (require, exports, ej2_base_1, ej2_base_2, cell_renderer_1, ej2_inputs_1, util_1, ej2_dropdowns_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var FilterCellRenderer = (function (_super) {
        __extends(FilterCellRenderer, _super);
        function FilterCellRenderer() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.element = _this.parent.createElement('TH', { className: 'e-filterbarcell', attrs: { role: 'columnheader' } });
            return _this;
        }
        FilterCellRenderer.prototype.getGui = function () {
            return this.parent.createElement('div');
        };
        FilterCellRenderer.prototype.render = function (cell, data) {
            var tr = this.parent.element.querySelector('.e-filterbar');
            var node = this.element.cloneNode();
            var innerDIV = this.getGui();
            var input;
            var column = cell.column;
            tr.appendChild(node);
            node.setAttribute('e-mappinguid', column.uid);
            if (column.filterTemplate) {
                var fltrData = {};
                Eif (data) {
                    fltrData[column.field] = data[column.field];
                }
                var col = 'column';
                fltrData["" + col] = column;
                Eif (column.visible) {
                    Eif (this.parent.filterSettings.type === 'FilterBar') {
                        node.classList.add('e-fltrtemp');
                    }
                    var isReactCompiler = this.parent.isReact && typeof (column.filterTemplate) !== 'string' &&
                        !(column.filterTemplate.prototype && column.filterTemplate.prototype.CSPTemplate);
                    var isReactChild = this.parent.parentDetails && this.parent.parentDetails.parentInstObj &&
                        this.parent.parentDetails.parentInstObj.isReact;
                    var tempID = this.parent.element.id + column.uid + 'filterTemplate';
                    Iif (isReactCompiler || isReactChild) {
                        column.getFilterTemplate()(fltrData, this.parent, 'filterTemplate', tempID, null, null, node);
                        this.parent.renderTemplates();
                    }
                    else {
                        var element = column.getFilterTemplate()(fltrData, this.parent, 'filterTemplate', tempID, null, null, null, this.parent.root);
                        util_1.appendChildren(node, element);
                    }
                }
                else {
                    node.classList.add('e-hide');
                }
            }
            else {
                if (column.type !== 'checkbox') {
                    if ((ej2_base_1.isNullOrUndefined(column.allowFiltering) || column.allowFiltering) && !ej2_base_1.isNullOrUndefined(column.filterBarTemplate)) {
                        node.classList.add('e-fltrtemp');
                        ej2_base_2.attributes(innerDIV, {
                            'class': 'e-fltrtempdiv'
                        });
                        if (ej2_base_1.isNullOrUndefined(column.filterBarTemplate.create)) {
                            input = this.parent.createElement('input', {
                                id: column.field + '_filterBarcell', className: 'e-filterUi_input e-filtertext e-fltrTemp',
                                attrs: { type: 'search', title: column.headerText }
                            });
                            innerDIV.appendChild(input);
                        }
                        else {
                            var args = { column: column, node: Element };
                            var temp = column.filterBarTemplate.create;
                            if (typeof temp === 'string') {
                                temp = ej2_base_1.getValue(temp, window);
                            }
                            input = temp(args);
                            if (typeof input === 'string') {
                                var div = this.parent.createElement('div');
                                div.innerHTML = input;
                                input = div.firstChild;
                            }
                            ej2_base_2.attributes(innerDIV, {
                                class: 'e-filterUi_input e-filtertext e-fltrTemp',
                                title: column.headerText,
                                id: column.field + '_filterBarcell'
                            });
                            innerDIV.appendChild(input);
                        }
                    }
                    else {
                        ej2_base_2.attributes(innerDIV, {
                            'class': 'e-filterdiv e-fltrinputdiv'
                        });
                        input = this.parent.createElement('input', {
                            id: column.field + '_filterBarcell', className: 'e-filtertext',
                            attrs: {
                                type: 'search', title: column.headerText + cell.attributes.title,
                                value: data[cell.column.field] ? data[cell.column.field] : ''
                            }
                        });
                        innerDIV.appendChild(input);
                        var args = {
                            element: input, floatLabelType: 'Never',
                            properties: {
                                enableRtl: this.parent.enableRtl, showClearButton: true, cssClass: this.parent.cssClass
                            }
                        };
                        this.parent.filterModule.inputList.push(args);
                        ej2_inputs_1.Input.createInput(args, this.parent.createElement);
                    }
                    if (column.allowFiltering === false || column.field === '' || ej2_base_1.isNullOrUndefined(column.field)) {
                        input.setAttribute('disabled', 'true');
                        input.classList.add('e-disable');
                    }
                    var clearIconElem = innerDIV.querySelector('.e-clear-icon');
                    if (clearIconElem) {
                        clearIconElem.setAttribute('title', this.parent.localeObj.getConstant('ClearButton'));
                    }
                    if (!column.visible) {
                        node.classList.add('e-hide');
                    }
                    this.appendHtml(node, innerDIV);
                    if (this.parent.filterSettings.showFilterBarOperator && this.parent.filterSettings.type === 'FilterBar' &&
                        !this.parent.isPrinting && ej2_base_1.isNullOrUndefined(column.filterTemplate) && ej2_base_1.isNullOrUndefined(column.filterBarTemplate)) {
                        this.operatorIconRender(innerDIV, column, cell);
                    }
                    if ((ej2_base_1.isNullOrUndefined(column.allowFiltering) || column.allowFiltering) && !ej2_base_1.isNullOrUndefined(column.filterBarTemplate)) {
                        var templateWrite = column.filterBarTemplate.write;
                        var args = { element: input, column: column };
                        if (typeof templateWrite === 'string') {
                            templateWrite = ej2_base_1.getValue(templateWrite, window);
                        }
                        templateWrite.call(this, args);
                    }
                }
                else {
                    Iif (!column.visible) {
                        node.classList.add('e-hide');
                    }
                }
            }
            if (this.parent.isFrozenGrid()) {
                util_1.addStickyColumnPosition(this.parent, column, node);
            }
            return node;
        };
        FilterCellRenderer.prototype.appendHtml = function (node, innerHtml) {
            node.appendChild(innerHtml);
            return node;
        };
        FilterCellRenderer.prototype.operatorIconRender = function (innerDIV, column, cell) {
            var gObj = this.parent;
            var operators;
            var fbicon = this.parent.createElement('input', {
                className: ' e-filterbaroperator e-icons e-icon-filter',
                id: cell.column.uid
            });
            innerDIV.querySelector('span').appendChild(fbicon);
            if (column.filter && column.filter.operator) {
                operators = column.filter.operator;
            }
            else if (gObj.filterSettings.columns.length) {
                for (var i = 0, a = gObj.filterSettings.columns; i < a.length; i++) {
                    var col = a[parseInt(i.toString(), 10)];
                    if (col.field === column.field) {
                        operators = col.operator;
                        break;
                    }
                    else {
                        operators = 'equal';
                    }
                }
            }
            else {
                operators = 'equal';
            }
            Iif (!ej2_base_1.isNullOrUndefined(gObj.filterModule.operators[column.field])) {
                operators = gObj.filterModule.operators[column.field];
            }
            this.dropOptr = new ej2_dropdowns_1.DropDownList({
                fields: { text: 'text', value: 'value' },
                popupHeight: 'auto',
                value: operators,
                width: '0px',
                enabled: column.allowFiltering,
                popupWidth: 'auto',
                enableRtl: this.parent.enableRtl,
                change: this.internalEvent.bind(this),
                beforeOpen: function () {
                    var operator = gObj.filterModule.customOperators;
                    this.dataSource = operator[gObj.getColumnByUid(this.element.id).type + 'Operator'];
                    for (var i = 0; i < this.dataSource.length; i++) {
                        Iif (column.filter && column.filter.operator && ej2_base_1.isNullOrUndefined(gObj.filterModule.operators[column.field]) &&
                            this.dataSource[parseInt(i.toString(), 10)].value === column.filter.operator) {
                            this.value = column.filter.operator;
                        }
                    }
                },
                cssClass: this.parent.cssClass ? 'e-popup-flbar' + ' ' + this.parent.cssClass : 'e-popup-flbar'
            });
            this.dropOptr.appendTo(fbicon);
            var spanElmt = ej2_base_1.closest(this.dropOptr.element, 'span');
            spanElmt.classList.add('e-filterbardropdown');
            spanElmt.removeAttribute('tabindex');
        };
        FilterCellRenderer.prototype.internalEvent = function (e) {
            var gObj = this.parent;
            var col = gObj.getColumnByUid(e.element.getAttribute('id'));
            e.column = col;
            gObj.filterModule.operators[col.field] = e.value;
            gObj.notify(events.getFilterBarOperator, e);
        };
        return FilterCellRenderer;
    }(cell_renderer_1.CellRenderer));
    exports.FilterCellRenderer = FilterCellRenderer;
});