all files / grid/services/ row-model-generator.js

100% Statements 72/72
100% Branches 57/57
100% Functions 11/11
100% Lines 72/72
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   3036×   1782× 1782× 1782× 1782×   1782× 32581×   1782×   41432× 41432× 470× 470× 470×   41432× 437×   41432×   41432× 41432× 41432× 41432× 41432× 41432× 41432× 41432× 41432× 41432× 41432× 154× 14×   140×     41432× 41432× 41432× 41432× 41432× 41432× 41432× 41432×   41432×   42093× 42093× 1005×     42176× 42176× 42176× 211745×   42176×   243411×                       243409× 224766×   243409×   21× 661× 661×   21×   114×          
define(["require", "exports", "@syncfusion/ej2-base", "../models/row", "../base/enum", "../models/cell", "../base/util", "../../grid/base/util", "../base/constant"], function (require, exports, ej2_base_1, row_1, enum_1, cell_1, util_1, util_2, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RowModelGenerator = (function () {
        function RowModelGenerator(parent) {
            this.parent = parent;
        }
        RowModelGenerator.prototype.generateRows = function (data, args) {
            var rows = [];
            var startIndex = this.parent.enableVirtualization && args ? args.startIndex : 0;
            startIndex = this.parent.enableInfiniteScrolling && args ? this.getInfiniteIndex(args) : startIndex;
            if (this.parent.enableImmutableMode && args && args.startIndex) {
                startIndex = args.startIndex;
            }
            for (var i = 0, len = Object.keys(data).length; i < len; i++, startIndex++) {
                rows[parseInt(i.toString(), 10)] = this.generateRow(data[parseInt(i.toString(), 10)], startIndex);
            }
            return rows;
        };
        RowModelGenerator.prototype.ensureColumns = function () {
            var cols = [];
            if (this.parent.detailTemplate || this.parent.childGrid) {
                var args = {};
                this.parent.notify(events.detailIndentCellInfo, args);
                cols.push(this.generateCell(args, null, enum_1.CellType.DetailExpand));
            }
            if (this.parent.isRowDragable()) {
                cols.push(this.generateCell({}, null, enum_1.CellType.RowDragIcon));
            }
            return cols;
        };
        RowModelGenerator.prototype.generateRow = function (data, index, cssClass, indent, pid, tIndex, parentUid) {
            var options = {};
            options.foreignKeyData = {};
            options.uid = util_1.getUid('grid-row');
            options.data = data;
            options.index = index;
            options.indent = indent;
            options.tIndex = tIndex;
            options.isDataRow = true;
            options.parentGid = pid;
            options.parentUid = parentUid;
            if (this.parent.isPrinting) {
                if (this.parent.hierarchyPrintMode === 'All') {
                    options.isExpand = true;
                }
                else if (this.parent.hierarchyPrintMode === 'Expanded' && this.parent.expandedRows && this.parent.expandedRows[parseInt(index.toString(), 10)]) {
                    options.isExpand = this.parent.expandedRows[parseInt(index.toString(), 10)].isExpand;
                }
            }
            options.cssClass = cssClass;
            options.isAltRow = this.parent.enableAltRow ? index % 2 !== 0 : false;
            options.isAltRow = this.parent.enableAltRow ? index % 2 !== 0 : false;
            options.isSelected = this.parent.getSelectedRowIndexes().indexOf(index) > -1;
            this.refreshForeignKeyRow(options);
            var cells = this.ensureColumns();
            var row = new row_1.Row(options, this.parent);
            row.cells = this.parent.getFrozenMode() === 'Right' ? this.generateCells(options).concat(cells)
                : cells.concat(this.generateCells(options));
            return row;
        };
        RowModelGenerator.prototype.refreshForeignKeyRow = function (options) {
            var foreignKeyColumns = this.parent.getForeignKeyColumns();
            for (var i = 0; i < foreignKeyColumns.length; i++) {
                ej2_base_1.setValue(foreignKeyColumns[parseInt(i.toString(), 10)].field, util_2.getForeignData(foreignKeyColumns[parseInt(i.toString(), 10)], options.data), options.foreignKeyData);
            }
        };
        RowModelGenerator.prototype.generateCells = function (options) {
            var dummies = this.parent.getColumns();
            var tmp = [];
            for (var i = 0; i < dummies.length; i++) {
                tmp.push(this.generateCell(dummies[parseInt(i.toString(), 10)], options.uid, ej2_base_1.isNullOrUndefined(dummies[parseInt(i.toString(), 10)].commands) ? undefined : enum_1.CellType.CommandColumn, null, i, options.foreignKeyData));
            }
            return tmp;
        };
        RowModelGenerator.prototype.generateCell = function (column, rowId, cellType, colSpan, oIndex, foreignKeyData) {
            var opt = {
                'visible': column.visible,
                'isDataCell': !ej2_base_1.isNullOrUndefined(column.field || column.template),
                'isTemplate': !ej2_base_1.isNullOrUndefined(column.template),
                'rowID': rowId,
                'column': column,
                'cellType': !ej2_base_1.isNullOrUndefined(cellType) ? cellType : enum_1.CellType.Data,
                'colSpan': colSpan,
                'commands': column.commands,
                'isForeignKey': column.isForeignColumn && column.isForeignColumn(),
                'foreignKeyData': column.isForeignColumn && column.isForeignColumn() && ej2_base_1.getValue(column.field, foreignKeyData)
            };
            if (opt.isDataCell || opt.column.type === 'checkbox' || opt.commands) {
                opt.index = oIndex;
            }
            return new cell_1.Cell(opt);
        };
        RowModelGenerator.prototype.refreshRows = function (input) {
            for (var i = 0; i < input.length; i++) {
                this.refreshForeignKeyRow(input[parseInt(i.toString(), 10)]);
                input[parseInt(i.toString(), 10)].cells = this.generateCells(input[parseInt(i.toString(), 10)]);
            }
            return input;
        };
        RowModelGenerator.prototype.getInfiniteIndex = function (args) {
            return args.requestType === 'infiniteScroll' || args.requestType === 'delete' || args.action === 'add'
                ? (ej2_base_1.isNullOrUndefined(args.startIndex) ? args['index'] : args.startIndex) : 0;
        };
        return RowModelGenerator;
    }());
    exports.RowModelGenerator = RowModelGenerator;
});