UNPKG

@syncfusion/ej2-treegrid

Version:
1,168 lines (1,159 loc) 760 kB
import { Property, merge, ChildProperty, Collection, isNullOrUndefined, Browser, removeClass, addClass, getValue, createElement, setValue, extend as extend$1, Internationalization, getEnumValue, compile, L10n, EventHandler, KeyboardEvents, SanitizeHtmlHelper, Complex, Event, NotifyPropertyChanges, Component, closest, setStyleAttribute, select, classList, debounce, remove } from '@syncfusion/ej2-base'; import { Grid, Logger as Logger$1, detailLists, Clipboard, getObject, parentsUntil, Print as Print$1, templateCompiler, appendChildren, extend, CellRenderer, getUid, CellType, Freeze as Freeze$1, getNumberFormat, getActualProperties, iterateArrayOrObject, RowDropSettings as RowDropSettings$1, Reorder as Reorder$1, Resize as Resize$1, Scroll, RowDD as RowDD$1, VirtualRowModelGenerator, Filter as Filter$1, Data, ExportHelper, ExcelExport as ExcelExport$1, PdfExport as PdfExport$1, Page as Page$1, Toolbar as Toolbar$1, calculateAggregate, Aggregate as Aggregate$1, Sort as Sort$1, ColumnMenu as ColumnMenu$1, ContextMenu as ContextMenu$1, resetRowIndex, Edit as Edit$1, CommandColumn as CommandColumn$1, DetailRow as DetailRow$1, Cell, VirtualContentRenderer, InterSectionObserver, getTransformValues, RenderType, VirtualHeaderRenderer, VirtualScroll as VirtualScroll$1, ColumnChooser as ColumnChooser$1, RowRenderer, InfiniteScroll as InfiniteScroll$1 } from '@syncfusion/ej2-grids'; import { createCheckBox } from '@syncfusion/ej2-buttons'; import { DataManager, ODataAdaptor, WebApiAdaptor, WebMethodAdaptor, CacheAdaptor, UrlAdaptor, Query, DataUtil, RemoteSaveAdaptor, Deferred, JsonAdaptor, Predicate as Predicate$1 } from '@syncfusion/ej2-data'; import { showSpinner, hideSpinner, createSpinner } from '@syncfusion/ej2-popups'; var __extends = (undefined && undefined.__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 __()); }; })(); var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Represents the "Column" model class for TreeGrid, defining essential properties and functionalities of a column. */ var Column = /** @__PURE__ @class */ (function () { function Column(options) { /** * Allows or disallows editing of the column. Set to `false` to make a column non-editable. * By default, all columns are editable. * * @default true */ this.allowEditing = true; /** * Customization options for the edit cell. * * @default {} */ this.edit = {}; /** * When set to `true`, encodes HTML content in headers and cells to prevent HTML injection. * * @default true */ this.disableHtmlEncode = true; /** * Disables column reordering if set to `false`. By default, columns can be reordered. * * @default true */ this.allowReordering = true; /** * Disables column menu for the column if set to `false`. By default, column menus are enabled for all columns. * * @default true */ this.showColumnMenu = true; /** * Disables filtering for the column if set to `false`. By default, columns are filterable. * * @default true */ this.allowFiltering = true; /** * Disables sorting for the column if set to `false`. By default, columns are sortable. * * @default true */ this.allowSorting = true; /** * Disables resizing for the column if set to `false`. By default, columns can be resized. * * @default true */ this.allowResizing = true; /** * Customize default filter options for a specific column, providing types and UI definitions for custom components. * * @default null */ this.filter = {}; merge(this, options); } /** * Reflects state changes for TreeGrid column directives, particularly in React. * * @param {Column} column - The column to update. * @returns {void} * @hidden */ Column.prototype.setProperties = function (column) { var keys = Object.keys(column); for (var i = 0; i < keys.length; i++) { this[keys[parseInt(i.toString(), 10)]] = column[keys[parseInt(i.toString(), 10)]]; if (this.parent && this.parent['isReact'] && keys[parseInt(i.toString(), 10)] === 'template') { var refreshReactColumnTemplateByUid = 'refreshReactColumnTemplateByUid'; this.parent.clipboardModule['treeGridParent'].renderModule["" + refreshReactColumnTemplateByUid](this.uid); } } }; return Column; }()); /** * Defines TreeGrid column */ var TreeGridColumn = /** @__PURE__ @class */ (function (_super) { __extends(TreeGridColumn, _super); function TreeGridColumn() { return _super !== null && _super.apply(this, arguments) || this; } __decorate([ Property(null) ], TreeGridColumn.prototype, "columns", void 0); return TreeGridColumn; }(Column)); /** * Defines stacked tree grid column */ var StackedColumn = /** @__PURE__ @class */ (function (_super) { __extends(StackedColumn, _super); function StackedColumn() { return _super !== null && _super.apply(this, arguments) || this; } return StackedColumn; }(TreeGridColumn)); var __extends$1 = (undefined && undefined.__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 __()); }; })(); var __decorate$1 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Configures the loading indicator for the Tree Grid, allowing you to display a visual indicator during data loading operations to enhance user experience. */ var LoadingIndicator = /** @__PURE__ @class */ (function (_super) { __extends$1(LoadingIndicator, _super); function LoadingIndicator() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$1([ Property('Spinner') ], LoadingIndicator.prototype, "indicatorType", void 0); return LoadingIndicator; }(ChildProperty)); var __extends$2 = (undefined && undefined.__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 __()); }; })(); var __decorate$2 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Represents the filter configuration for a column in the TreeGrid. */ var Predicate = /** @__PURE__ @class */ (function (_super) { __extends$2(Predicate, _super); function Predicate() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Property() ], Predicate.prototype, "field", void 0); __decorate$2([ Property() ], Predicate.prototype, "operator", void 0); __decorate$2([ Property() ], Predicate.prototype, "value", void 0); __decorate$2([ Property() ], Predicate.prototype, "matchCase", void 0); __decorate$2([ Property() ], Predicate.prototype, "ignoreAccent", void 0); __decorate$2([ Property() ], Predicate.prototype, "predicate", void 0); __decorate$2([ Property({}) ], Predicate.prototype, "actualFilterValue", void 0); __decorate$2([ Property({}) ], Predicate.prototype, "actualOperator", void 0); __decorate$2([ Property() ], Predicate.prototype, "type", void 0); __decorate$2([ Property() ], Predicate.prototype, "ejpredicate", void 0); __decorate$2([ Property() ], Predicate.prototype, "uid", void 0); __decorate$2([ Property() ], Predicate.prototype, "isForeignKey", void 0); return Predicate; }(ChildProperty)); /** * Configures the filtering behavior of the TreeGrid, enabling complex data filtering capabilities. */ var FilterSettings = /** @__PURE__ @class */ (function (_super) { __extends$2(FilterSettings, _super); function FilterSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$2([ Collection([], Predicate) ], FilterSettings.prototype, "columns", void 0); __decorate$2([ Property('FilterBar') ], FilterSettings.prototype, "type", void 0); __decorate$2([ Property() ], FilterSettings.prototype, "mode", void 0); __decorate$2([ Property(true) ], FilterSettings.prototype, "showFilterBarStatus", void 0); __decorate$2([ Property(1500) ], FilterSettings.prototype, "immediateModeDelay", void 0); __decorate$2([ Property() ], FilterSettings.prototype, "operators", void 0); __decorate$2([ Property(false) ], FilterSettings.prototype, "ignoreAccent", void 0); __decorate$2([ Property('Parent') ], FilterSettings.prototype, "hierarchyMode", void 0); return FilterSettings; }(ChildProperty)); var __extends$3 = (undefined && undefined.__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 __()); }; })(); var __decorate$3 = (undefined && undefined.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; /** * Configures the text wrapping behavior of the TreeGrid. */ var TextWrapSettings = /** @__PURE__ @class */ (function (_super) { __extends$3(TextWrapSettings, _super); function TextWrapSettings() { return _super !== null && _super.apply(this, arguments) || this; } __decorate$3([ Property('Both') ], TextWrapSettings.prototype, "wrapMode", void 0); return TextWrapSettings; }(ChildProperty)); var __extends$4 = (undefined && undefined.__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 __()); }; })(); /** * Logger module for TreeGrid * * @hidden */ var DOC_URL = 'https://ej2.syncfusion.com/documentation/treegrid'; var BASE_DOC_URL = 'https://ej2.syncfusion.com/documentation'; var ERROR = '[EJ2TreeGrid.Error]'; var IsRowDDEnabled = false; var Logger = /** @__PURE__ @class */ (function (_super) { __extends$4(Logger, _super); function Logger(parent) { var _this = this; Grid.Inject(Logger$1); _this = _super.call(this, parent) || this; return _this; } /** * For internal use only - Get the module name. * * @private * @returns {string} - Returns Logger module name */ Logger.prototype.getModuleName = function () { return 'logger'; }; Logger.prototype.log = function (types, args) { if (!(types instanceof Array)) { types = [types]; } var type = types; for (var i = 0; i < type.length; i++) { var item = detailLists[type[parseInt(i.toString(), 10)]]; var cOp = item.check(args, this.parent); if (cOp.success) { var message = item.generateMessage(args, this.parent, cOp.options); message = message.replace('EJ2Grid', 'EJ2TreeGrid').replace('* Hierarchy Grid', '').replace('* Grouping', ''); if (IsRowDDEnabled && type[parseInt(i.toString(), 10)] === 'primary_column_missing') { message = message.replace('Editing', 'Row DragAndDrop'); IsRowDDEnabled = false; } var index = message.indexOf('https'); var gridurl = message.substring(index); if (type[parseInt(i.toString(), 10)] === 'module_missing') { message = message.replace(gridurl, DOC_URL + '/modules'); } else if (type[parseInt(i.toString(), 10)] === 'primary_column_missing' || type[parseInt(i.toString(), 10)] === 'selection_key_missing') { message = message.replace(gridurl, BASE_DOC_URL + '/api/treegrid/column/#isprimarykey'); } else if (type[parseInt(i.toString(), 10)] === 'grid_remote_edit') { message = message.replace(gridurl, DOC_URL + '/edit'); } else if (type[parseInt(i.toString(), 10)] === 'virtual_height') { message = message.replace(gridurl, DOC_URL + '/virtual'); } else if (type[parseInt(i.toString(), 10)] === 'check_datasource_columns') { message = message.replace(gridurl, DOC_URL + '/columns'); } else if (type[parseInt(i.toString(), 10)] === 'locale_missing') { message = message.replace(gridurl, DOC_URL + '/global-local/#localization'); } if (type[parseInt(i.toString(), 10)] === 'datasource_syntax_mismatch') { if (!isNullOrUndefined(this.treeGridObj) && !isNullOrUndefined(this.treeGridObj.dataStateChange)) { // eslint-disable-next-line no-console console[item.logType](message); } } else { // eslint-disable-next-line no-console console[item.logType](message); } } } }; Logger.prototype.treeLog = function (types, args, treeGrid) { this.treeGridObj = treeGrid; if (!(types instanceof Array)) { types = [types]; } var type = types; if (treeGrid.allowRowDragAndDrop && !treeGrid.columns.filter(function (column) { return column.isPrimaryKey; }).length) { IsRowDDEnabled = true; this.log('primary_column_missing', args); } for (var i = 0; i < type.length; i++) { var item = treeGridDetails[type[parseInt(i.toString(), 10)]]; var cOp = item.check(args, treeGrid); if (cOp.success) { var message = item.generateMessage(args, treeGrid, cOp.options); // eslint-disable-next-line no-console console[item.logType](message); } } }; return Logger; }(Logger$1)); var treeGridDetails = { // eslint-disable-next-line camelcase mapping_fields_missing: { type: 'mapping_fields_missing', logType: 'error', check: function (args, parent) { var opt = { success: false }; if ((isNullOrUndefined(parent.idMapping) && isNullOrUndefined(parent.childMapping) && isNullOrUndefined(parent.parentIdMapping)) || (!isNullOrUndefined(parent.idMapping) && isNullOrUndefined(parent.parentIdMapping)) || (isNullOrUndefined(parent.idMapping) && !isNullOrUndefined(parent.parentIdMapping))) { opt = { success: true }; } return opt; }, generateMessage: function () { return ERROR + ':' + ' MAPPING FIELDS MISSING \n' + 'One of the following fields is missing. It is ' + 'required for the hierarchical relationship of records in TreeGrid:\n' + '* childMapping\n' + '* idMapping\n' + '* parentIdMapping\n' + 'Refer to the following documentation links for more details.\n' + (BASE_DOC_URL + "/api/treegrid#childmapping") + '\n' + (BASE_DOC_URL + "/api/treegrid#idmapping") + '\n' + (BASE_DOC_URL + "/api/treegrid#$parentidmapping"); } } }; /** * @hidden */ var load = 'load'; /** @hidden */ var rowDataBound = 'rowDataBound'; /** @hidden */ var dataBound = 'dataBound'; /** @hidden */ var queryCellInfo = 'queryCellInfo'; /** @hidden */ var beforeDataBound = 'beforeDataBound'; /** @hidden */ var actionBegin = 'actionBegin'; /** @hidden */ var dataStateChange = 'dataStateChange'; /** @hidden */ var actionComplete = 'actionComplete'; /** @hidden */ var rowSelecting = 'rowSelecting'; /** @hidden */ var rowSelected = 'rowSelected'; /** @hidden */ var checkboxChange = 'checkboxChange'; /** @hidden */ var rowDeselected = 'rowDeselected'; /** @hidden */ var toolbarClick = 'toolbarClick'; /** @hidden */ var beforeExcelExport = 'beforeExcelExport'; /** @hidden */ var beforePdfExport = 'beforePdfExport'; /** @hidden */ var resizeStop = 'resizeStop'; /** @hidden */ var expanded = 'expanded'; /** @hidden */ var expanding = 'expanding'; /** @hidden */ var collapsed = 'collapsed'; /** @hidden */ var collapsing = 'collapsing'; /** @hidden */ var remoteExpand = 'remoteExpand'; /** @hidden */ var localPagedExpandCollapse = 'localPagedExpandCollapse'; /** @hidden */ var pagingActions = 'pagingActions'; /** @hidden */ var printGridInit = 'printGrid-Init'; /** @hidden */ var contextMenuOpen = 'contextMenuOpen'; /** @hidden */ var contextMenuClick = 'contextMenuClick'; /** @hidden */ var beforeCopy = 'beforeCopy'; /** @hidden */ var beforePaste = 'beforePaste'; /** @hidden */ var savePreviousRowPosition = 'savePreviousRowPosition'; /** @hidden */ var crudAction = 'crudAction'; /** @hidden */ var beginEdit = 'beginEdit'; /** @hidden */ var beginAdd = 'beginAdd'; /** @hidden */ var recordDoubleClick = 'recordDoubleClick'; /** @hidden */ var cellSave = 'cellSave'; /** @hidden */ var cellSaved = 'cellSaved'; /** @hidden */ var cellEdit = 'cellEdit'; /** @hidden */ var batchDelete = 'batchDelete'; /** @hidden */ var batchCancel = 'batchCancel'; /** @hidden */ var batchAdd = 'batchAdd'; /** @hidden */ var beforeBatchDelete = 'beforeBatchDelete'; /** @hidden */ var beforeBatchAdd = 'beforeBatchAdd'; /** @hidden */ var beforeBatchSave = 'beforeBatchSave'; /** @hidden */ var batchSave = 'batchSave'; /** @hidden */ var keyPressed = 'key-pressed'; /** @hidden */ var updateData = 'update-data'; /** @hidden */ var doubleTap = 'double-tap'; /** @hidden */ var virtualColumnIndex = 'virtualColumnIndex'; /** @hidden */ var virtualActionArgs = 'virtual-action-args'; /** @hidden */ var destroy = 'destroy'; /** @hidden */ var dataListener = 'data-listener'; /** @hidden */ var indexModifier = 'index-modifier'; /** @hidden */ var beforeStartEdit = 'edit-form'; /** @hidden */ var beforeBatchCancel = 'before-batch-cancel'; /** @hidden */ var batchEditFormRendered = 'batcheditform-rendered'; /** @hidden */ var detailDataBound = 'detailDataBound'; /** @hidden */ var rowDrag = 'rowDrag'; /** @hidden */ var rowDragStartHelper = 'rowDragStartHelper'; /** @hidden */ var rowDrop = 'rowDrop'; /** @hidden */ var rowDragStart = 'rowDragStart'; /** @hidden */ var rowsAdd = 'rows-add'; /** @hidden */ var rowsRemove = 'rows-remove'; /** @hidden */ var rowdraging = 'row-draging'; /** @hidden */ var rowDropped = 'row-dropped'; /** @hidden */ var autoCol = 'auto-col'; /** @hidden */ var rowDeselecting = 'rowDeselecting'; /** @hidden */ var headerContent = 'e-headercontent'; /** @hidden */ var movableContent = 'e-movablecontent'; /** @hidden */ var movableHeader = 'e-movableheader'; /** @hidden */ var frozenContent = 'e-frozencontent'; /** @hidden */ var frozenHeader = 'e-frozenheader'; /** @hidden */ var content = 'e-content'; /** @hidden */ var table = 'e-table'; /** @hidden */ var leftRight = 'Left-Right'; /** @hidden */ var frozenRight = 'frozen-right'; /** @hidden */ var frozenLeft = 'frozen-left'; /** @hidden */ var ariaColIndex = 'aria-colindex'; /** @hidden */ var ariaRowIndex = 'aria-rowindex'; /** @hidden */ var actionFailure = 'actionFailure'; var __extends$5 = (undefined && undefined.__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 __()); }; })(); /** * The `Clipboard` module is used to handle clipboard copy action. * * @hidden */ var TreeClipboard = /** @__PURE__ @class */ (function (_super) { __extends$5(TreeClipboard, _super); function TreeClipboard(parent, serviceLocator) { var _this = _super.call(this, parent.grid, serviceLocator) || this; _this.treeCopyContent = ''; _this.copiedUniqueIdCollection = []; _this.treeGridParent = parent; _this.serviceLocator = serviceLocator; return _this; } TreeClipboard.prototype.setCopyData = function (withHeader) { var copyContent = 'copyContent'; var getCopyData = 'getCopyData'; var isSelect = 'isSelect'; var uniqueID = 'uniqueID'; var currentRecords = this.treeGridParent.getCurrentViewRecords(); if (window.getSelection().toString() === '') { this.clipBoardTextArea.value = this["" + copyContent] = ''; var rows = this.treeGridParent.grid.getRows(); if (this.treeGridParent.selectionSettings.mode !== 'Cell') { var selectedIndexes = this.treeGridParent.getSelectedRowIndexes().sort(function (a, b) { return a - b; }); for (var i = 0; i < selectedIndexes.length; i++) { if (i > 0) { this.treeCopyContent += '\n'; } if (!rows[selectedIndexes[parseInt(i.toString(), 10)]].classList.contains('e-summaryrow')) { var cells = [].slice.call(rows[selectedIndexes[parseInt(i.toString(), 10)]].querySelectorAll('.e-rowcell')); var uniqueid = this.treeGridParent.getSelectedRecords()[parseInt(i.toString(), 10)]["" + uniqueID]; if (this.copiedUniqueIdCollection.indexOf(uniqueid) === -1) { if (this.treeGridParent.copyHierarchyMode === 'Parent' || this.treeGridParent.copyHierarchyMode === 'Both') { this.parentContentData(currentRecords, selectedIndexes[parseInt(i.toString(), 10)], rows, withHeader, i); } this["" + getCopyData](cells, false, '\t', withHeader); this.treeCopyContent += this["" + copyContent]; this.copiedUniqueIdCollection.push(uniqueid); this["" + copyContent] = ''; if (this.treeGridParent.copyHierarchyMode === 'Child' || this.treeGridParent.copyHierarchyMode === 'Both') { this.childContentData(currentRecords, selectedIndexes[parseInt(i.toString(), 10)], rows, withHeader); } } } } if (withHeader) { var headerTextArray = []; for (var i = 0; i < this.treeGridParent.getVisibleColumns().length; i++) { headerTextArray[parseInt(i.toString(), 10)] = this.treeGridParent.getVisibleColumns()[parseInt(i.toString(), 10)].headerText; } this["" + getCopyData](headerTextArray, false, '\t', withHeader); this.treeCopyContent = this["" + copyContent] + '\n' + this.treeCopyContent; } var args = { data: this.treeCopyContent, cancel: false }; this.treeGridParent.trigger(beforeCopy, args); if (args.cancel) { return; } this.clipBoardTextArea.value = this["" + copyContent] = args.data; if (!Browser.userAgent.match(/ipad|ipod|iphone/i)) { this.clipBoardTextArea.select(); } else { this.clipBoardTextArea.setSelectionRange(0, this.clipBoardTextArea.value.length); } this["" + isSelect] = true; this.copiedUniqueIdCollection = []; this.treeCopyContent = ''; } else { _super.prototype.setCopyData.call(this, withHeader); } } }; TreeClipboard.prototype.parentContentData = function (currentRecords, selectedIndex, rows, withHeader, index) { var getCopyData = 'getCopyData'; var copyContent = 'copyContent'; var parentItem = 'parentItem'; var uniqueID = 'uniqueID'; var level = 'level'; if (!isNullOrUndefined(currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem])) { var treeLevel = currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem]["" + level]; for (var i = 0; i < treeLevel + 1; i++) { for (var j = 0; j < currentRecords.length; j++) { if (!isNullOrUndefined(currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem]) && currentRecords[parseInt(j.toString(), 10)]["" + uniqueID] === currentRecords[parseInt(selectedIndex.toString(), 10)]["" + parentItem]["" + uniqueID]) { selectedIndex = j; var cells = [].slice.call(rows[parseInt(selectedIndex.toString(), 10)].querySelectorAll('.e-rowcell')); var uniqueid = currentRecords[parseInt(j.toString(), 10)]["" + uniqueID]; if (this.copiedUniqueIdCollection.indexOf(uniqueid) === -1) { this["" + getCopyData](cells, false, '\t', withHeader); if (index > 0) { this.treeCopyContent = this.treeCopyContent + this["" + copyContent] + '\n'; } else { this.treeCopyContent = this["" + copyContent] + '\n' + this.treeCopyContent; } this.copiedUniqueIdCollection.push(uniqueid); this["" + copyContent] = ''; break; } } } } } }; TreeClipboard.prototype.copy = function (withHeader) { _super.prototype.copy.call(this, withHeader); }; TreeClipboard.prototype.paste = function (data, rowIndex, colIndex) { _super.prototype.paste.call(this, data, rowIndex, colIndex); }; /** * For internal use only - Get the module name. * * @private * @returns {string} Returns clipboard module name */ TreeClipboard.prototype.getModuleName = function () { return 'clipboard'; }; /** * To destroy the clipboard * * @returns {void} * @hidden */ TreeClipboard.prototype.destroy = function () { _super.prototype.destroy.call(this); }; TreeClipboard.prototype.childContentData = function (currentRecords, selectedIndex, rows, withHeader) { var getCopyData = 'getCopyData'; var copyContent = 'copyContent'; var childRecords = 'childRecords'; var hasChildRecords = 'hasChildRecords'; var uniqueID = 'uniqueID'; if (currentRecords[parseInt(selectedIndex.toString(), 10)]["" + hasChildRecords]) { var childData = currentRecords[parseInt(selectedIndex.toString(), 10)]["" + childRecords]; for (var i = 0; i < childData.length; i++) { for (var j = 0; j < currentRecords.length; j++) { if (!isNullOrUndefined(childData[parseInt(i.toString(), 10)]["" + uniqueID]) && currentRecords[parseInt(j.toString(), 10)]["" + uniqueID] === childData[parseInt(i.toString(), 10)]["" + uniqueID]) { if ((!isNullOrUndefined(rows[parseInt(j.toString(), 10)])) && !rows[parseInt(j.toString(), 10)].classList.contains('e-summaryrow')) { var cells = [].slice.call(rows[parseInt(j.toString(), 10)].querySelectorAll('.e-rowcell')); var uniqueid = currentRecords[parseInt(j.toString(), 10)]["" + uniqueID]; if (this.copiedUniqueIdCollection.indexOf(uniqueid) === -1) { this["" + getCopyData](cells, false, '\t', withHeader); this.treeCopyContent += ('\n' + this["" + copyContent]); this["" + copyContent] = ''; this.copiedUniqueIdCollection.push(uniqueid); this.childContentData(currentRecords, j, rows, withHeader); } } break; } } } } }; return TreeClipboard; }(Clipboard)); /** * @param {TreeGrid} parent - Tree Grid instance * @returns {boolean} - Specifies whether remote data binding */ function isRemoteData(parent) { if (parent.dataSource instanceof DataManager) { var adaptor = parent.dataSource.adaptor; return (adaptor instanceof ODataAdaptor || (adaptor instanceof WebApiAdaptor) || (adaptor instanceof WebMethodAdaptor) || (adaptor instanceof CacheAdaptor) || adaptor instanceof UrlAdaptor); } return false; } /** * @param {TreeGrid | IGrid} parent - Tree Grid or Grid instance * @returns {boolean} - Returns whether custom binding */ function isCountRequired(parent) { if (parent.dataSource && 'result' in parent.dataSource) { return true; } return false; } /** * @param {TreeGrid} parent - Tree Grid instance * @returns {boolean} - Returns whether checkbox column is enabled */ function isCheckboxcolumn(parent) { for (var i = 0; i < parent.columns.length; i++) { if (parent.columns[parseInt(i.toString(), 10)].showCheckbox) { return true; } } return false; } /** * @param {TreeGrid} parent - Tree Grid instance * @returns {boolean} - Returns whether filtering and searching done */ function isFilterChildHierarchy(parent) { if ((!isNullOrUndefined(parent.grid.searchSettings.key) && parent.grid.searchSettings.key !== '' && (parent.searchSettings.hierarchyMode === 'Child' || parent.searchSettings.hierarchyMode === 'None')) || (parent.allowFiltering && parent.grid.filterSettings.columns.length && (parent.filterSettings.hierarchyMode === 'Child' || parent.filterSettings.hierarchyMode === 'None'))) { return true; } return false; } /** * @param {Object} records - Define records for which parent records has to be found * @hidden * @returns {Object} - Returns parent records collection */ function findParentRecords(records) { var datas = []; var recordsLength = Object.keys(records).length; for (var i = 0, len = recordsLength; i < len; i++) { var hasChild = getObject('hasChildRecords', records[parseInt(i.toString(), 10)]); if (hasChild) { datas.push(records[parseInt(i.toString(), 10)]); } } return datas; } /** * @param {TreeGrid} parent - Tree Grid instance * @returns {boolean} - Returns the expand status of record * @param {ITreeData} record - Define the record for which expand status has be found * @param {ITreeData[]} parents - Parent Data collection * @hidden */ function getExpandStatus(parent, record, parents) { var parentRecord = isNullOrUndefined(record.parentItem) ? null : getParentData(parent, record.parentItem.uniqueID); var childParent; if (parentRecord != null) { if (parent.initialRender && !isNullOrUndefined(parentRecord[parent.expandStateMapping]) && !parentRecord[parent.expandStateMapping]) { parentRecord.expanded = false; return false; } else if (parentRecord.expanded === false) { return false; } else if (parentRecord.parentItem) { childParent = getParentData(parent, parentRecord.parentItem.uniqueID); if (childParent && parent.initialRender && !isNullOrUndefined(childParent[parent.expandStateMapping]) && !childParent[parent.expandStateMapping]) { childParent.expanded = false; return false; } if (childParent && childParent.expanded === false) { return false; } else if (childParent) { return getExpandStatus(parent, childParent); } return true; } else { return true; } } else { return true; } } /** * @param {ITreeData} records - Define the record for which child records has to be found * @returns {Object[]} - Returns child records collection * @hidden */ function findChildrenRecords(records) { var datas = []; if (isNullOrUndefined(records) || (!records.hasChildRecords && !isNullOrUndefined(records.childRecords) && !records.childRecords.length)) { return []; } if (!isNullOrUndefined(records.childRecords)) { var childRecords = records.childRecords.filter(function (item) { return !item.isSummaryRow; }); var keys = Object.keys(childRecords); for (var i = 0, len = keys.length; i < len; i++) { datas.push(childRecords[parseInt(i.toString(), 10)]); if (childRecords[parseInt(i.toString(), 10)].hasChildRecords || (!isNullOrUndefined(childRecords[parseInt(i.toString(), 10)].childRecords) && childRecords[parseInt(i.toString(), 10)].childRecords.length)) { datas = datas.concat(findChildrenRecords(childRecords[parseInt(i.toString(), 10)])); } } } return datas; } /** * @param {TreeGrid} parent - Tree Grid instance * @returns {boolean} - Returns whether local data binding */ function isOffline(parent) { if (isRemoteData(parent)) { var dm = parent.dataSource; return !isNullOrUndefined(dm.ready); } return true; } /** * @param {Object[]} array - Defines the array to be cloned * @returns {Object[]} - Returns cloned array collection */ function extendArray(array) { var objArr = []; var obj; var keys; for (var i = 0; array && i < array.length; i++) { keys = Object.keys(array[parseInt(i.toString(), 10)]); obj = {}; for (var j = 0; j < keys.length; j++) { obj[keys[parseInt(j.toString(), 10)]] = array[parseInt(i.toString(), 10)][keys[parseInt(j.toString(), 10)]]; } objArr.push(obj); } return objArr; } /** * @param {ITreeData} value - Defined the dirty data to be cleaned * @returns {ITreeData} - Returns cleaned original data */ function getPlainData(value) { delete value.hasChildRecords; delete value.childRecords; delete value.index; delete value.parentItem; delete value.level; delete value.taskData; delete value.uniqueID; return value; } /** * @param {TreeGrid} parent - TreeGrid instance * @param {string} value - IdMapping field name * @param {boolean} requireFilter - Specified whether treegrid data is filtered * @returns {ITreeData} - Returns IdMapping matched record */ function getParentData(parent, value, requireFilter) { if (requireFilter) { var idFilter = 'uniqueIDFilterCollection'; return parent["" + idFilter]["" + value]; } else { var id = 'uniqueIDCollection'; return parent["" + id]["" + value]; } } /** * @param {HTMLTableRowElement} el - Row element * @returns {boolean} - Returns whether hidden */ function isHidden(el) { var style = window.getComputedStyle(el); return ((style.display === 'none') || (style.visibility === 'hidden')); } /** * TreeGrid Selection module * * @hidden */ var Selection = /** @__PURE__ @class */ (function () { /** * Constructor for Selection module * * @param {TreeGrid} parent - Tree Grid instance */ function Selection(parent) { this.parent = parent; this.selectedItems = []; this.selectedIndexes = []; this.filteredList = []; this.searchingRecords = []; this.addEventListener(); } /** * For internal use only - Get the module name. * * @private * @returns {string} Returns Selection module name */ Selection.prototype.getModuleName = function () { return 'selection'; }; Selection.prototype.addEventListener = function () { this.parent.on('dataBoundArg', this.headerCheckbox, this); this.parent.on('columnCheckbox', this.columnCheckbox, this); this.parent.on('updateGridActions', this.updateGridActions, this); this.parent.grid.on('colgroup-refresh', this.headerCheckbox, this); this.parent.on('checkboxSelection', this.checkboxSelection, this); }; Selection.prototype.removeEventListener = function () { if (this.parent.isDestroyed) { return; } this.parent.off('dataBoundArg', this.headerCheckbox); this.parent.off('columnCheckbox', this.columnCheckbox); this.parent.grid.off('colgroup-refresh', this.headerCheckbox); this.parent.off('checkboxSelection', this.checkboxSelection); this.parent.off('updateGridActions', this.updateGridActions); }; /** * To destroy the Selection * * @returns {void} * @hidden */ Selection.prototype.destroy = function () { this.removeEventListener(); }; Selection.prototype.checkboxSelection = function (args) { var _a; var target = getObject('target', args); var checkWrap = parentsUntil(target, 'e-checkbox-wrapper'); var checkBox; if (checkWrap && checkWrap.querySelectorAll('.e-treecheckselect').length > 0) { checkBox = checkWrap.querySelector('input[type="checkbox"]'); var rowIndex = []; rowIndex.push(target.closest('tr').rowIndex); this.selectCheckboxes(rowIndex); this.triggerChkChangeEvent(checkBox, checkBox.nextElementSibling.classList.contains('e-check'), target.closest('tr')); } else if (checkWrap && checkWrap.querySelectorAll('.e-treeselectall').length > 0 && this.parent.autoCheckHierarchy) { var checkBoxvalue = !checkWrap.querySelector('.e-frame').classList.contains('e-check') && !checkWrap.querySelector('.e-frame').classList.contains('e-stop'); this.headerSelection(checkBoxvalue); checkBox = checkWrap.querySelector('input[type="checkbox"]'); this.triggerChkChangeEvent(checkBox, checkBoxvalue, target.closest('tr')); } if (!isNullOrUndefined(this.parent['parentQuery']) && this.parent.selectionSettings.persistSelection && this.parent['columnModel'].filter(function (col) { return col.type === 'checkbox'; }).length > 0 && isRemoteData(this.parent)) { if (this.parent['parentQuery'].length > 0) { (_a = this.parent.query.queries).push.apply(_a, this.parent['parentQuery']); this.parent['parentQuery'] = []; } } }; Selection.prototype.triggerChkChangeEvent = function (checkBox, checkState, rowElement) { var data = this.parent.getCurrentViewRecords()[rowElement.rowIndex]; var args = { checked: checkState, target: checkBox, rowElement: rowElement, rowData: checkBox.classList.contains('e-treeselectall') ? this.parent.getCheckedRecords() : data }; this.parent.trigger(checkboxChange, args); }; Selection.prototype.getCheckboxcolumnIndex = function () { var mappingUid; var columnIndex; var stackedHeader = 'stackedHeader'; var columnModel = 'columnModel'; var columns = this.parent["" + stackedHeader] ? this.parent["" + columnModel] : (this.parent.columns); for (var col = 0; col < columns.length; col++) { if (columns[parseInt(col.toString(), 10)].showCheckbox) { mappingUid = columns[parseInt(col.toString(), 10)].uid; } } var headerCelllength = this.parent.getHeaderContent().querySelectorAll('.e-headercelldiv').length; for (var j = 0; j < headerCelllength; j++) { var headercell = this.parent.getHeaderContent().querySelectorAll('.e-headercelldiv')[parseInt(j.toString(), 10)]; if (headercell.getAttribute('e-mappinguid') === mappingUid) { columnIndex = j; } } return columnIndex; }; Selection.prototype.headerCheckbox = function () { this.columnIndex = this.getCheckboxcolumnIndex(); if (this.columnIndex > -1 && this.parent.getHeaderContent().querySelectorAll('.e-treeselectall').length === 0) { var headerElement = this.parent.getHeaderContent().querySelectorAll('.e-headercelldiv')[this.columnIndex]; var value = false; var rowChkBox = this.parent.createElement('input', { className: 'e-treeselectall', attrs: { 'type': 'checkbox' } }); var checkWrap = createCheckBox(this.parent.createElement, false, { checked: value, label: ' ' }); checkWrap.classList.add('e-hierarchycheckbox'); checkWrap.insertBefore(rowChkBox.cloneNode(), checkWrap.firstChild); if (!isNullOrUndefined(headerElement)) { headerElement.insertBefore(checkWrap, headerElement.firstChild); } if (this.parent.autoCheckHierarchy) { this.headerSelection(); } } else if (this.columnIndex > -1 && this.parent.getHeaderContent().querySelectorAll('.e-treeselectall').length > 0) { var checkWrap = this.parent.getHeaderContent().querySelectorAll('.e-checkbox-wrapper')[0]; var checkBoxvalue = checkWrap.querySelector('.e-frame').classList.contains('e-check'); if (this.parent.autoCheckHierarchy && checkBoxvalue) { this.headerSelection(checkBoxvalue); } } }; Selection.prototype.renderColumnCheckbox = function (args) { var rowChkBox = this.parent.createElement('input', { className: 'e-treecheckselect', attrs: { 'type': 'checkbox', 'aria-label': 'checkbox' } }); var data = args.data; args.cell.classList.add('e-treegridcheckbox'); args.cell.setAttribute('aria-label', 'checkbox'); var value = (isNullOrUndefined(data.checkboxState) || data.checkboxState === 'uncheck') ? false : true; var checkWrap = createCheckBox(this.parent.createElement, false, { checked: value, label: ' ' }); checkWrap.classList.add('e-hierarchycheckbox'); if (this.parent.allowTextWrap) { checkWrap.querySelector('.e-frame').style.width = '18px'; } if (data.checkboxState === 'indeterminate') { var checkbox = checkWrap.querySelectorAll('.e-frame')[0]; removeClass([checkbox], ['e-check', 'e-stop', 'e-uncheck']); checkWrap.querySelector('.e-frame').classList.add('e-stop'); } checkWrap.insertBefore(rowChkBox.cloneNode(), checkWrap.firstChild); return checkWrap; }; Selection.prototype.columnCheckbox = function (container) { var checkWrap = this.renderColumnCheckbox(container); var containerELe = container.cell.querySelector('.e-treecolumn-container'); if (!isNullOrUndefined(containerELe)) { if (!container.cell.querySelector('.e-hierarchycheckbox')) { containerELe.insertBefore(checkWrap, containerELe.querySelectorAll('.e-treecell')[0]); } } else { var spanEle = this.parent.createElement('span', { className: 'e-treecheckbox' }); var data = container.cell.innerHTML; container.cell.innerHTML = ''; spanEle.innerHTML = data; var divEle = this.parent.createElement('div', { className: 'e-treecheckbox-container' }); divEle.appendChild(checkWrap); divEle.appendChild(spanEle); container.cell.appendChild(divEle); } }; Selection.prototype.selectCheckboxes = function (rowIndexes) { if (isNullOrUndefined(rowIndexes)) { var error = 'The provided value for the rowIndexes is undefined. Please ensure the rowIndexes contains number.'; this.parent.trigger(actionFailure, { error: error }); } for (var i = 0; i < rowIndexes.length; i++) { var record = this.parent.getCurrentViewRecords()[rowIndexes[parseInt(i.toString(), 10)]]; var flatRecord = getParentData(this.parent, record.uniqueID); record = flatRecord; var checkboxState = (record.checkboxState === 'uncheck') ? 'check' : 'uncheck'; record.checkboxState = checkboxState; var keys = Object.keys(record); for (var j = 0; j < keys.length; j++) { if (Object.prototype.hasOwnProperty.call(flatRecord, keys[parseInt(j.toString(), 10)])) { flatRecord[keys[parseInt(j.toString(), 10)]] = record[keys[parseInt(j.toString(), 10)]]; } } this.traverSelection(record, checkboxState, false); if (this.parent.autoCheckHierarchy) { this.headerSelection(); } } }; Selection.prototype.traverSelection = f