all files / grid/models/ column.js

87.06% Statements 74/85
82.61% Branches 38/46
88.89% Functions 16/18
86.9% Lines 73/84
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   3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 3003× 38× 38×   3003× 376× 376× 376×   3003×   3003×   3003×   3003×     3003×   3003×         3003×                       3003× 417× 417× 417×         232×             2705840×   345197×   257×   118×   880×   184×     94×   978168×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "../services/value-formatter", "../base/util"], function (require, exports, ej2_base_1, ej2_data_1, value_formatter_1, util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Column = (function () {
        function Column(options) {
            var _this = this;
            this.allowSorting = true;
            this.allowResizing = true;
            this.allowFiltering = true;
            this.allowGrouping = true;
            this.allowReordering = true;
            this.showColumnMenu = true;
            this.enableGroupByFormat = false;
            this.allowEditing = true;
            this.filter = {};
            this.showInColumnChooser = true;
            this.edit = {};
            this.sortDirection = 'Descending';
            this.getEditTemplate = function () { return _this.editTemplateFn; };
            ej2_base_1.merge(this, options);
            this.uid = util_1.getUid('grid-column');
            var valueFormatter = new value_formatter_1.ValueFormatter();
            if (options.format && (options.format.skeleton || options.format.format)) {
                this.setFormatter(valueFormatter.getFormatFunction(options.format));
                this.setParser(valueFormatter.getParserFunction(options.format));
            }
            if (!this.field) {
                this.allowFiltering = false;
                this.allowGrouping = false;
                this.allowSorting = false;
            }
            if (this.commands && !this.textAlign) {
                this.textAlign = 'Right';
            }
            if (this.template || this.commandsTemplate) {
                this.templateFn = util_1.templateCompiler(this.template || this.commandsTemplate);
            }
            if (this.headerTemplate) {
                this.headerTemplateFn = util_1.templateCompiler(this.headerTemplate);
            }
            Iif (this.filter.itemTemplate) {
                this.fltrTemplateFn = util_1.templateCompiler(this.filter.itemTemplate);
            }
            if (this.editTemplate) {
                this.editTemplateFn = util_1.templateCompiler(this.editTemplate);
            }
            if (this.isForeignColumn() && (ej2_base_1.isNullOrUndefined(this.editType) || this.editType === 'dropdownedit')) {
                this.editType = 'dropdownedit';
                this.edit.params = ej2_base_1.extend({
                    dataSource: this.dataSource,
                    query: new ej2_data_1.Query(), fields: { value: this.foreignKeyField || this.field, text: this.foreignKeyValue }
                }, this.edit.params);
            }
            if (this.sortComparer) {
                var a_1 = this.sortComparer;
                this.sortComparer = function comparer(x, y) {
                    if (typeof a_1 === 'string') {
                        a_1 = util_1.getObject(a_1, window);
                    }
                    if (this.sortDirection === 'Descending') {
                        var z = x;
                        x = y;
                        y = z;
                    }
                    return a_1(x, y);
                };
            }
            if (!this.sortComparer && this.isForeignColumn()) {
                this.sortComparer = function (x, y) {
                    x = util_1.getObject(_this.foreignKeyValue, util_1.getForeignData(_this, {}, x)[0]);
                    y = util_1.getObject(_this.foreignKeyValue, util_1.getForeignData(_this, {}, y)[0]);
                    return _this.sortDirection === 'Descending' ? ej2_data_1.DataUtil.fnDescending(x, y) : ej2_data_1.DataUtil.fnAscending(x, y);
                };
            }
        }
        Column.prototype.getSortDirection = function () {
            return this.sortDirection;
        };
        Column.prototype.setSortDirection = function (direction) {
            this.sortDirection = direction;
        };
        Column.prototype.setProperties = function (column) {
            var keys = Object.keys(column);
            for (var i = 0; i < keys.length; i++) {
                this[keys[i]] = column[keys[i]];
            }
        };
        Column.prototype.isForeignColumn = function () {
            return !!(this.dataSource && this.foreignKeyValue);
        };
        Column.prototype.getFormatter = function () {
            return this.formatFn;
        };
        Column.prototype.setFormatter = function (value) {
            this.formatFn = value;
        };
        Column.prototype.getParser = function () {
            return this.parserFn;
        };
        Column.prototype.setParser = function (value) {
            this.parserFn = value;
        };
        Column.prototype.getColumnTemplate = function () {
            return this.templateFn;
        };
        Column.prototype.getHeaderTemplate = function () {
            return this.headerTemplateFn;
        };
        Column.prototype.getFilterItemTemplate = function () {
            return this.fltrTemplateFn;
        };
        Column.prototype.getDomSetter = function () {
            return this.disableHtmlEncode ? 'textContent' : 'innerHTML';
        };
        return Column;
    }());
    exports.Column = Column;
});