UNPKG

@syncfusion/ej2-treegrid

Version:
111 lines (110 loc) 5.39 kB
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 __()); }; })(); import { VirtualRowModelGenerator } from '@syncfusion/ej2-grids'; import * as events from '../base/constant'; import { isNullOrUndefined } from '@syncfusion/ej2-base'; import { DataManager } from '@syncfusion/ej2-data'; import { isCountRequired, isRemoteData } from '../utils'; /** * RowModelGenerator is used to generate grid data rows. * * @hidden */ var TreeVirtualRowModelGenerator = /** @class */ (function (_super) { __extends(TreeVirtualRowModelGenerator, _super); function TreeVirtualRowModelGenerator(parent) { var _this = _super.call(this, parent) || this; _this.addEventListener(); return _this; } TreeVirtualRowModelGenerator.prototype.addEventListener = function () { this.parent.on(events.dataListener, this.getDatas, this); }; TreeVirtualRowModelGenerator.prototype.getDatas = function (args) { this.visualData = args.data; }; TreeVirtualRowModelGenerator.prototype.getDataInfo = function () { return _super.prototype.getData.call(this); }; TreeVirtualRowModelGenerator.prototype.generateRows = function (data, notifyArgs) { var info = this.getDataInfo(); if (notifyArgs.requestType === 'refresh' && notifyArgs.isExpandCollapse) { notifyArgs.virtualInfo = this['prevInfo']; } if (!isNullOrUndefined(notifyArgs.virtualInfo) && !(this.parent.root.loadChildOnDemand && isRemoteData(this.parent.root))) { if (notifyArgs.virtualInfo.direction !== 'right' && notifyArgs.virtualInfo.direction !== 'left') { if ((!isRemoteData(this.parent.root) || isCountRequired(this.parent)) || notifyArgs.virtualInfo.blockIndexes.length === 1) { notifyArgs.virtualInfo.blockIndexes = info.blockIndexes; } } else { notifyArgs.virtualInfo.blockIndexes = this.getBlockIndexes(notifyArgs.virtualInfo.page); } } if ((this.parent.dataSource instanceof DataManager && this.parent.dataSource.dataSource.url !== undefined && !this.parent.dataSource.dataSource.offline && this.parent.dataSource.dataSource.url !== '') || isCountRequired(this.parent)) { return _super.prototype.generateRows.call(this, data, notifyArgs); } else { if (!isNullOrUndefined(notifyArgs.requestType) && notifyArgs.requestType.toString() === 'collapseAll') { notifyArgs.requestType = 'refresh'; } var rows = _super.prototype.generateRows.call(this, data, notifyArgs); if (!isNullOrUndefined((this.visualData))) { for (var r = 0; r < rows.length; r++) { rows[parseInt(r.toString(), 10)].index = (this.visualData).indexOf(rows[parseInt(r.toString(), 10)].data); } } return rows; } }; TreeVirtualRowModelGenerator.prototype.checkAndResetCache = function (action) { var clear = ['paging', 'refresh', 'sorting', 'filtering', 'searching', 'reorder', 'save', 'delete'].some(function (value) { return action === value; }); if ((this.parent.dataSource instanceof DataManager && this.parent.dataSource.dataSource.url !== undefined && !this.parent.dataSource.dataSource.offline && this.parent.dataSource.dataSource.url !== '') || isCountRequired(this.parent)) { var model = 'model'; var currentPage = this["" + model].currentPage; if (clear) { this.cache = {}; /*this.movableCache = {}; this.frozenRightCache = {};*/ this.data = {}; this.groups = {}; } else if (action === 'virtualscroll' && this.cache[parseInt(currentPage.toString(), 10)] && this.cache[parseInt(currentPage.toString(), 10)].length > (this.parent.contentModule).getBlockSize()) { if (this.cache[parseInt(currentPage.toString(), 10)].length > (this.parent.contentModule).getBlockSize()) { this.cache[parseInt(currentPage.toString(), 10)] = this.cache[parseInt(currentPage.toString(), 10)].slice(0, (this.parent.contentModule).getBlockSize()); } } } else { if (clear || action === 'virtualscroll') { this.cache = {}; this.data = {}; this.groups = {}; /*this.movableCache = {}; this.frozenRightCache = {};*/ } } return clear; }; return TreeVirtualRowModelGenerator; }(VirtualRowModelGenerator)); export { TreeVirtualRowModelGenerator };