UNPKG

4.67 kBJavaScriptView Raw
1/**
2 * ag-grid - Advanced Data Grid / Data Table supporting Javascript / React / AngularJS / Web Components
3 * @version v18.1.2
4 * @link http://www.ag-grid.com/
5 * @license MIT
6 */
7"use strict";
8var __extends = (this && this.__extends) || (function () {
9 var extendStatics = Object.setPrototypeOf ||
10 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
12 return function (d, b) {
13 extendStatics(d, b);
14 function __() { this.constructor = d; }
15 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
16 };
17})();
18var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21 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;
22 return c > 3 && r && Object.defineProperty(target, key, r), r;
23};
24var __metadata = (this && this.__metadata) || function (k, v) {
25 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
26};
27Object.defineProperty(exports, "__esModule", { value: true });
28var component_1 = require("../../widgets/component");
29var utils_1 = require("../../utils");
30var constants_1 = require("../../constants");
31var context_1 = require("../../context/context");
32var gridOptionsWrapper_1 = require("../../gridOptionsWrapper");
33var valueFormatterService_1 = require("../valueFormatterService");
34var SelectCellEditor = (function (_super) {
35 __extends(SelectCellEditor, _super);
36 function SelectCellEditor() {
37 var _this = _super.call(this, '<div class="ag-cell-edit-input"><select class="ag-cell-edit-input"/></div>') || this;
38 _this.eSelect = _this.getGui().querySelector('select');
39 return _this;
40 }
41 SelectCellEditor.prototype.init = function (params) {
42 var _this = this;
43 this.focusAfterAttached = params.cellStartedEdit;
44 if (utils_1.Utils.missing(params.values)) {
45 console.log('ag-Grid: no values found for select cellEditor');
46 return;
47 }
48 params.values.forEach(function (value) {
49 var option = document.createElement('option');
50 option.value = value;
51 var valueFormatted = _this.valueFormatterService.formatValue(params.column, null, null, value);
52 var valueFormattedExits = valueFormatted !== null && valueFormatted !== undefined;
53 option.text = valueFormattedExits ? valueFormatted : value;
54 if (params.value === value) {
55 option.selected = true;
56 }
57 _this.eSelect.appendChild(option);
58 });
59 // we don't want to add this if full row editing, otherwise selecting will stop the
60 // full row editing.
61 if (!this.gridOptionsWrapper.isFullRowEdit()) {
62 this.addDestroyableEventListener(this.eSelect, 'change', function () { return params.stopEditing(); });
63 }
64 this.addDestroyableEventListener(this.eSelect, 'keydown', function (event) {
65 var isNavigationKey = event.keyCode === constants_1.Constants.KEY_UP || event.keyCode === constants_1.Constants.KEY_DOWN;
66 if (isNavigationKey) {
67 event.stopPropagation();
68 }
69 });
70 this.addDestroyableEventListener(this.eSelect, 'mousedown', function (event) {
71 event.stopPropagation();
72 });
73 };
74 SelectCellEditor.prototype.afterGuiAttached = function () {
75 if (this.focusAfterAttached) {
76 this.eSelect.focus();
77 }
78 };
79 SelectCellEditor.prototype.focusIn = function () {
80 this.eSelect.focus();
81 };
82 SelectCellEditor.prototype.getValue = function () {
83 return this.eSelect.value;
84 };
85 __decorate([
86 context_1.Autowired('gridOptionsWrapper'),
87 __metadata("design:type", gridOptionsWrapper_1.GridOptionsWrapper)
88 ], SelectCellEditor.prototype, "gridOptionsWrapper", void 0);
89 __decorate([
90 context_1.Autowired('valueFormatterService'),
91 __metadata("design:type", valueFormatterService_1.ValueFormatterService)
92 ], SelectCellEditor.prototype, "valueFormatterService", void 0);
93 return SelectCellEditor;
94}(component_1.Component));
95exports.SelectCellEditor = SelectCellEditor;