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 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 26× 26× 26× 26× 26× 26× 26× 26× 1× 64× 1560× 1552× 1552× 1552× 64× 64× 39× 39× 13× 125× 125× 123× 125× 13× 25× 25× 1× 586× 586× 586× 586× 586× 32× 32× 554× 1645× 1645× 586× 586× 21× 21× 565× 565× 586× 17× 586× 1× 1645× 1645× 1645× 1645× 1645× 1645× 1645× 1645× 1645× 702× 702× 702× 702× 1645× 1× 1× | /* 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", "@syncfusion/ej2-buttons", "./cell-renderer", "../base/util", "../base/constant"], function (require, exports, ej2_base_1, ej2_buttons_1, cell_renderer_1, util_1, constant_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var CommandColumnRenderer = (function (_super) { __extends(CommandColumnRenderer, _super); function CommandColumnRenderer(parent, locator) { var _this = _super.call(this, parent, locator) || this; _this.buttonElement = _this.parent.createElement('button', {}); _this.unbounDiv = _this.parent.createElement('div', { className: 'e-unboundcelldiv', styles: 'display: inline-block' }); _this.childRefs = []; _this.element = _this.parent.createElement('TD', { className: 'e-rowcell e-unboundcell', attrs: { tabindex: '-1', role: 'gridcell' } }); _this.parent.on(constant_1.destroy, _this.destroyButtons, _this); _this.parent.on(constant_1.commandColumnDestroy, _this.destroyButtons, _this); return _this; } CommandColumnRenderer.prototype.destroyButtons = function (args) { for (var i = 0; i < this.childRefs.length; i++) { if (this.childRefs[parseInt(i.toString(), 10)] && !this.childRefs[parseInt(i.toString(), 10)].isDestroyed && !(this.parent.editSettings.showAddNewRow && this.parent.enableVirtualization && util_1.parentsUntil(this.childRefs[parseInt(i.toString(), 10)].element, 'e-addedrow'))) { this.childRefs[parseInt(i.toString(), 10)].destroy(); Eif (this.childRefs[parseInt(i.toString(), 10)].element) { this.childRefs[parseInt(i.toString(), 10)].element.innerHTML = ''; } } } this.childRefs = []; if (args.type === 'refreshCommandColumn') { var elem = this.parent.element.querySelectorAll('.e-gridcontent .e-unboundcell'); if (elem.length) { for (var i = 0; i < elem.length; i++) { Eif (elem[parseInt(i.toString(), 10)] && !(this.parent.editSettings.showAddNewRow && this.parent.enableVirtualization && util_1.parentsUntil(elem[parseInt(i.toString(), 10)], 'e-addedrow'))) { if (elem[parseInt(i.toString(), 10)].querySelector('.e-unboundcelldiv')) { elem[parseInt(i.toString(), 10)].querySelector('.e-unboundcelldiv').innerHTML = ''; } elem[parseInt(i.toString(), 10)].innerHTML = ''; } } elem = null; } } else { this.parent.off(constant_1.destroy, this.destroyButtons); this.parent.off(constant_1.commandColumnDestroy, this.destroyButtons); } }; CommandColumnRenderer.prototype.render = function (cell, data, attributes, isVirtualEdit) { var node = this.element.cloneNode(); var uid = 'uid'; node.appendChild(this.unbounDiv.cloneNode()); node.setAttribute('aria-label', this.localizer.getConstant('CommandColumnAria') + cell.column.headerText); if (cell.column.commandsTemplate) { Iif (this.parent.isReact && typeof (cell.column.commandsTemplate) !== 'string' && !(cell.column.commandsTemplate.prototype && cell.column.commandsTemplate.prototype.CSPTemplate)) { var tempID = this.parent + 'commandsTemplate'; cell.column.getColumnTemplate()(data, this.parent, 'commandsTemplate', tempID, null, null, node.firstElementChild); this.parent.renderTemplates(); } else { util_1.appendChildren(node.firstElementChild, cell.column.getColumnTemplate()(data, this.parent, 'commandsTemplate', null, null, null, null, this.parent.root)); } } else { for (var _i = 0, _a = cell.commands; _i < _a.length; _i++) { var command = _a[_i]; node = this.renderButton(node, command, attributes.index, command["" + uid]); } } this.setAttributes(node, cell, attributes); if ((!this.parent.enableVirtualization && (this.parent.isEdit && (!this.parent.editSettings.showAddNewRow || (this.parent.editSettings.showAddNewRow && (!this.parent.element.querySelector('.e-editedrow')))))) || isVirtualEdit) { ej2_base_1.addClass([].slice.call(node.getElementsByClassName('e-edit-delete')), 'e-hide'); ej2_base_1.removeClass([].slice.call(node.getElementsByClassName('e-save-cancel')), 'e-hide'); } else { ej2_base_1.addClass([].slice.call(node.getElementsByClassName('e-save-cancel')), 'e-hide'); ej2_base_1.removeClass([].slice.call(node.getElementsByClassName('e-edit-delete')), 'e-hide'); } if (this.parent.isFrozenGrid()) { util_1.addStickyColumnPosition(this.parent, cell.column, node); } return node; }; CommandColumnRenderer.prototype.renderButton = function (node, buttonOption, index, uid) { var button = this.buttonElement.cloneNode(); ej2_base_1.attributes(button, { 'id': this.parent.element.id + (buttonOption.type || '') + '_' + index + '_' + uid, 'type': 'button', title: !ej2_base_1.isNullOrUndefined(buttonOption.title) ? buttonOption.title : buttonOption.buttonOption.content || this.localizer.getConstant(buttonOption.type) || buttonOption.type, 'data-uid': uid }); button.onclick = buttonOption.buttonOption.click; buttonOption.buttonOption.cssClass = this.parent.cssClass ? buttonOption.buttonOption.cssClass + ' ' + this.parent.cssClass : buttonOption.buttonOption.cssClass; var buttonObj = new ej2_buttons_1.Button(buttonOption.buttonOption, button); this.childRefs.push(buttonObj); buttonObj.commandType = buttonOption.type; node.firstElementChild.appendChild(buttonObj.element); switch (buttonOption.type) { case 'Edit': case 'Delete': ej2_base_1.addClass([button], ['e-edit-delete', 'e-' + buttonOption.type.toLowerCase() + 'button']); break; case 'Cancel': case 'Save': ej2_base_1.addClass([button], ['e-save-cancel', 'e-' + buttonOption.type.toLowerCase() + 'button']); break; } return node; }; return CommandColumnRenderer; }(cell_renderer_1.CellRenderer)); exports.CommandColumnRenderer = CommandColumnRenderer; }); |