all files / grid/actions/ aggregate.js

100% Statements 86/86
100% Branches 32/32
100% Functions 14/14
100% Lines 86/86
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   79× 79× 79×   20597×   79× 79× 79× 79× 79× 237×   79× 79× 79× 79× 79×   23×   79× 79× 73× 73×   79× 79×   91× 91× 201× 201×   201× 12× 12×   189× 66× 66×   201×     27×   18×   18× 18× 18× 18× 18× 11×     80×   79× 79× 79× 79×   194× 116×   78× 78× 78× 78× 78× 78× 78× 77×     194×           91× 141× 201×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/enum", "../services/value-formatter", "../base/constant", "../renderer/footer-renderer", "../renderer/summary-cell-renderer", "../services/summary-model-generator", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, enum_1, value_formatter_1, constant_1, footer_renderer_1, summary_cell_renderer_1, summary_model_generator_1, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Aggregate = (function () {
        function Aggregate(parent, locator) {
            this.parent = parent;
            this.locator = locator;
            this.addEventListener();
        }
        Aggregate.prototype.getModuleName = function () {
            return 'aggregate';
        };
        Aggregate.prototype.initiateRender = function () {
            var _this = this;
            var cellFac = this.locator.getService('cellRendererFactory');
            var instance = new summary_cell_renderer_1.SummaryCellRenderer(this.parent, this.locator);
            var type = [enum_1.CellType.Summary, enum_1.CellType.CaptionSummary, enum_1.CellType.GroupSummary];
            for (var i = 0; i < type.length; i++) {
                cellFac.addCellRenderer(type[parseInt(i.toString(), 10)], instance);
            }
            this.footerRenderer = new footer_renderer_1.FooterRenderer(this.parent, this.locator);
            this.footerRenderer.renderPanel();
            this.footerRenderer.renderTable();
            var footerContent = this.footerRenderer.getPanel();
            if (this.parent.element.scrollHeight >= this.parent.getHeight(this.parent.height)
                && footerContent) {
                ej2_base_2.addClass([footerContent], ['e-footerpadding']);
            }
            this.locator.register('footerRenderer', this.footerRenderer);
            var fn = function () {
                _this.prepareSummaryInfo();
                _this.parent.off(constant_1.dataReady, fn);
            };
            this.parent.on(constant_1.dataReady, fn, this);
            this.parent.on(constant_1.dataReady, this.footerRenderer.refresh, this.footerRenderer);
        };
        Aggregate.prototype.prepareSummaryInfo = function () {
            var _this = this;
            summaryIterator(this.parent.aggregates, function (column) {
                var cFormat = ej2_base_1.getValue('customFormat', column);
                if (!ej2_base_2.isNullOrUndefined(cFormat)) {
                    column.setPropertiesSilent({ format: cFormat });
                }
                if (typeof (column.format) === 'object') {
                    var valueFormatter = new value_formatter_1.ValueFormatter();
                    column.setFormatter(valueFormatter.getFormatFunction(ej2_base_1.extend({}, column.format)));
                }
                else if (typeof (column.format) === 'string') {
                    var fmtr = _this.locator.getService('valueFormatter');
                    column.setFormatter(fmtr.getFormatFunction({ format: column.format }));
                }
                column.setPropertiesSilent({ columnName: column.columnName || column.field });
            });
        };
        Aggregate.prototype.onPropertyChanged = function (e) {
            if (e.module !== this.getModuleName()) {
                return;
            }
            if (ej2_base_2.isNullOrUndefined(this.footerRenderer)) {
                this.initiateRender();
            }
            this.prepareSummaryInfo();
            this.footerRenderer.refresh();
            var cModel = new summary_model_generator_1.CaptionSummaryModelGenerator(this.parent);
            var gModel = new summary_model_generator_1.GroupSummaryModelGenerator(this.parent);
            if (gModel.getData().length !== 0 || !cModel.isEmpty()) {
                this.parent.notify(constant_1.modelChanged, {});
            }
        };
        Aggregate.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(constant_1.initialEnd, this.initiateRender, this);
            this.parent.on(constant_1.uiUpdate, this.onPropertyChanged, this);
            this.parent.on(constant_1.refreshAggregates, this.refresh, this);
            this.parent.on(constant_1.destroy, this.destroy, this);
        };
        Aggregate.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.footerRenderer.removeEventListener();
            this.parent.off(constant_1.initialEnd, this.initiateRender);
            this.parent.off(constant_1.dataReady, this.footerRenderer.refresh);
            this.parent.off(constant_1.uiUpdate, this.onPropertyChanged);
            this.parent.off(constant_1.refreshAggregates, this.refresh);
            this.parent.off(constant_1.destroy, this.destroy);
            if (this.parent.element.querySelector('.' + literals.gridFooter)) {
                ej2_base_1.remove(this.parent.element.querySelector('.' + literals.gridFooter));
            }
        };
        Aggregate.prototype.destroy = function () {
            this.removeEventListener();
        };
        Aggregate.prototype.refresh = function (data, element) {
            var editedData = data instanceof Array ? data : [data];
            this.parent.notify(constant_1.refreshFooterRenderer, editedData);
            if (element) {
                editedData.row = element;
            }
            if (this.parent.groupSettings.columns.length > 0) {
                this.parent.notify(constant_1.groupAggregates, editedData);
            }
        };
        return Aggregate;
    }());
    exports.Aggregate = Aggregate;
    function summaryIterator(aggregates, callback) {
        for (var i = 0; i < aggregates.length; i++) {
            for (var j = 0; j < aggregates[parseInt(i.toString(), 10)].columns.length; j++) {
                callback(aggregates[parseInt(i.toString(), 10)].columns[parseInt(j.toString(), 10)], aggregates[parseInt(i.toString(), 10)]);
            }
        }
    }
    exports.summaryIterator = summaryIterator;
});