all files / grid/actions/ context-menu.js

100% Statements 330/330
94.75% Branches 289/305
100% Functions 29/29
100% Lines 330/330
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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587                                                       18× 18× 18× 18× 18× 18× 18× 18×   19×   18× 18× 18×   35× 18×   17× 17× 17× 17×         19× 19× 19× 19× 19× 19× 19×                       19×         19× 19× 19× 221× 221× 212× 33×     179×         19× 11× 11× 11×   19×   30× 30× 30×   30×   20×   52× 52×                                                                     52× 52× 52×   23× 23× 23×   23×   223×   26× 26× 26× 26× 26×   32× 32×   31×                 26× 26× 26×   26× 16×       26× 26× 26× 286× 286× 286× 286× 276× 97×   276×   16× 14×     260×           258×   179×     10×               26×   26× 26× 26×   26× 26× 26× 26× 26×     32×   806× 806× 10×   796× 154×     642×   806×   808×     276× 276×     37×   37×   14×       14×   14×       14×         68× 12×   68×   20×   13×   20×   15×     15×               34×   12×   22×         34×     34×     24×   34×     34×     16×   34×   276×     36× 36×   35× 35× 35× 35× 35×   35× 35× 35× 17×   35×   20538×   223×   338×   223× 223×   14× 14×   16× 16×       12× 12×   12× 12×   12× 12×   12× 12×   14× 14×   11× 11×   11× 11×   11× 11×   11× 11×   12× 12×   12× 12×   12× 12×   12× 12×   12× 12×   11× 11×   223×       223×   498×         18×                                         18×   26× 26× 10× 10×     16× 16×     10× 10× 10×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-navigations", "../base/constant", "../actions/resize", "../actions/page", "../base/util", "../actions/group", "../actions/sort", "../actions/pdf-export", "../actions/excel-export", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, ej2_navigations_1, events, resize_1, page_1, util_1, group_1, sort_1, pdf_export_1, excel_export_1, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.menuClass = {
        header: '.' + literals.gridHeader,
        content: '.' + literals.gridContent,
        edit: '.e-inline-edit',
        batchEdit: '.e-editedbatchcell',
        editIcon: 'e-edit',
        pager: '.e-gridpager',
        delete: 'e-delete',
        save: 'e-save',
        cancel: 'e-cancel',
        copy: 'e-copy',
        pdf: 'e-pdfexport',
        group: 'e-icon-group',
        ungroup: 'e-icon-ungroup',
        csv: 'e-csvexport',
        excel: 'e-excelexport',
        fPage: 'e-icon-first',
        nPage: 'e-icon-next',
        lPage: 'e-icon-last',
        pPage: 'e-icon-prev',
        ascending: 'e-icon-ascending',
        descending: 'e-icon-descending',
        groupHeader: 'e-groupdroparea',
        touchPop: 'e-gridpopup',
        autofit: 'e-icon-autofit',
        autofitall: 'e-icon-autofitall'
    };
    var ContextMenu = (function () {
        function ContextMenu(parent, serviceLocator) {
            this.defaultItems = {};
            this.disableItems = [];
            this.hiddenItems = [];
            this.localeText = this.setLocaleKey();
            this.parent = parent;
            this.gridID = parent.element.id;
            this.serviceLocator = serviceLocator;
            this.addEventListener();
        }
        ContextMenu.prototype.addEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.uiUpdate, this.enableAfterRenderMenu, this);
            this.parent.on(events.initialLoad, this.render, this);
            this.parent.on(events.destroy, this.destroy, this);
        };
        ContextMenu.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.initialLoad, this.render);
            this.parent.off(events.uiUpdate, this.enableAfterRenderMenu);
            this.parent.off(events.destroy, this.destroy);
            ej2_base_1.EventHandler.remove(this.element, 'keydown', this.keyDownHandler.bind(this));
        };
        ContextMenu.prototype.keyDownHandler = function (e) {
            if (e.code === 'Tab' || e.which === 9) {
                this.contextMenu.close();
            }
            if (e.code === 'Escape') {
                this.contextMenu.close();
                this.parent.notify(events.restoreFocus, {});
            }
        };
        ContextMenu.prototype.render = function () {
            this.parent.element.classList.add('e-noselect');
            this.l10n = this.serviceLocator.getService('localization');
            this.element = this.parent.createElement('ul', { id: this.gridID + '_cmenu' });
            ej2_base_1.EventHandler.add(this.element, 'keydown', this.keyDownHandler.bind(this));
            this.parent.element.appendChild(this.element);
            var target = '#' + this.gridID;
            this.contextMenu = new ej2_navigations_1.ContextMenu({
                items: this.getMenuItems(),
                enableRtl: this.parent.enableRtl,
                enablePersistence: this.parent.enablePersistence,
                locale: this.parent.locale,
                target: target,
                select: this.contextMenuItemClick.bind(this),
                beforeOpen: this.contextMenuBeforeOpen.bind(this),
                onOpen: this.contextMenuOpen.bind(this),
                onClose: this.contextMenuOnClose.bind(this),
                cssClass: this.parent.cssClass ? 'e-grid-menu' + ' ' + this.parent.cssClass : 'e-grid-menu'
            });
            this.contextMenu.appendTo(this.element);
        };
        ContextMenu.prototype.enableAfterRenderMenu = function (e) {
            Eif (e.module === this.getModuleName() && e.enable) {
                if (this.contextMenu) {
                    this.contextMenu.destroy();
                    ej2_base_2.remove(this.element);
                    this.parent.element.classList.remove('e-noselect');
                }
                this.render();
            }
        };
        ContextMenu.prototype.getMenuItems = function () {
            var menuItems = [];
            var exportItems = [];
            for (var _i = 0, _a = this.parent.contextMenuItems; _i < _a.length; _i++) {
                var item = _a[_i];
                if (typeof item === 'string' && this.getDefaultItems().indexOf(item) !== -1) {
                    if (item.toLocaleLowerCase().indexOf('export') !== -1) {
                        exportItems.push(this.buildDefaultItems(item));
                    }
                    else {
                        menuItems.push(this.buildDefaultItems(item));
                    }
                }
                else Eif (typeof item !== 'string') {
                    menuItems.push(item);
                }
            }
            if (exportItems.length > 0) {
                var exportGroup = this.buildDefaultItems('export');
                exportGroup.items = exportItems;
                menuItems.push(exportGroup);
            }
            return menuItems;
        };
        ContextMenu.prototype.getLastPage = function () {
            var totalpage = Math.floor(this.parent.pageSettings.totalRecordsCount / this.parent.pageSettings.pageSize);
            Eif (this.parent.pageSettings.totalRecordsCount % this.parent.pageSettings.pageSize) {
                totalpage += 1;
            }
            return totalpage;
        };
        ContextMenu.prototype.contextMenuOpen = function () {
            this.isOpen = true;
        };
        ContextMenu.prototype.contextMenuItemClick = function (args) {
            var item = this.getKeyFromId(args.item.id);
            switch (item) {
                case 'AutoFitAll':
                    this.parent.autoFitColumns([]);
                    break;
                case 'AutoFit':
                    this.parent.autoFitColumns(this.targetColumn.field);
                    break;
                case 'Group':
                    this.parent.groupColumn(this.targetColumn.field);
                    break;
                case 'Ungroup':
                    this.parent.ungroupColumn(this.targetColumn.field);
                    break;
                case 'Edit':
                    Eif (this.parent.editModule) {
                        if (this.parent.editSettings.mode === 'Batch') {
                            Eif (this.row && this.cell && !isNaN(parseInt(this.cell.getAttribute(literals.dataColIndex), 10))) {
                                this.parent.editModule.editCell(parseInt(this.row.getAttribute(literals.dataRowIndex), 10), this.parent.getColumns()[parseInt(this.cell.getAttribute(literals.dataColIndex), 10)].field);
                            }
                        }
                        else {
                            this.parent.editModule.endEdit();
                            this.parent.editModule.startEdit(this.row);
                        }
                    }
                    break;
                case 'Delete':
                    Eif (this.parent.editModule) {
                        if (this.parent.editSettings.mode !== 'Batch') {
                            this.parent.editModule.endEdit();
                        }
                        if (this.parent.getSelectedRecords().length === 1) {
                            Eif (!this.parent.isCheckBoxSelection) {
                                this.parent.isFocusFirstCell = true;
                            }
                            this.parent.editModule.deleteRow(this.row);
                        }
                        else {
                            this.parent.deleteRecord();
                        }
                    }
                    break;
                case 'Save':
                    Eif (this.parent.editModule) {
                        if (this.parent.isEdit && this.parent.editSettings.mode !== 'Batch') {
                            this.parent.isFocusFirstCell = true;
                        }
                        this.parent.editModule.endEdit();
                    }
                    break;
                case 'Cancel':
                    Eif (this.parent.editModule) {
                        if (this.parent.isEdit) {
                            this.parent.isFocusFirstCell = true;
                        }
                        this.parent.editModule.closeEdit();
                    }
                    break;
                case 'Copy':
                    this.parent.copy();
                    break;
                case 'PdfExport':
                    this.parent.pdfExport();
                    break;
                case 'ExcelExport':
                    this.parent.excelExport();
                    break;
                case 'CsvExport':
                    this.parent.csvExport();
                    break;
                case 'SortAscending':
                    this.isOpen = false;
                    this.parent.sortColumn(this.targetColumn.field, 'Ascending');
                    break;
                case 'SortDescending':
                    this.isOpen = false;
                    this.parent.sortColumn(this.targetColumn.field, 'Descending');
                    break;
                case 'FirstPage':
                    this.parent.goToPage(1);
                    break;
                case 'PrevPage':
                    this.parent.goToPage(this.parent.pageSettings.currentPage - 1);
                    break;
                case 'LastPage':
                    this.parent.goToPage(this.getLastPage());
                    break;
                case 'NextPage':
                    this.parent.goToPage(this.parent.pageSettings.currentPage + 1);
                    break;
            }
            args.column = this.targetColumn;
            args.rowInfo = this.targetRowdata;
            this.parent.trigger(events.contextMenuClick, args);
        };
        ContextMenu.prototype.contextMenuOnClose = function (args) {
            var parent = 'parentObj';
            Eif (args.items.length > 0 && args.items[0]["" + parent] instanceof ej2_navigations_1.ContextMenu) {
                this.updateItemStatus();
            }
            this.parent.notify(events.selectRowOnContextOpen, { isOpen: false });
        };
        ContextMenu.prototype.getLocaleText = function (item) {
            return this.l10n.getConstant(this.localeText["" + item]);
        };
        ContextMenu.prototype.updateItemStatus = function () {
            this.contextMenu.showItems(this.hiddenItems);
            this.contextMenu.enableItems(this.disableItems);
            this.hiddenItems = [];
            this.disableItems = [];
            this.isOpen = false;
        };
        ContextMenu.prototype.contextMenuBeforeOpen = function (args) {
            var closestGrid = ej2_base_1.closest(args.event.target, '.e-grid');
            if (args.event && closestGrid && closestGrid !== this.parent.element) {
                args.cancel = true;
            }
            else if (args.event && (ej2_base_1.closest(args.event.target, '.' + exports.menuClass.groupHeader)
                || ej2_base_1.closest(args.event.target, '.' + exports.menuClass.touchPop) ||
                ej2_base_1.closest(args.event.target, '.e-summarycell') ||
                ej2_base_1.closest(args.event.target, '.e-groupcaption') ||
                ej2_base_1.closest(args.event.target, '.e-filterbarcell')) ||
                (this.parent.editSettings.showAddNewRow && ej2_base_1.closest(args.event.target, '.e-addedrow')
                    && this.parent.element.querySelector('.e-editedrow'))) {
                args.cancel = true;
            }
            else {
                this.targetColumn = this.getColumn(args.event);
                Eif (util_1.parentsUntil(args.event.target, 'e-grid')) {
                    this.targetRowdata = this.parent.getRowInfo(args.event.target);
                }
                if ((ej2_base_1.isNullOrUndefined(args.parentItem)) && this.targetColumn) {
                    if (this.targetRowdata.cell) {
                        this.parent.notify(events.selectRowOnContextOpen, { isOpen: true });
                        this.selectRow(args.event, (this.targetRowdata.cell.classList.contains('e-selectionbackground')
                            && this.parent.selectionSettings.type === 'Multiple') ? false : true);
                    }
                }
                var hideSepItems = [];
                var showSepItems = [];
                for (var _i = 0, _a = args.items; _i < _a.length; _i++) {
                    var item = _a[_i];
                    var key = this.getKeyFromId(item.id);
                    var dItem = this.defaultItems["" + key];
                    if (this.getDefaultItems().indexOf(key) !== -1) {
                        if (this.ensureDisabledStatus(key)) {
                            this.disableItems.push(item.text);
                        }
                        if (args.event && (this.ensureTarget(args.event.target, exports.menuClass.edit) ||
                            this.ensureTarget(args.event.target, exports.menuClass.batchEdit))) {
                            if (key !== 'Save' && key !== 'Cancel') {
                                this.hiddenItems.push(item.text);
                            }
                        }
                        else if (this.parent.editModule && this.parent.editSettings.mode === 'Batch' &&
                            ((ej2_base_1.closest(args.event.target, '.e-gridform')) ||
                                this.parent.editModule.getBatchChanges()[literals.changedRecords].length ||
                                this.parent.editModule.getBatchChanges()[literals.addedRecords].length ||
                                this.parent.editModule.getBatchChanges()[literals.deletedRecords].length) && (key === 'Save' || key === 'Cancel')) {
                            continue;
                        }
                        else if (ej2_base_1.isNullOrUndefined(args.parentItem) && args.event
                            && !this.ensureTarget(args.event.target, dItem.target)) {
                            this.hiddenItems.push(item.text);
                        }
                    }
                    else if (item.target && args.event &&
                        !this.ensureTarget(args.event.target, item.target)) {
                        if (item.separator) {
                            hideSepItems.push(item.id);
                        }
                        else {
                            this.hiddenItems.push(item.text);
                        }
                    }
                    else if (this.ensureTarget(args.event.target, item.target) && item.separator) {
                        showSepItems.push(item.id);
                    }
                }
                if (showSepItems.length > 0) {
                    this.contextMenu.showItems(showSepItems, true);
                }
                this.contextMenu.enableItems(this.disableItems, false);
                this.contextMenu.hideItems(this.hiddenItems);
                if (hideSepItems.length > 0) {
                    this.contextMenu.hideItems(hideSepItems, true);
                }
                this.eventArgs = args.event;
                args.column = this.targetColumn;
                args.rowInfo = this.targetRowdata;
                this.parent.trigger(events.contextMenuOpen, args);
                if (args.cancel || (this.hiddenItems.length === args.items.length && !args.parentItem)) {
                    this.updateItemStatus();
                    args.cancel = true;
                }
            }
            util_1.applyBiggerTheme(this.parent.element, this.contextMenu.element.parentElement);
        };
        ContextMenu.prototype.ensureTarget = function (targetElement, selector) {
            var target = targetElement;
            if (this.ensureFrozenHeader(targetElement) && (selector === exports.menuClass.header || selector === exports.menuClass.content)) {
                target = ej2_base_1.closest(targetElement, selector === exports.menuClass.header ? 'thead' : literals.tbody);
            }
            else if (selector === exports.menuClass.content || selector === exports.menuClass.header) {
                target = util_1.parentsUntil(ej2_base_1.closest(targetElement, '.' + literals.table), selector.substr(1, selector.length));
            }
            else {
                target = ej2_base_1.closest(targetElement, selector);
            }
            return target && util_1.parentsUntil(target, 'e-grid') === this.parent.element;
        };
        ContextMenu.prototype.ensureFrozenHeader = function (targetElement) {
            return (this.parent.frozenRows)
                && ej2_base_1.closest(targetElement, exports.menuClass.header) ? true : false;
        };
        ContextMenu.prototype.ensureDisabledStatus = function (item) {
            var status = false;
            switch (item) {
                case 'AutoFitAll':
                case 'AutoFit':
                    status = !(this.parent.ensureModuleInjected(resize_1.Resize) && !this.parent.isEdit)
                        || (this.targetColumn && !this.targetColumn.field && item === 'AutoFit');
                    break;
                case 'Group':
                    if (!this.parent.allowGrouping || (this.parent.ensureModuleInjected(group_1.Group) && this.targetColumn
                        && this.parent.groupSettings.columns.indexOf(this.targetColumn.field) >= 0) ||
                        (this.targetColumn && !this.targetColumn.field)) {
                        status = true;
                    }
                    break;
                case 'Ungroup':
                    if (!this.parent.allowGrouping || !this.parent.ensureModuleInjected(group_1.Group)
                        || (this.parent.ensureModuleInjected(group_1.Group) && this.targetColumn
                            && this.parent.groupSettings.columns.indexOf(this.targetColumn.field) < 0)) {
                        status = true;
                    }
                    break;
                case 'Edit':
                case 'Delete':
                case 'Save':
                case 'Cancel':
                    if (!this.parent.editModule || (this.parent.getDataRows().length === 0)) {
                        status = true;
                    }
                    break;
                case 'Copy':
                    if ((this.parent.getSelectedRowIndexes().length === 0 && this.parent.getSelectedRowCellIndexes().length === 0) ||
                        this.parent.getCurrentViewRecords().length === 0) {
                        status = true;
                    }
                    break;
                case 'export':
                    if ((!this.parent.allowExcelExport || !this.parent.excelExport) ||
                        !this.parent.ensureModuleInjected(pdf_export_1.PdfExport) && !this.parent.ensureModuleInjected(excel_export_1.ExcelExport)) {
                        status = true;
                    }
                    break;
                case 'PdfExport':
                    if (!(this.parent.allowPdfExport) || !this.parent.ensureModuleInjected(pdf_export_1.PdfExport)) {
                        status = true;
                    }
                    break;
                case 'ExcelExport':
                case 'CsvExport':
                    if (!(this.parent.allowExcelExport) || !this.parent.ensureModuleInjected(excel_export_1.ExcelExport)) {
                        status = true;
                    }
                    break;
                case 'SortAscending':
                case 'SortDescending':
                    if ((!this.parent.allowSorting) || !this.parent.ensureModuleInjected(sort_1.Sort) ||
                        (this.targetColumn && !this.targetColumn.field)) {
                        status = true;
                    }
                    else if (this.parent.ensureModuleInjected(sort_1.Sort) && this.parent.sortSettings.columns.length > 0 && this.targetColumn) {
                        var sortColumns = this.parent.sortSettings.columns;
                        for (var i = 0; i < sortColumns.length; i++) {
                            if (sortColumns[parseInt(i.toString(), 10)].field === this.targetColumn.field
                                && sortColumns[parseInt(i.toString(), 10)].direction.toLowerCase() === item.toLowerCase().replace('sort', '').toLocaleLowerCase()) {
                                status = true;
                            }
                        }
                    }
                    break;
                case 'FirstPage':
                case 'PrevPage':
                    if (!this.parent.allowPaging || !this.parent.ensureModuleInjected(page_1.Page) ||
                        this.parent.getCurrentViewRecords().length === 0 ||
                        (this.parent.ensureModuleInjected(page_1.Page) && this.parent.pageSettings.currentPage === 1)) {
                        status = true;
                    }
                    break;
                case 'LastPage':
                case 'NextPage':
                    if (!this.parent.allowPaging || !this.parent.ensureModuleInjected(page_1.Page) ||
                        this.parent.getCurrentViewRecords().length === 0 ||
                        (this.parent.ensureModuleInjected(page_1.Page) && this.parent.pageSettings.currentPage === this.getLastPage())) {
                        status = true;
                    }
                    break;
            }
            return status;
        };
        ContextMenu.prototype.getContextMenu = function () {
            return this.element;
        };
        ContextMenu.prototype.destroy = function () {
            var gridElement = this.parent.element;
            if (!gridElement || (!gridElement.querySelector('.' + literals.gridHeader) && !gridElement.querySelector('.' + literals.gridContent))) {
                return;
            }
            Eif (this.contextMenu) {
                this.contextMenu.select = null;
                this.contextMenu.beforeOpen = null;
                this.contextMenu.onOpen = null;
                this.contextMenu.onClose = null;
            }
            this.removeEventListener();
            this.contextMenu.destroy();
            if (this.element.parentNode) {
                ej2_base_2.remove(this.element);
            }
            this.parent.element.classList.remove('e-noselect');
        };
        ContextMenu.prototype.getModuleName = function () {
            return 'contextMenu';
        };
        ContextMenu.prototype.generateID = function (item) {
            return this.gridID + '_cmenu_' + item;
        };
        ContextMenu.prototype.getKeyFromId = function (id) {
            return id.replace(this.gridID + '_cmenu_', '');
        };
        ContextMenu.prototype.buildDefaultItems = function (item) {
            var menuItem;
            switch (item) {
                case 'AutoFitAll':
                    menuItem = { target: exports.menuClass.header, iconCss: exports.menuClass.autofitall };
                    break;
                case 'AutoFit':
                    menuItem = { target: exports.menuClass.header, iconCss: exports.menuClass.autofit };
                    break;
                case 'Group':
                    menuItem = { target: exports.menuClass.header, iconCss: exports.menuClass.group };
                    break;
                case 'Ungroup':
                    menuItem = { target: exports.menuClass.header, iconCss: exports.menuClass.ungroup };
                    break;
                case 'Edit':
                    menuItem = { target: exports.menuClass.content, iconCss: exports.menuClass.editIcon };
                    break;
                case 'Delete':
                    menuItem = { target: exports.menuClass.content, iconCss: exports.menuClass.delete };
                    break;
                case 'Save':
                    menuItem = { target: exports.menuClass.edit, iconCss: exports.menuClass.save };
                    break;
                case 'Cancel':
                    menuItem = { target: exports.menuClass.edit, iconCss: exports.menuClass.cancel };
                    break;
                case 'Copy':
                    menuItem = { target: exports.menuClass.content, iconCss: exports.menuClass.copy };
                    break;
                case 'export':
                    menuItem = { target: exports.menuClass.content };
                    break;
                case 'PdfExport':
                    menuItem = { target: exports.menuClass.content, iconCss: exports.menuClass.pdf };
                    break;
                case 'ExcelExport':
                    menuItem = { target: exports.menuClass.content, iconCss: exports.menuClass.excel };
                    break;
                case 'CsvExport':
                    menuItem = { target: exports.menuClass.content, iconCss: exports.menuClass.csv };
                    break;
                case 'SortAscending':
                    menuItem = { target: exports.menuClass.header, iconCss: exports.menuClass.ascending };
                    break;
                case 'SortDescending':
                    menuItem = { target: exports.menuClass.header, iconCss: exports.menuClass.descending };
                    break;
                case 'FirstPage':
                    menuItem = { target: exports.menuClass.pager, iconCss: exports.menuClass.fPage };
                    break;
                case 'PrevPage':
                    menuItem = { target: exports.menuClass.pager, iconCss: exports.menuClass.pPage };
                    break;
                case 'LastPage':
                    menuItem = { target: exports.menuClass.pager, iconCss: exports.menuClass.lPage };
                    break;
                case 'NextPage':
                    menuItem = { target: exports.menuClass.pager, iconCss: exports.menuClass.nPage };
                    break;
            }
            this.defaultItems["" + item] = {
                text: this.getLocaleText(item), id: this.generateID(item),
                target: menuItem.target, iconCss: menuItem.iconCss ? 'e-icons ' + menuItem.iconCss : ''
            };
            return this.defaultItems["" + item];
        };
        ContextMenu.prototype.getDefaultItems = function () {
            return ['AutoFitAll', 'AutoFit',
                'Group', 'Ungroup', 'Edit', 'Delete', 'Save', 'Cancel', 'Copy', 'export',
                'PdfExport', 'ExcelExport', 'CsvExport', 'SortAscending', 'SortDescending',
                'FirstPage', 'PrevPage', 'LastPage', 'NextPage'];
        };
        ContextMenu.prototype.setLocaleKey = function () {
            var localeKeys = {
                'AutoFitAll': 'autoFitAll',
                'AutoFit': 'autoFit',
                'Copy': 'Copy',
                'Group': 'Group',
                'Ungroup': 'Ungroup',
                'Edit': 'EditRecord',
                'Delete': 'DeleteRecord',
                'Save': 'Save',
                'Cancel': 'CancelButton',
                'PdfExport': 'Pdfexport',
                'ExcelExport': 'Excelexport',
                'CsvExport': 'Csvexport',
                'export': 'Export',
                'SortAscending': 'SortAscending',
                'SortDescending': 'SortDescending',
                'FirstPage': 'FirstPage',
                'LastPage': 'LastPage',
                'PrevPage': 'PreviousPage',
                'NextPage': 'NextPage'
            };
            return localeKeys;
        };
        ContextMenu.prototype.getColumn = function (e) {
            var cell = ej2_base_1.closest(e.target, 'th.e-headercell');
            if (cell) {
                var uid = cell.querySelector('.e-headercelldiv, .e-stackedheadercelldiv').getAttribute('e-mappinguid');
                return this.parent.getColumnByUid(uid);
            }
            else {
                var ele = (this.parent.getRowInfo(e.target).column);
                return ele || null;
            }
        };
        ContextMenu.prototype.selectRow = function (e, isSelectable) {
            this.cell = e.target;
            this.row = ej2_base_1.closest(e.target, 'tr.e-row') || this.row;
            if (this.row && isSelectable && !util_1.parentsUntil(e.target, 'e-gridpager')) {
                this.parent.selectRow(parseInt(this.row.getAttribute(literals.dataRowIndex), 10));
            }
        };
        return ContextMenu;
    }());
    exports.ContextMenu = ContextMenu;
});