all files / treegrid/actions/ virtual-scroll.js

86.71% Statements 137/158
72.03% Branches 85/118
95.45% Functions 21/22
86.45% Lines 134/155
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          42× 42× 42× 42× 42× 42× 42×       11279×   42×     42× 42× 42×   41× 41×           69× 69× 69× 69×             69×   58×   69×   69× 69×   145× 145× 145× 145× 145× 132728×   145× 145× 145× 145× 145× 145× 145× 145× 145× 120× 120× 120× 120× 120× 120× 120×     25× 25×     25×         25× 25× 25×         25×                     25×           25×               25× 25× 25×       25×   25× 25× 25×   145×   41×     42× 42× 42× 42×   5254×   42× 42× 42× 42×     42×   42×   42× 42× 42×   42×   42× 42× 42× 42×        
/* 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-grids", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "../base/constant", "@syncfusion/ej2-data", "../utils", "../renderer/virtual-tree-content-render", "@syncfusion/ej2-grids"], function (require, exports, ej2_grids_1, ej2_grids_2, ej2_base_1, events, ej2_data_1, utils_1, virtual_tree_content_render_1, ej2_grids_3) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var VirtualScroll = (function () {
        function VirtualScroll(parent) {
            this.prevstartIndex = -1;
            this.setEndIndexToGantt = true;
            this.prevendIndex = -1;
            this.prevSelectedRecord = [];
            this.parent = parent;
            ej2_grids_1.Grid.Inject(TreeVirtual);
            this.addEventListener();
        }
        VirtualScroll.prototype.returnVisualData = function (args) {
            args.data = this.visualData;
        };
        VirtualScroll.prototype.getModuleName = function () {
            return 'virtualScroll';
        };
        VirtualScroll.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.localPagedExpandCollapse, this.collapseExpandVirtualchilds, this);
            this.parent.on(events.pagingActions, this.virtualPageAction, this);
            this.parent.on(events.destroy, this.destroy, this);
        };
        VirtualScroll.prototype.removeEventListener = function () {
            Eif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.localPagedExpandCollapse, this.collapseExpandVirtualchilds);
            this.parent.off(events.pagingActions, this.virtualPageAction);
            this.parent.off(events.destroy, this.destroy);
        };
        VirtualScroll.prototype.collapseExpandVirtualchilds = function (row) {
            this.parent.grid.notify(events.virtualActionArgs, { isExpandCollapse: true });
            this.expandCollapseRec = row.record;
            row.record.expanded = row.action === 'collapse' ? false : true;
            var ret = {
                result: this.parent.flatData,
                row: row.row,
                action: row.action,
                record: row.record,
                count: this.parent.flatData.length
            };
            if (this.parent.enableVirtualization && this.parent.selectionSettings.mode === 'Cell' ||
                this.parent.selectionSettings.mode === 'Row' && !this.parent.selectionSettings.persistSelection) {
                this.parent.grid.clearSelection();
            }
            if (ej2_base_1.getValue('isCollapseAll', this.parent) && this.parent.selectionSettings.persistSelection && this.parent.getSelectedRecords().length > 0) {
                this.prevSelectedRecord = this.parent.getSelectedRecords();
                this.parent.grid.clearSelection();
            }
            var requestType = ej2_base_1.getValue('isCollapseAll', this.parent) ? 'collapseAll' : 'refresh';
            ej2_base_1.getValue('grid.renderModule', this.parent).dataManagerSuccess(ret, { requestType: requestType });
        };
        VirtualScroll.prototype.virtualPageAction = function (pageingDetails) {
            var _this = this;
            var dm = new ej2_data_1.DataManager(pageingDetails.result);
            var expanded = new ej2_data_1.Predicate('expanded', 'notequal', null).or('expanded', 'notequal', undefined);
            var parents = dm.executeLocal(new ej2_data_1.Query().where(expanded));
            var visualData = parents.filter(function (e) {
                return utils_1.getExpandStatus(_this.parent, e, parents);
            });
            this.visualData = visualData;
            pageingDetails.count = visualData.length;
            this.parent.grid.notify(events.dataListener, { data: visualData });
            var counts = { startIndex: -1, endIndex: -1, count: pageingDetails.count, requestType: pageingDetails.actionArgs.requestType };
            this.parent.grid.notify(events.indexModifier, counts);
            var startIndex = counts.startIndex;
            var endIndex = counts.endIndex;
            pageingDetails.count = visualData.length;
            if (startIndex === -1 && endIndex === -1) {
                var query = new ej2_data_1.Query();
                var size = this.parent.grid.pageSettings.pageSize;
                var current = this.parent.grid.pageSettings.currentPage;
                var skip = size * (current - 1);
                query = query.skip(skip).take(size);
                dm.dataSource.json = visualData;
                pageingDetails.result = dm.executeLocal(query);
            }
            else {
                var requestType = pageingDetails.actionArgs.requestType;
                if (requestType === 'filtering' || requestType === 'collapseAll' || requestType === 'searching' || (requestType === 'refresh' && ej2_base_1.getValue('isExpandAll', this.parent)) ||
                    (requestType === 'refresh' && this.parent.enableCollapseAll && endIndex > visualData.length && ej2_base_1.isNullOrUndefined(this.expandCollapseRec))) {
                    startIndex = 0;
                    endIndex = this.parent.grid.pageSettings.pageSize - 1;
                    this.parent.grid.getContent().firstElementChild.scrollTop = 0;
                    this.parent.grid.notify(events.virtualActionArgs, { setTop: true });
                }
                if ((requestType === 'save' && pageingDetails.actionArgs.index >= (counts.count - this.parent.grid.pageSettings.pageSize)) || (requestType === 'refresh' && this.parent['isGantt'] && this.parent['isAddedFromGantt'])) {
                    Eif (this.setEndIndexToGantt) {
                        this.ganttEndIndex = counts.endIndex;
                    }
                    Eif ((counts.endIndex + this.parent.pageSettings.pageSize >= counts.count && (this.parent.root && counts.count - this.ganttEndIndex === this.visualData.length - this.parent.root['previousFlatData'].length))
                        || !(this.parent['isGantt'] && this.parent['isAddedFromGantt'])) {
                        startIndex = counts.startIndex + (counts.count - counts.endIndex);
                        endIndex = counts.count;
                        this.setEndIndexToGantt = false;
                    }
                    this.ganttEndIndex = endIndex;
                    this.parent['isAddedFromGantt'] = false;
                }
                var virtualWrapperElement = this.parent.grid.contentModule.virtualEle.wrapper;
                var translateY = ej2_grids_3.getTransformValues(virtualWrapperElement).height;
                Iif (!ej2_base_1.isNullOrUndefined(this.expandCollapseRec) && (pageingDetails.actionArgs.requestType === 'virtualscroll' ||
                    (pageingDetails.actionArgs.requestType === 'refresh' && startIndex !== this.prevstartIndex)) &&
                    (startIndex < this.parent.getRows().length && endIndex <= startIndex + this.parent.getRows().length) && translateY === 0) {
                    startIndex = 0;
                }
                if (!ej2_base_1.isNullOrUndefined(this.expandCollapseRec)) {
                    var resourceCount = this.parent.getRows();
                    var sIndex = visualData.indexOf(this.expandCollapseRec);
                    var tempdata = visualData.slice(sIndex, sIndex + resourceCount.length);
                    Iif (tempdata.length < resourceCount.length && sIndex >= 0 && startIndex !== 0) {
                        sIndex = visualData.length - resourceCount.length;
                        sIndex = sIndex > 0 ? sIndex : 0;
                        startIndex = sIndex;
                        endIndex = visualData.length;
                    }
                    else Iif (ej2_base_1.getValue('isCollapseAll', this.parent)) {
                        startIndex = 0;
                        endIndex = this.parent.grid.pageSettings.pageSize - 1;
                        this.parent.grid.notify(events.virtualActionArgs, { setTop: true });
                    }
                }
                Iif (this.prevrequestType === 'collapseAll' && pageingDetails.actionArgs.requestType === 'virtualscroll'
                    && !ej2_base_1.isNullOrUndefined(this.parent.idMapping) && startIndex === 0) {
                    startIndex = 0;
                    endIndex = this.parent.grid.pageSettings.pageSize - 1;
                    this.parent.grid.notify(events.virtualActionArgs, { setTop: true });
                }
                Iif ((this.parent.enableCollapseAll || this.parent.expandStateMapping) && !ej2_base_1.isNullOrUndefined(this.expandCollapseRec)) {
                    if (pageingDetails.count < this.parent.getRows()[0].getBoundingClientRect().height) {
                        startIndex = 0;
                    }
                    else if (!this.parent['isExpandAll']) {
                        startIndex = this.prevstartIndex === -1 ? 0 : this.prevstartIndex;
                    }
                }
                this.expandCollapseRec = null;
                startIndex = startIndex < 0 ? 0 : startIndex;
                Iif (endIndex === 0 && visualData.length > 0) {
                    pageingDetails.result = visualData;
                }
                else {
                    pageingDetails.result = visualData.slice(startIndex, endIndex);
                }
                this.prevstartIndex = startIndex;
                this.prevendIndex = endIndex;
                this.prevrequestType = pageingDetails.actionArgs.requestType;
            }
            this.parent.notify('updateAction', pageingDetails);
        };
        VirtualScroll.prototype.destroy = function () {
            this.removeEventListener();
        };
        return VirtualScroll;
    }());
    exports.VirtualScroll = VirtualScroll;
    var TreeVirtual = (function (_super) {
        __extends(TreeVirtual, _super);
        function TreeVirtual(parent, locator) {
            var _this = _super.call(this, parent, locator) || this;
            ej2_base_1.getValue('parent', _this).off('initial-load', ej2_base_1.getValue('instantiateRenderer', _this), _this);
            ej2_base_1.getValue('parent', _this).on('initial-load', _this.instantiateRenderers, _this);
            return _this;
        }
        TreeVirtual.prototype.getModuleName = function () {
            return 'treeVirtualScroll';
        };
        TreeVirtual.prototype.instantiateRenderers = function () {
            var parentGrid = ej2_base_1.getValue('parent', this);
            ej2_base_1.getValue('parent', this).log(['limitation', 'virtual_height'], 'virtualization');
            var renderer = ej2_base_1.getValue('locator', this).getService('rendererFactory');
            if (parentGrid.enableColumnVirtualization) {
                ej2_base_1.getValue('addRenderer', renderer)
                    .apply(renderer, [ej2_grids_2.RenderType.Header, new ej2_grids_3.VirtualHeaderRenderer(ej2_base_1.getValue('parent', this), ej2_base_1.getValue('locator', this))]);
            }
            ej2_base_1.getValue('addRenderer', renderer)
                .apply(renderer, [ej2_grids_2.RenderType.Content, new virtual_tree_content_render_1.VirtualTreeContentRenderer(ej2_base_1.getValue('parent', this), ej2_base_1.getValue('locator', this))]);
            this.ensurePageSize();
        };
        TreeVirtual.prototype.ensurePageSize = function () {
            var parentGrid = ej2_base_1.getValue('parent', this);
            var rowHeight = parentGrid.getRowHeight();
            if (!ej2_base_1.isNullOrUndefined(parentGrid.height) && typeof (parentGrid.height) === 'string' && parentGrid.height.indexOf('%') !== -1) {
                parentGrid.element.style.height = parentGrid.height;
            }
            var vHeight = parentGrid.height.toString().indexOf('%') < 0 ? parseInt(parentGrid.height.toString(), 10) :
                parentGrid.element.getBoundingClientRect().height;
            var blockSize = ~~(vHeight / rowHeight);
            var height = blockSize * 2;
            var size = parentGrid.pageSettings.pageSize;
            parentGrid.setProperties({ pageSettings: { pageSize: size < height ? height : size } }, true);
        };
        return TreeVirtual;
    }(ej2_grids_1.VirtualScroll));
    exports.TreeVirtual = TreeVirtual;
});