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

94.2% Statements 65/69
91.25% Branches 73/80
100% Functions 15/15
93.94% Lines 62/66
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          79× 79×   79×   4235×   4235×   4235× 4235× 4235× 3409× 48×   3409×     826× 12×     826× 826× 826× 826× 648× 648× 12× 72×   12× 12×       826×         826× 826×   826×                 825×   826×   4235× 4235× 4235× 10599× 10599× 10599× 9854×   10599×   82×            
/* 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", "../base/util", "./cell-renderer", "../base/constant"], function (require, exports, ej2_base_1, util_1, cell_renderer_1, constant_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var SummaryCellRenderer = (function (_super) {
        __extends(SummaryCellRenderer, _super);
        function SummaryCellRenderer() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.element = _this.parent
                .createElement('TD', { className: 'e-summarycell', attrs: { tabindex: '-1', role: 'gridcell' } });
            return _this;
        }
        SummaryCellRenderer.prototype.getValue = function (field, data, column) {
            var key = !ej2_base_1.isNullOrUndefined(column.type) ?
                column.field + ' - ' + (typeof column.type === 'string' ? column.type.toLowerCase() : '') : column.columnName;
            return data[column.columnName] ? data[column.columnName]["" + key] : '';
        };
        SummaryCellRenderer.prototype.evaluate = function (node, cell, data, attributes) {
            var column = cell.column;
            this.parent.on(constant_1.refreshAggregateCell, this.refreshWithAggregate(node, cell), this);
            if (!(column.footerTemplate || column.groupFooterTemplate || column.groupCaptionTemplate)) {
                if (this.parent.rowRenderingMode === 'Vertical') {
                    node.style.display = 'none';
                }
                return true;
            }
            else {
                if (this.parent.rowRenderingMode === 'Vertical') {
                    node.classList.add('e-lastsummarycell');
                }
            }
            var tempObj = column.getTemplate(cell.cellType);
            var tempID = '';
            var gColumn = this.parent.getColumnByField(data[column.columnName].field);
            if (!ej2_base_1.isNullOrUndefined(gColumn)) {
                data[column.columnName].headerText = gColumn.headerText;
                if (gColumn.isForeignColumn()) {
                    var fData = gColumn.columnData.filter(function (e) {
                        return e[gColumn.foreignKeyField] === data[column.columnName].key;
                    })[0];
                    Eif (fData) {
                        data[column.columnName].foreignKey = fData[gColumn.foreignKeyValue];
                    }
                }
            }
            var isNotStringTemplate = column.footerTemplate ? typeof (column.footerTemplate) !== 'string' && !(column.footerTemplate.prototype &&
                column.footerTemplate.prototype.CSPTemplate) : column.groupFooterTemplate ? typeof (column.groupFooterTemplate) !== 'string' &&
                !(column.groupFooterTemplate.prototype && column.groupFooterTemplate.prototype.CSPTemplate)
                : column.groupCaptionTemplate ? typeof (column.groupCaptionTemplate) !== 'string' && !(column.groupCaptionTemplate.prototype &&
                    column.groupCaptionTemplate.prototype.CSPTemplate) : false;
            var isReactCompiler = this.parent.isReact && isNotStringTemplate;
            var isReactChild = this.parent.parentDetails && this.parent.parentDetails.parentInstObj &&
                this.parent.parentDetails.parentInstObj.isReact && isNotStringTemplate;
            if (isReactCompiler || isReactChild) {
                var prop = data[column.columnName];
                Iif (tempObj.property === 'groupCaptionTemplate' || tempObj.property === 'groupFooterTemplate') {
                    var groupKey = 'groupKey';
                    var key = 'key';
                    prop["" + groupKey] = prop["" + key];
                }
                tempObj.fn(prop, this.parent, tempObj.property, tempID, null, null, node);
                Iif (!this.parent.isInitialLoad) {
                    this.parent.renderTemplates();
                }
            }
            else {
                util_1.appendChildren(node, tempObj.fn(data[column.columnName], this.parent, tempObj.property, tempID, null, null, null, this.parent.root));
            }
            return false;
        };
        SummaryCellRenderer.prototype.refreshWithAggregate = function (node, cell) {
            var _this = this;
            var cellNode = cell;
            return function (args) {
                var cell = cellNode;
                var field = cell.column.columnName ? cell.column.columnName : null;
                var curCell = (!ej2_base_1.isNullOrUndefined(field) ? args.cells.filter(function (cell) {
                    return cell.column.columnName === field;
                })[0] : null);
                if (node.parentElement && node.parentElement.getAttribute('data-uid') === args.dataUid && field && curCell &&
                    field === curCell.column.columnName) {
                    _this.refreshTD(node, curCell, args.data);
                }
            };
        };
        return SummaryCellRenderer;
    }(cell_renderer_1.CellRenderer));
    exports.SummaryCellRenderer = SummaryCellRenderer;
});