all files / pivotview/renderer/ render.js

93.18% Statements 656/704
84.75% Branches 550/649
94.55% Functions 52/55
93.18% Lines 656/704
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 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218   679× 679× 679× 679×   679× 679× 679× 679×   447× 447× 447× 447× 447× 447× 447× 446× 22× 22×     424× 85×   424×   446×       446× 446× 27×   446× 446×   232×   446× 446×   446× 446× 419×         447×   917× 196× 196× 196× 196× 196× 196×         196× 196× 196×   196×     196×     95× 95×                                                                                                 95×   1317×         13× 13×   10× 10×   12×     11× 11×         10× 10×   106075×   12078×   92×   392×   574×   52×   666× 18× 142× 142× 142×     18×   666× 548× 12×     536×     666× 666× 660×   666× 663×   666× 666×   46× 338× 338× 338× 338× 338×       338×   330×     338× 40×   338× 338× 338× 338× 338×   31×           27×     22×     31×   31×               30×     25×     31×   31× 12× 12×     19×             13×       31×   31× 11× 11×     20×             19×   31×   31× 11× 11×     20×               19×     31×   31× 10×   31×               31×   31×   31×       29×     31×     46×   17× 17× 17×         17× 17×       17× 17×         17× 17× 17× 17×       17×                                                                     17×   14×       570× 570× 35×   570× 35×   570× 570× 29×     28× 28× 28× 28× 28× 28× 28× 28× 28× 28× 28× 28× 28× 19× 19×     19×     19×   28×   19× 19× 161× 161× 161× 161× 107×       19×   28× 103× 103×     10493× 1848× 1848×         1848× 1848× 74× 74×   74×                   74×         10493×                                                       78× 78×   48× 48× 48× 1211× 1211× 1211× 1211× 1211× 1209× 1096×               113× 36×                 77×                   48×   106075× 106075× 106013× 106013× 106013× 106013× 9254× 9254× 9254× 9254× 12796× 3542×       12796×   9254× 9254× 9254× 2886×       9254× 9254×   9232× 9232×   9254× 9254× 710× 384× 384×     326×     9254× 9254× 5328×               9254×       9254× 9254× 1140×   37×                             96759× 96759× 96759× 96759× 96759× 65585×   96724× 418×   96724×             105978× 152× 152× 152× 152× 152×           105978× 105978×   106040× 106040×   12078× 10493× 10493× 10493× 10493× 10493× 10493×   312×   10181× 304× 304× 304× 22×     10493× 10493× 10493× 10493×       4409×   4409×   10493× 1480× 1480×   1480× 135×     1345×     10493× 10493× 39× 17× 17×     22× 22× 22×       10493× 861× 861× 30× 30×   861×             861× 861×       861×   861×   10493× 10493× 190× 190× 190× 190× 190×           10493× 10493× 10493× 22814× 6295×     10493× 10493×     12078×                   447× 447× 447× 1507× 446× 446×     447×   148× 148× 126× 125× 125× 125× 125× 125× 1183× 1183× 1183× 1183× 11577× 11530×     1183×               22×   148×   254×       254×   1179×     1179× 1179× 1179× 1179×   15×     15× 15× 15× 15×   462× 462×   462× 462× 272×   190× 13×           462×   1095× 1095× 1095× 572×   1095× 1089× 1086× 1086×   1086× 1086× 1086× 1086× 1086× 1086× 1086× 1086× 1086× 1086× 1086×   508×     578×                       1095×   447× 447× 429× 429× 429× 429× 429× 1034× 1034× 1034× 1034× 1034× 960× 6596× 6596× 6596×         6596× 4032×                       2564× 2564× 2564× 2564× 2564× 4939× 2375×     2375×     2564×                 2564×   4939× 4939×   2564×   6596× 6596×   6596× 6596× 6596× 6596×     1034×   429×                     18×   447× 446× 446×   447× 447×   16551× 16551×   250× 250× 250× 250× 250×   689× 689× 1306× 1306× 629× 629× 742× 742× 311× 311×     431×     629×     677×     689×   92× 92×   52× 52×   574× 49× 49× 49× 49× 49×     525× 525×   574× 574×   392× 392× 35× 35× 35× 35×   392×   144× 144× 136× 136×       144×   144×   966×   966×   116471× 805×     115666×     116471× 805×     115666×          
define(["require", "exports", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "@syncfusion/ej2-grids", "@syncfusion/ej2-base", "../../common/base/css-constant", "../../common/base/constant", "../../common/popups/aggregate-menu"], function (require, exports, ej2_grids_1, ej2_grids_2, ej2_grids_3, ej2_base_1, cls, events, aggregate_menu_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Render = (function () {
        function Render(parent) {
            this.colPos = 0;
            this.lastSpan = 0;
            this.parent = parent;
            this.resColWidth = (this.parent.showGroupingBar && this.parent.groupingBarModule) ? (this.parent.isAdaptive ? 180 : 250) :
                (this.parent.isAdaptive ? 140 : 200);
            this.engine = parent.engineModule;
            this.gridSettings = parent.gridSettings;
            this.formatList = this.getFormatList();
            this.aggMenu = new aggregate_menu_1.AggregateMenu(this.parent);
        }
        Render.prototype.render = function () {
            var parent = this.parent;
            var engine = this.parent.engineModule;
            this.parent.gridHeaderCellInfo = [];
            this.parent.gridCellCollection = {};
            this.injectGridModules(parent);
            this.rowStartPos = this.getRowStartPos();
            if (this.parent.grid && this.parent.grid.element && this.parent.element.querySelector('.e-grid')) {
                if (!engine.isEngineUpdated) {
                    engine.headerContent = this.frameDataSource('header');
                    engine.valueContent = this.frameDataSource('value');
                }
                else {
                    if (this.parent.enableValueSorting) {
                        engine.valueContent = this.frameDataSource('value');
                    }
                    engine.isEngineUpdated = false;
                }
                this.parent.grid.setProperties({
                    columns: this.frameStackedHeaders(), dataSource: parent.dataSourceSettings.values.length > 0 && !this.engine.isEmptyData ? engine.valueContent :
                        this.frameDataSource('value')
                }, true);
                this.parent.grid.notify('datasource-modified', {});
                if (this.parent.isScrolling) {
                    this.parent.resizeInfo = {};
                }
                this.parent.grid.refreshColumns();
                if (this.parent.showGroupingBar && this.parent.groupingBarModule &&
                    this.parent.element.querySelector('.' + cls.GROUPING_BAR_CLASS)) {
                    this.parent.groupingBarModule.setGridRowWidth();
                }
                var e = this.parent.element.querySelector('.e-movablecontent');
                e.querySelector('colGroup').innerHTML =
                    this.parent.grid.getHeaderContent().querySelector('.e-movableheader').querySelector('colgroup').innerHTML;
                this.parent.grid.width = this.calculateGridWidth();
                if (!this.parent.isScrolling) {
                    this.calculateGridHeight(true);
                }
            }
            else {
                this.parent.element.innerHTML = '';
                this.bindGrid(this.parent, (this.engine.isEmptyData ? true : false));
                this.parent.element.appendChild(ej2_base_1.createElement('div', { id: this.parent.element.id + '_grid' }));
                this.parent.grid.isStringTemplate = true;
                this.parent.grid.appendTo('#' + this.parent.element.id + '_grid');
            }
            this.parent.grid.on(ej2_grids_1.headerRefreshed, this.refreshHeader, this);
        };
        Render.prototype.refreshHeader = function () {
            if (this.parent.enableVirtualization) {
                var mHdr = this.parent.element.querySelector('.' + cls.MOVABLEHEADER_DIV);
                var mCont = this.parent.element.querySelector('.' + cls.MOVABLECONTENT_DIV);
                var vtr = mCont.querySelector('.' + cls.VIRTUALTRACK_DIV);
                this.parent.virtualHeaderDiv = mHdr.querySelector('.' + cls.VIRTUALTRACK_DIV);
                Eif (mHdr.querySelector('.' + cls.VIRTUALTRACK_DIV)) {
                    ej2_base_1.remove(mHdr.querySelector('.' + cls.VIRTUALTRACK_DIV));
                }
                else {
                    this.parent.virtualHeaderDiv = ej2_base_1.createElement('div', { className: cls.VIRTUALTRACK_DIV });
                }
                mHdr.appendChild(this.parent.virtualHeaderDiv);
                Eif (vtr) {
                    ej2_base_1.setStyleAttribute(this.parent.virtualHeaderDiv, { height: 0, width: vtr.style.width });
                }
                ej2_base_1.setStyleAttribute(mHdr.querySelector('.e-table'), {
                    transform: (mCont.querySelector('.e-table').style.transform).split(',')[0] + ',' + 0 + 'px)'
                });
                mHdr.scrollLeft = mCont.scrollLeft;
            }
        };
        Render.prototype.bindGrid = function (parent, isEmpty) {
            this.injectGridModules(parent);
            this.parent.grid = new ej2_grids_2.Grid({
                frozenColumns: 1,
                frozenRows: 0,
                dataSource: isEmpty ? this.frameEmptyData() : this.frameDataSource('value'),
                columns: isEmpty ? this.frameEmptyColumns() : this.frameStackedHeaders(),
                height: isEmpty ? 'auto' : this.calculateGridHeight(),
                width: isEmpty ? this.parent.width : this.calculateGridWidth(),
                locale: parent.locale,
                enableRtl: parent.enableRtl,
                allowExcelExport: parent.allowExcelExport,
                allowPdfExport: parent.allowPdfExport,
                allowResizing: this.gridSettings.allowResizing,
                allowTextWrap: this.gridSettings.allowTextWrap,
                allowReordering: this.gridSettings.allowReordering,
                allowSelection: this.gridSettings.allowSelection,
                contextMenuItems: this.gridSettings.contextMenuItems,
                selectedRowIndex: this.gridSettings.selectedRowIndex,
                selectionSettings: this.gridSettings.selectionSettings,
                textWrapSettings: this.gridSettings.textWrapSettings,
                printMode: this.gridSettings.printMode,
                rowHeight: this.gridSettings.rowHeight,
                gridLines: this.gridSettings.gridLines,
                contextMenuClick: this.contextMenuClick.bind(this),
                contextMenuOpen: this.contextMenuOpen.bind(this),
                beforeCopy: this.gridSettings.beforeCopy ? this.gridSettings.beforeCopy.bind(this.parent) : undefined,
                beforePrint: this.gridSettings.beforePrint ? this.gridSettings.beforePrint.bind(this.parent) : undefined,
                printComplete: this.gridSettings.printComplete ? this.gridSettings.printComplete.bind(this.parent) : undefined,
                rowSelecting: this.gridSettings.rowSelecting ? this.gridSettings.rowSelecting.bind(this.parent) : undefined,
                rowSelected: this.rowSelected.bind(this),
                rowDeselecting: this.gridSettings.rowDeselecting ? this.gridSettings.rowDeselecting.bind(this.parent) : undefined,
                rowDeselected: this.rowDeselected.bind(this),
                cellSelecting: this.gridSettings.cellSelecting ? this.gridSettings.cellSelecting.bind(this.parent) : undefined,
                cellSelected: this.cellSelected.bind(this),
                cellDeselecting: this.gridSettings.cellDeselecting ? this.gridSettings.cellDeselecting.bind(this.parent) : undefined,
                cellDeselected: this.cellDeselected.bind(this),
                resizeStart: this.gridSettings.resizeStart ? this.gridSettings.resizeStart.bind(this.parent) : undefined,
                columnDragStart: this.gridSettings.columnDragStart ? this.gridSettings.columnDragStart.bind(this) : undefined,
                columnDrag: this.gridSettings.columnDrag ? this.gridSettings.columnDrag.bind(this) : undefined,
                columnDrop: this.gridSettings.columnDrop ? this.gridSettings.columnDrop.bind(this) : undefined,
                resizing: this.setGroupWidth.bind(this),
                resizeStop: this.onResizeStop.bind(this),
                queryCellInfo: this.queryCellInfo.bind(this),
                dataBound: this.dataBound.bind(this),
                headerCellInfo: this.headerCellInfo.bind(this),
                excelHeaderQueryCellInfo: this.excelHeaderQueryCellInfo.bind(this),
                pdfHeaderQueryCellInfo: this.pdfHeaderQueryCellInfo.bind(this),
                excelQueryCellInfo: this.excelQueryCellInfo.bind(this),
                pdfQueryCellInfo: this.pdfQueryCellInfo.bind(this)
            });
            this.parent.grid.on('header-refreshed', this.headerRefreshed.bind(this));
        };
        Render.prototype.headerRefreshed = function (args) {
            if (this.parent.lastGridSettings && Object.keys(this.parent.lastGridSettings).indexOf('allowResizing') > -1) {
                this.parent.lastGridSettings = undefined;
                Eif (this.parent.showGroupingBar && this.parent.groupingBarModule &&
                    this.parent.element.querySelector('.' + cls.GROUPING_BAR_CLASS)) {
                    this.parent.groupingBarModule.setGridRowWidth();
                }
            }
        };
        Render.prototype.rowSelected = function (args) {
            this.parent.renderModule.selected();
            this.parent.trigger(events.rowSelected, args);
        };
        Render.prototype.rowDeselected = function (args) {
            this.parent.renderModule.selected();
            this.parent.trigger(events.rowDeselected, args);
        };
        Render.prototype.cellSelected = function (args) {
            if (this.parent.rowRangeSelection.enable) {
                this.parent.grid.selectionModule.selectRowsByRange(this.parent.rowRangeSelection.startIndex, this.parent.rowRangeSelection.endIndex);
                this.parent.rowRangeSelection.enable = false;
            }
            else {
                this.parent.renderModule.selected();
                this.parent.trigger(events.selected, args);
            }
        };
        Render.prototype.cellSelecting = function (args) {
            this.parent.trigger(events.cellSelecting, args);
        };
        Render.prototype.cellDeselected = function (args) {
            this.parent.renderModule.selected();
            this.parent.trigger(events.cellDeselected, args);
        };
        Render.prototype.queryCellInfo = function (args) {
            this.parent.renderModule.rowCellBoundEvent(args);
        };
        Render.prototype.headerCellInfo = function (args) {
            this.parent.renderModule.columnCellBoundEvent(args);
        };
        Render.prototype.excelHeaderQueryCellInfo = function (args) {
            this.parent.renderModule.excelColumnEvent(args);
        };
        Render.prototype.pdfQueryCellInfo = function (args) {
            this.parent.renderModule.pdfRowEvent(args);
        };
        Render.prototype.excelQueryCellInfo = function (args) {
            this.parent.renderModule.excelRowEvent(args);
        };
        Render.prototype.pdfHeaderQueryCellInfo = function (args) {
            this.parent.renderModule.pdfColumnEvent(args);
        };
        Render.prototype.dataBound = function (args) {
            if (this.parent.cellTemplate && !(window && window.Blazor)) {
                for (var _i = 0, _a = this.parent.gridHeaderCellInfo; _i < _a.length; _i++) {
                    var cell = _a[_i];
                    Eif (this.parent.cellTemplate) {
                        ej2_base_1.append([].slice.call(this.parent.getCellTemplate()(cell, this.parent, 'cellTemplate', this.parent.element.id + '_cellTemplate')), cell.targetCell);
                    }
                }
                this.parent.gridHeaderCellInfo = [];
            }
            if (this.parent.element.querySelector('.e-firstcell')) {
                if (this.parent.enableRtl) {
                    this.parent.element.querySelector('.e-firstcell').style.borderRight = 'none';
                }
                else {
                    this.parent.element.querySelector('.e-firstcell').style.borderLeft = 'none';
                }
            }
            this.parent.grid.widthService.setWidthToTable();
            if (!this.parent.isEmptyGrid) {
                this.calculateGridHeight(true);
            }
            if (this.parent.currentView !== 'Chart') {
                this.parent.grid.hideScroll();
            }
            this.parent.isScrolling = false;
            this.parent.notify(events.contentReady, {});
        };
        Render.prototype.contextMenuOpen = function (args) {
            for (var _i = 0, _a = args.items; _i < _a.length; _i++) {
                var item = _a[_i];
                var cellTarget = this.parent.lastCellClicked;
                var elem = null;
                var bool = void 0;
                Iif (cellTarget.classList.contains('e-stackedheadercelldiv') || cellTarget.classList.contains('e-cellvalue') ||
                    cellTarget.classList.contains('e-headercelldiv') || cellTarget.classList.contains('e-icons') || cellTarget.classList.contains('e-rhandler')) {
                    elem = cellTarget.parentElement;
                }
                else if (cellTarget.classList.contains('e-headercell') || cellTarget.classList.contains('e-rowcell') || cellTarget.classList.contains('e-columnsheader') ||
                    cellTarget.classList.contains('e-rowsheader') || cellTarget.classList.contains('e-valuescontent') || cellTarget.classList.contains('e-valuesheader')) {
                    elem = cellTarget;
                }
                else Eif (cellTarget.classList.contains('e-headertext')) {
                    elem = cellTarget.parentElement.parentElement;
                }
                if (elem.classList.contains('e-valuesheader') || elem.classList.contains('e-stot')) {
                    bool = true;
                }
                var rowIndex = Number(elem.getAttribute('index'));
                var colIndex = Number(elem.getAttribute('aria-colindex'));
                var pivotValue1 = this.parent.pivotValues[rowIndex][colIndex];
                var select = item.id;
                switch (select) {
                    case 'expand':
                        if (elem.querySelectorAll('.' + cls.EXPAND).length > 0) {
                            Eif (args.element.querySelectorAll(cls.CONTEXT_COLLAPSE_ID)) {
                                args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.add(cls.MENU_DISABLE);
                            }
                            if (args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.contains(cls.MENU_DISABLE)) {
                                args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.remove(cls.MENU_DISABLE);
                            }
                            if (args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.contains(cls.MENU_HIDE)) {
                                args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.remove(cls.MENU_HIDE);
                                args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.remove(cls.MENU_HIDE);
                            }
                        }
                        else {
                            if (bool) {
                                args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.add(cls.MENU_HIDE);
                            }
                            else {
                                args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.add(cls.MENU_DISABLE);
                            }
                        }
                        break;
                    case 'collapse':
                        if (elem.querySelectorAll('.' + cls.COLLAPSE).length > 0) {
                            Eif (args.element.querySelector(cls.CONTEXT_EXPAND_ID)) {
                                args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.add(cls.MENU_DISABLE);
                            }
                            Eif (args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.contains(cls.MENU_DISABLE)) {
                                args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.remove(cls.MENU_DISABLE);
                            }
                            Iif (args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.contains(cls.MENU_HIDE)) {
                                args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.remove(cls.MENU_HIDE);
                                args.element.querySelector(cls.CONTEXT_EXPAND_ID).classList.remove(cls.MENU_HIDE);
                            }
                        }
                        else {
                            if (bool) {
                                args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.add(cls.MENU_HIDE);
                            }
                            else {
                                args.element.querySelector(cls.CONTEXT_COLLAPSE_ID).classList.add(cls.MENU_DISABLE);
                            }
                        }
                        break;
                    case 'drillthrough':
                        if (!this.parent.allowDrillThrough) {
                            Eif (args.element.querySelector(cls.CONTEXT_DRILLTHROUGH_ID)) {
                                args.element.querySelector(cls.CONTEXT_DRILLTHROUGH_ID).classList.add(cls.MENU_DISABLE);
                            }
                        }
                        else if (!(elem.classList.contains('e-summary'))) {
                            Iif (elem.innerText === "") {
                                if (args.element.querySelector(cls.CONTEXT_DRILLTHROUGH_ID)) {
                                    args.element.querySelector(cls.CONTEXT_DRILLTHROUGH_ID).classList.add(cls.MENU_DISABLE);
                                }
                            }
                        }
                        else {
                            Iif (args.element.querySelector(cls.CONTEXT_DRILLTHROUGH_ID).classList.contains(cls.MENU_DISABLE)) {
                                args.element.querySelector(cls.CONTEXT_DRILLTHROUGH_ID).classList.remove(cls.MENU_DISABLE);
                            }
                        }
                        break;
                    case 'sortasc':
                        if (!this.parent.enableValueSorting) {
                            Eif (args.element.querySelector(cls.CONTEXT_SORT_ASC_ID)) {
                                args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.add(cls.MENU_DISABLE);
                            }
                        }
                        else if (elem.querySelectorAll('.e-icon-descending').length > 0) {
                            Eif (args.element.querySelector(cls.CONTEXT_SORT_DESC_ID)) {
                                args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.add(cls.MENU_DISABLE);
                            }
                            else {
                                args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.remove(cls.MENU_DISABLE);
                            }
                            Eif (args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.contains(cls.MENU_DISABLE)) {
                                args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.remove(cls.MENU_DISABLE);
                            }
                        }
                        else if (args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.contains(cls.MENU_DISABLE)) {
                            args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.remove(cls.MENU_DISABLE);
                        }
                        break;
                    case 'sortdesc':
                        if (!this.parent.enableValueSorting) {
                            Eif (args.element.querySelector(cls.CONTEXT_SORT_DESC_ID)) {
                                args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.add(cls.MENU_DISABLE);
                            }
                        }
                        else if (elem.querySelectorAll('.e-icon-ascending').length > 0) {
                            Eif (args.element.querySelector(cls.CONTEXT_SORT_ASC_ID)) {
                                args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.add(cls.MENU_DISABLE);
                            }
                            else {
                                args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.remove(cls.MENU_DISABLE);
                            }
                            Iif (args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.contains(cls.MENU_DISABLE)) {
                                args.element.querySelector(cls.CONTEXT_SORT_DESC_ID).classList.remove(cls.MENU_DISABLE);
                            }
                        }
                        else Iif (args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.contains(cls.MENU_DISABLE)) {
                            args.element.querySelector(cls.CONTEXT_SORT_ASC_ID).classList.remove(cls.MENU_DISABLE);
                        }
                        break;
                    case 'CalculatedField':
                        if (!this.parent.allowCalculatedField) {
                            args.element.querySelector(cls.CONTEXT_CALC_ID).classList.add(cls.MENU_DISABLE);
                        }
                        break;
                    case 'pdf':
                        if (!this.parent.allowPdfExport) {
                            args.element.querySelector(cls.CONTEXT_PDF_ID).classList.add(cls.MENU_DISABLE);
                        }
                        break;
                    case 'excel':
                        if (!this.parent.allowExcelExport) {
                            args.element.querySelector(cls.CONTEXT_EXCEL_ID).classList.add(cls.MENU_DISABLE);
                        }
                        break;
                    case 'csv':
                        if (!this.parent.allowExcelExport) {
                            args.element.querySelector(cls.CONTEXT_CSV_ID).classList.add(cls.MENU_DISABLE);
                        }
                        break;
                    case 'exporting':
                        if ((!this.parent.allowExcelExport) && (!this.parent.allowPdfExport)) {
                            args.element.querySelector(cls.CONTEXT_EXPORT_ID).classList.add(cls.MENU_DISABLE);
                        }
                        break;
                    case 'aggregate':
                        if (elem.innerText === "") {
                            Eif (args.element.querySelector(cls.CONTEXT_AGGREGATE_ID)) {
                                args.element.querySelector(cls.CONTEXT_AGGREGATE_ID).classList.add(cls.MENU_DISABLE);
                            }
                        }
                        else {
                            if (args.element.querySelector(cls.CONTEXT_AGGREGATE_ID).classList.contains(cls.MENU_DISABLE)) {
                                args.element.querySelector(cls.CONTEXT_AGGREGATE_ID).classList.remove(cls.MENU_DISABLE);
                            }
                        }
                        break;
                }
            }
            this.parent.trigger(events.contextMenuOpen, args);
        };
        Render.prototype.contextMenuClick = function (args) {
            var target = this.parent.lastCellClicked;
            var selected = args.item.id;
            var event = new MouseEvent('dblclick', {
                'view': window,
                'bubbles': true,
                'cancelable': true
            });
            var ele = null;
            Iif (target.classList.contains('e-stackedheadercelldiv') || target.classList.contains('e-cellvalue') ||
                target.classList.contains('e-headercelldiv') || target.classList.contains('e-icons') || target.classList.contains('e-rhandler')) {
                ele = target.parentElement;
            }
            else Eif (target.classList.contains('e-headercell') || target.classList.contains('e-rowcell')) {
                ele = target;
            }
            else if (target.classList.contains('e-headertext')) {
                ele = target.parentElement.parentElement;
            }
            var rowIndx = Number(ele.getAttribute('index'));
            var colIndx = Number(ele.getAttribute('aria-colindex'));
            var pivotValue = this.parent.pivotValues[rowIndx][colIndx];
            if (args.item.id === 'AggSum' || args.item.id === 'AggProduct' || args.item.id === 'AggCount' ||
                args.item.id === 'AggDistinctCount' || args.item.id === 'AggAvg' || args.item.id === 'AggMin' ||
                args.item.id === 'AggMax' || args.item.id === 'AggMoreOption') {
                this.field = this.parent.engineModule.fieldList[pivotValue.actualText.toString()].caption;
            }
            switch (selected) {
                case 'pdf':
                    this.parent.pdfExport();
                    break;
                case 'excel':
                    this.parent.excelExport();
                    break;
                case 'csv':
                    this.parent.csvExport();
                    break;
                case 'drillthrough':
                    ele.dispatchEvent(event);
                    break;
                case 'sortasc':
                    this.parent.setProperties({
                        dataSourceSettings: {
                            valueSortSettings: {
                                headerText: pivotValue.valueSort.levelName,
                                headerDelimiter: this.parent.dataSourceSettings.valueSortSettings.headerDelimiter
                            }
                        }
                    });
                    this.parent.dataSourceSettings.valueSortSettings.sortOrder = 'Ascending';
                    break;
                case 'sortdesc':
                    this.parent.setProperties({
                        dataSourceSettings: {
                            valueSortSettings: {
                                headerText: pivotValue.valueSort.levelName,
                                headerDelimiter: this.parent.dataSourceSettings.valueSortSettings.headerDelimiter
                            }
                        }
                    });
                    this.parent.dataSourceSettings.valueSortSettings.sortOrder = 'Descending';
                    break;
                case 'expand':
                    Eif (ele.querySelectorAll('.' + cls.EXPAND)) {
                        var exp = ele.querySelectorAll('.' + cls.EXPAND)[0];
                        this.parent.onDrill(exp);
                    }
                    break;
                case 'collapse':
                    Eif (ele.querySelectorAll('.' + cls.COLLAPSE)) {
                        var colp = ele.querySelectorAll('.' + cls.COLLAPSE)[0];
                        this.parent.onDrill(colp);
                    }
                    break;
                case 'CalculatedField':
                    this.parent.calculatedFieldModule.createCalculatedFieldDialog();
                    break;
                case 'AggSum':
                    this.updateAggregate('Sum');
                    break;
                case 'AggProduct':
                    this.updateAggregate('Product');
                    break;
                case 'AggCount':
                    this.updateAggregate('Count');
                    break;
                case 'AggDistinctCount':
                    this.updateAggregate('DistinctCount');
                    break;
                case 'AggAvg':
                    this.updateAggregate('Avg');
                    break;
                case 'AggMin':
                    this.updateAggregate('Min');
                    break;
                case 'AggMax':
                    this.updateAggregate('Max');
                    break;
                case 'AggMoreOption':
                    ele.setAttribute('id', this.field);
                    ele.setAttribute('data-caption', this.field);
                    ele.setAttribute('data-field', this.field);
                    ele.setAttribute('data-type', this.parent.engineModule.fieldList[pivotValue.actualText.toString()].aggregateType);
                    ele.setAttribute('data-basefield', this.parent.engineModule.fieldList[pivotValue.actualText.toString()].baseField);
                    ele.setAttribute('data-baseItem', this.parent.engineModule.fieldList[pivotValue.actualText.toString()].baseItem);
                    this.aggMenu.createValueSettingsDialog(ele, this.parent.element);
                    break;
            }
            this.parent.trigger(events.contextMenuClick, args);
        };
        Render.prototype.updateAggregate = function (aggregate) {
            var valuefields = this.parent.dataSourceSettings.values;
            for (var valueCnt = 0; valueCnt < this.parent.dataSourceSettings.values.length; valueCnt++) {
                if (this.parent.dataSourceSettings.values[valueCnt].name === this.field) {
                    var dataSourceItem = valuefields[valueCnt];
                    dataSourceItem.type = aggregate;
                }
            }
        };
        Render.prototype.injectGridModules = function (parent) {
            ej2_grids_2.Grid.Inject(ej2_grids_2.Freeze);
            if (parent.allowExcelExport) {
                ej2_grids_2.Grid.Inject(ej2_grids_2.ExcelExport);
            }
            if (parent.allowPdfExport) {
                ej2_grids_2.Grid.Inject(ej2_grids_2.PdfExport);
            }
            ej2_grids_2.Grid.Inject(ej2_grids_3.Selection, ej2_grids_1.Reorder, ej2_grids_2.Resize);
            if (this.gridSettings.contextMenuItems) {
                ej2_grids_2.Grid.Inject(ej2_grids_2.ContextMenu);
            }
        };
        Render.prototype.updateGridSettings = function () {
            this.injectGridModules(this.parent);
            this.parent.grid.allowResizing = this.gridSettings.allowResizing;
            this.parent.grid.allowTextWrap = this.gridSettings.allowTextWrap;
            this.parent.grid.allowReordering = this.gridSettings.allowReordering;
            this.parent.grid.allowSelection = this.gridSettings.allowSelection;
            this.parent.grid.contextMenuItems = this.gridSettings.contextMenuItems;
            this.parent.grid.selectedRowIndex = this.gridSettings.selectedRowIndex;
            this.parent.grid.selectionSettings = this.gridSettings.selectionSettings;
            this.parent.grid.textWrapSettings = this.gridSettings.textWrapSettings;
            this.parent.grid.printMode = this.gridSettings.printMode;
            this.parent.grid.rowHeight = this.gridSettings.rowHeight;
            this.parent.grid.gridLines = this.gridSettings.gridLines;
            if (this.parent.lastGridSettings) {
                var keys = Object.keys(this.parent.lastGridSettings);
                Iif (keys.indexOf('height') > -1) {
                    this.parent.grid.height = this.gridSettings.height;
                }
                Iif (keys.indexOf('width') > -1) {
                    this.parent.grid.width = this.gridSettings.width;
                }
                this.updatePivotColumns();
            }
            this.clearColumnSelection();
        };
        Render.prototype.updatePivotColumns = function () {
            var keys = Object.keys(this.parent.lastGridSettings);
            for (var colPos = 0; colPos < this.parent.pivotColumns.length; colPos++) {
                var pivotColumn = this.parent.pivotColumns[colPos];
                for (var keyPos = 0; keyPos < keys.length; keyPos++) {
                    var key = keys[keyPos];
                    if (!ej2_base_1.isNullOrUndefined(this.parent.pivotColumns[colPos][key])) {
                        pivotColumn[key] = this.parent.lastGridSettings[key];
                    }
                }
            }
            this.parent.fillGridColumns(this.parent.grid.columns);
        };
        Render.prototype.clearColumnSelection = function () {
            this.parent.element.querySelectorAll('.' + cls.CELL_ACTIVE_BGCOLOR).forEach(function (ele) {
                ele.classList.remove(cls.CELL_ACTIVE_BGCOLOR);
                ele.classList.remove(cls.SELECTED_BGCOLOR);
            });
        };
        Render.prototype.appendValueSortIcon = function (cell, tCell, rCnt, cCnt) {
            if (this.parent.enableValueSorting) {
                var vSort = this.parent.dataSourceSettings.valueSortSettings;
                var len = (cell.type === 'grand sum' &&
                    this.parent.dataSourceSettings.values.length === 1 && !this.parent.dataSourceSettings.alwaysShowValueHeader) ? 0 :
                    (this.parent.dataSourceSettings.values.length > 1 || this.parent.dataSourceSettings.alwaysShowValueHeader) ?
                        (this.parent.engineModule.headerContent.length - 1) :
                        this.parent.dataSourceSettings.columns.length === 0 ? 0 : (this.parent.engineModule.headerContent.length - 1);
                var lock = (vSort && vSort.headerText) ? cell.valueSort.levelName === vSort.headerText : cCnt === vSort.columnIndex;
                if (vSort !== undefined && lock && rCnt === len && this.parent.dataSourceSettings.valueAxis === 'column') {
                    Eif (tCell.querySelector('.e-sortfilterdiv')) {
                        tCell.querySelector('.e-sortfilterdiv').classList.add(vSort.sortOrder === 'Descending' ?
                            'e-descending' : 'e-ascending');
                        tCell.querySelector('.e-sortfilterdiv').classList.add(vSort.sortOrder === 'Descending' ?
                            'e-icon-descending' : 'e-icon-ascending');
                    }
                    else {
                        tCell.appendChild(ej2_base_1.createElement('div', {
                            className: (vSort.sortOrder === 'Descending' ?
                                'e-icon-descending e-icons e-descending e-sortfilterdiv' :
                                'e-icon-ascending e-icons e-ascending e-sortfilterdiv'),
                        }));
                    }
                    if (!ej2_base_1.isNullOrUndefined(cell.hasChild) && cell.type !== 'grand sum' && tCell.querySelector('.e-expand') &&
                        (tCell.querySelector('.e-icon-descending') || tCell.querySelector('.e-icon-ascending'))) {
                        var element = (tCell.querySelector('.e-icon-descending') || tCell.querySelector('.e-icon-ascending'));
                        ej2_base_1.setStyleAttribute(element, { 'padding-top': '12px' });
                    }
                }
            }
            return tCell;
        };
        Render.prototype.onResizeStop = function (args) {
            var column = args.column.field === '0.formattedText' ? '0.formattedText' : args.column.customAttributes.cell.valueSort.levelName;
            this.parent.resizeInfo[column] = Number(args.column.width.toString().split('px')[0]);
            this.setGroupWidth(args);
            this.calculateGridHeight(true);
            this.parent.grid.hideScroll();
        };
        Render.prototype.setGroupWidth = function (args) {
            if (this.parent.showGroupingBar && this.parent.groupingBarModule &&
                this.parent.element.querySelector('.' + cls.GROUPING_BAR_CLASS)) {
                this.parent.groupingBarModule.refreshUI();
                if (this.parent.element.querySelector('.e-group-row').offsetWidth < 245 && !this.parent.firstColWidth) {
                    args.cancel = true;
                    var gridColumn = this.parent.grid.columns;
                    if (gridColumn && gridColumn.length > 0) {
                        gridColumn[0].width = this.resColWidth;
                    }
                    this.parent.element.querySelector('.e-frozenheader').querySelector('col').style.width = (this.resColWidth + 'px');
                    this.parent.element.querySelector('.e-frozencontent').querySelector('col').style.width = (this.resColWidth + 'px');
                }
                this.parent.element.querySelector('.e-group-rows').style.height = 'auto';
                this.parent.element.querySelector('.e-group-values').style.width =
                    this.parent.element.querySelector('.e-group-row').offsetWidth + 'px';
                var firstRowHeight = this.parent.element.querySelector('.e-headercontent').offsetHeight;
                this.parent.element.querySelector('.e-group-rows').style.height = firstRowHeight + 'px';
            }
            this.parent.trigger(args.e.type === 'touchend' || args.e.type === 'mouseup' ? events.resizeStop : events.resizing, args);
        };
        Render.prototype.selected = function () {
            clearTimeout(this.timeOutObj);
            this.timeOutObj = setTimeout(this.onSelect.bind(this), 300);
        };
        Render.prototype.onSelect = function () {
            var pivotArgs = { selectedCellsInfo: [], pivotValues: this.parent.pivotValues, currentCell: null };
            var selectedElements = this.parent.element.querySelectorAll('.' + cls.CELL_SELECTED_BGCOLOR + ',.' + cls.SELECTED_BGCOLOR);
            for (var _i = 0, selectedElements_1 = selectedElements; _i < selectedElements_1.length; _i++) {
                var element = selectedElements_1[_i];
                var colIndex = Number(element.getAttribute('aria-colindex'));
                var rowIndex = Number(element.getAttribute('index'));
                var cell = this.engine.pivotValues[rowIndex][colIndex];
                if (cell) {
                    if (cell.axis === 'value') {
                        pivotArgs.selectedCellsInfo.push({
                            currentCell: cell,
                            value: cell.value,
                            columnHeaders: cell.columnHeaders,
                            rowHeaders: cell.rowHeaders,
                            measure: cell.actualText.toString()
                        });
                    }
                    else if (cell.axis === 'column') {
                        pivotArgs.selectedCellsInfo.push({
                            currentCell: cell,
                            value: cell.formattedText,
                            columnHeaders: cell.valueSort.levelName,
                            rowHeaders: '',
                            measure: ''
                        });
                    }
                    else {
                        pivotArgs.selectedCellsInfo.push({
                            currentCell: cell,
                            value: cell.formattedText,
                            columnHeaders: '',
                            rowHeaders: cell.valueSort.levelName,
                            measure: ''
                        });
                    }
                }
            }
            this.parent.trigger(events.cellSelected, pivotArgs);
        };
        Render.prototype.rowCellBoundEvent = function (args) {
            var tCell = args.cell;
            if (tCell && !this.parent.isEmptyGrid) {
                var customClass = this.parent.hyperlinkSettings.cssClass;
                tCell.setAttribute('index', (Number(tCell.getAttribute('index')) + this.engine.headerContent.length).toString());
                var cell = args.data[0];
                if (tCell.getAttribute('aria-colindex') === '0') {
                    var isValueCell = cell.type && cell.type === 'value';
                    tCell.innerText = '';
                    var level = cell.level ? cell.level : (isValueCell ? (this.lastSpan + 1) : 0);
                    do {
                        if (level > 0) {
                            tCell.appendChild(ej2_base_1.createElement('span', {
                                className: level === 0 ? '' : cls.NEXTSPAN,
                            }));
                        }
                        level--;
                    } while (level > -1);
                    level = cell.level ? cell.level : 0;
                    this.lastSpan = !isValueCell ? level : this.lastSpan;
                    if (!cell.hasChild && level > 0) {
                        tCell.appendChild(ej2_base_1.createElement('span', {
                            className: cls.LASTSPAN,
                        }));
                    }
                    var fieldName = void 0;
                    if ((this.parent.dataSourceSettings.rows.length > 0 &&
                        (cell.valueSort ? Object.keys(cell.valueSort).length > 0 : true))) {
                        fieldName = level > -1 ? this.parent.dataSourceSettings.rows[level].name : '';
                        tCell.setAttribute('fieldname', fieldName);
                    }
                    var localizedText = cell.formattedText;
                    if (cell.type) {
                        if (cell.type === 'grand sum') {
                            tCell.classList.add('e-gtot');
                            localizedText = this.parent.localeObj.getConstant('grandTotal');
                        }
                        else {
                            tCell.classList.add('e-stot');
                        }
                    }
                    tCell.classList.add(cls.ROWSHEADER);
                    if (cell.hasChild === true) {
                        tCell.appendChild(ej2_base_1.createElement('div', {
                            className: (cell.isDrilled === true ? cls.COLLAPSE : cls.EXPAND) + ' ' + cls.ICON,
                            attrs: {
                                'title': cell.isDrilled === true ? this.parent.localeObj.getConstant('collapse') :
                                    this.parent.localeObj.getConstant('expand')
                            }
                        }));
                    }
                    tCell.appendChild(ej2_base_1.createElement('span', {
                        className: cls.CELLVALUE,
                        innerHTML: (this.parent.isRowCellHyperlink || cell.enableHyperlink ? '<a  data-url="' + localizedText + '" class="e-hyperlinkcell ' + customClass + '">' + localizedText + '</a>' : localizedText)
                    }));
                    var vSort = this.parent.pivotView.dataSourceSettings.valueSortSettings;
                    if (this.parent.enableValueSorting) {
                        if (vSort && vSort.headerText && this.parent.dataSourceSettings.valueAxis === 'row'
                            && this.parent.pivotValues[Number(tCell.getAttribute('index'))][0].valueSort.levelName) {
                            Iif (this.parent.pivotValues[Number(tCell.getAttribute('index'))][0].valueSort.levelName
                                === vSort.headerText) {
                                var style = (tCell.querySelector('.e-expand') || tCell.querySelector('.e-collapse')) ?
                                    'padding-top: 18px' : 'padding-top: 12px';
                                tCell.appendChild(ej2_base_1.createElement('div', {
                                    className: (vSort.sortOrder === 'Descending' ?
                                        'e-icon-descending e-icons e-descending e-sortfilterdiv' :
                                        'e-icon-ascending e-icons e-ascending e-sortfilterdiv'),
                                    styles: style
                                }));
                            }
                        }
                    }
                }
                else {
                    var innerText = tCell.innerText;
                    tCell.innerText = '';
                    tCell.classList.add(cls.VALUESCONTENT);
                    cell = args.data[Number(tCell.getAttribute('aria-colindex'))];
                    if (cell.isSum) {
                        tCell.classList.add(cls.SUMMARY);
                    }
                    if (cell.cssClass) {
                        tCell.classList.add(cell.cssClass);
                    }
                    tCell.appendChild(ej2_base_1.createElement('span', {
                        className: cls.CELLVALUE,
                        innerHTML: ((tCell.className.indexOf('e-summary') !== -1 && this.parent.isSummaryCellHyperlink) ||
                            (tCell.className.indexOf('e-summary') === -1 && this.parent.isValueCellHyperlink) || cell.enableHyperlink ?
                            '<a data-url="' + innerText + '" class="e-hyperlinkcell ' + customClass + '">' + innerText + '</a>' : innerText)
                    }));
                }
                if (this.parent.cellTemplate) {
                    var index = tCell.getAttribute('index');
                    var colindex = tCell.getAttribute('aria-colindex');
                    var templateID = index + '_' + colindex;
                    Eif (!(window && window.Blazor)) {
                        ej2_base_1.append([].slice.call(this.parent.getCellTemplate()({ targetCell: tCell }, this.parent, 'cellTemplate', this.parent.element.id + '_cellTemplate')), tCell);
                    }
                    else if (index && colindex) {
                        this.parent.gridCellCollection[templateID] = tCell;
                    }
                }
                this.unWireEvents(tCell);
                this.wireEvents(tCell);
            }
            args.pivotview = this.parent;
            this.parent.trigger(events.queryCellInfo, args);
        };
        Render.prototype.columnCellBoundEvent = function (args) {
            if (args.cell.column && args.cell.column.customAttributes) {
                var cell = args.cell.column.customAttributes.cell;
                var tCell = args.node;
                Eif (cell) {
                    var customClass = this.parent.hyperlinkSettings.cssClass;
                    var level = cell.level ? cell.level : 0;
                    if ((cell.level === -1 && !cell.rowSpan && cell.rowIndex !== this.engine.headerContent.length - 1)
                        || cell.rowSpan === -1) {
                        args.node.style.display = 'none';
                    }
                    else if (cell.rowSpan > 1) {
                        args.node.setAttribute('rowspan', cell.rowSpan.toString());
                        args.node.setAttribute('aria-rowspan', cell.rowSpan.toString());
                        if ((cell.rowIndex + cell.rowSpan) === this.engine.headerContent.length) {
                            args.node.style.borderBottomWidth = '0px';
                        }
                    }
                    args.node.setAttribute('aria-colindex', cell.colIndex.toString());
                    args.node.setAttribute('index', cell.rowIndex.toString());
                    var fieldName = void 0;
                    if (!(this.parent.dataSourceSettings.values && this.parent.dataSourceSettings.valueAxis === 'column' &&
                        this.parent.dataSourceSettings.values.length > 1 &&
                        (cell.rowIndex === this.engine.headerContent.length - 1)) && this.parent.dataSourceSettings.columns &&
                        this.parent.dataSourceSettings.columns.length > 0) {
                        fieldName = level > -1 && this.parent.dataSourceSettings.columns[level] ?
                            this.parent.dataSourceSettings.columns[level].name : '';
                        tCell.setAttribute('fieldname', fieldName);
                    }
                    if (cell.type) {
                        tCell.classList.add(cell.type === 'grand sum' ? 'e-gtot' : 'e-stot');
                        var localizedText = cell.type === 'grand sum' ? this.parent.localeObj.getConstant('grandTotal') :
                            cell.formattedText.split('Total')[0] + this.parent.localeObj.getConstant('total');
                        if (tCell.querySelector('.e-headertext') !== null) {
                            tCell.querySelector('.e-headertext').innerText = localizedText;
                        }
                        else {
                            tCell.querySelector('.e-stackedheadercelldiv').innerText = localizedText;
                        }
                    }
                    tCell.classList.add(cls.COLUMNSHEADER);
                    if (this.parent.isColumnCellHyperlink || cell.enableHyperlink) {
                        if (tCell.querySelector('.e-stackedheadercelldiv')) {
                            var innerText = tCell.querySelector('.e-stackedheadercelldiv').innerText;
                            tCell.querySelector('.e-stackedheadercelldiv').innerHTML =
                                '<a data-url="' + innerText + '" class="e-hyperlinkcell ' + customClass + '">' + innerText + '</a>';
                        }
                        else Eif (tCell.querySelector('.e-headertext')) {
                            var innerText = tCell.querySelector('.e-headertext').innerText;
                            tCell.querySelector('.e-headertext').innerHTML =
                                '<a data-url="' + innerText + '" class="e-hyperlinkcell ' + customClass + '">' + innerText + '</a>';
                        }
                    }
                    if (cell.hasChild === true) {
                        var hdrdiv = tCell.querySelector('.e-headercelldiv');
                        if (hdrdiv) {
                            hdrdiv.style.height = 'auto';
                            hdrdiv.style.lineHeight = 'normal';
                        }
                        var div = ej2_base_1.createElement('div', {
                            className: (cell.isDrilled === true ? cls.COLLAPSE : cls.EXPAND) + ' ' + cls.ICON,
                            attrs: {
                                'title': cell.isDrilled === true ? this.parent.localeObj.getConstant('collapse') :
                                    this.parent.localeObj.getConstant('expand')
                            }
                        });
                        tCell.children[0].classList.add(cls.CELLVALUE);
                        Iif (window.navigator.userAgent.indexOf('Edge') > -1 || window.navigator.userAgent.indexOf('Trident') > -1) {
                            tCell.children[0].style.display = 'table';
                        }
                        else {
                            tCell.children[0].style.display = 'block';
                        }
                        tCell.insertBefore(div, tCell.children[0]);
                    }
                    tCell = this.appendValueSortIcon(cell, tCell, cell.rowIndex, cell.colIndex);
                    if (this.parent.cellTemplate) {
                        var index = tCell.getAttribute('index');
                        var colindex = tCell.getAttribute('aria-colindex');
                        var templateID = index + '_' + colindex;
                        Eif (!(window && window.Blazor)) {
                            this.parent.gridHeaderCellInfo.push({ targetCell: tCell });
                        }
                        else if (index && colindex) {
                            this.parent.gridCellCollection[templateID] = tCell;
                        }
                    }
                    var field = void 0;
                    var len = this.parent.dataSourceSettings.values.length;
                    for (var vCnt = 0; vCnt < len; vCnt++) {
                        if (this.parent.dataSourceSettings.values[vCnt].name === cell.actualText) {
                            tCell.classList.add(cls.VALUESHEADER);
                        }
                    }
                    this.unWireEvents(tCell);
                    this.wireEvents(tCell);
                }
            }
            this.parent.trigger(events.headerCellInfo, args);
        };
        Render.prototype.onHyperCellClick = function (e) {
            var cell = e.target.parentElement.parentElement;
            cell = (cell.className.indexOf('e-headercelldiv') > -1 ? cell.parentElement : cell);
            var args = {
                currentCell: cell,
                data: this.engine.pivotValues[Number(cell.getAttribute('index'))][Number(cell.getAttribute('aria-colindex'))],
                cancel: true
            };
            this.parent.trigger(events.hyperlinkCellClick, args, function (observedArgs) {
                Eif (!observedArgs.cancel) {
                    var url = args.currentCell.getAttribute('data-url') ? (args.currentCell).getAttribute('data-url') :
                        args.currentCell.querySelector('a').getAttribute('data-url');
                    window.open(url);
                }
            });
        };
        Render.prototype.getRowStartPos = function () {
            var pivotValues = this.parent.pivotValues;
            var rowPos;
            for (var rCnt = 0; rCnt < pivotValues.length; rCnt++) {
                if (pivotValues[rCnt] && pivotValues[rCnt][0] && pivotValues[rCnt][0].axis === 'row') {
                    rowPos = rCnt;
                    break;
                }
            }
            return rowPos;
        };
        Render.prototype.frameDataSource = function (type) {
            var dataContent = [];
            if (this.parent.dataSourceSettings.values.length > 0 && !this.engine.isEmptyData) {
                if ((this.parent.enableValueSorting) || !this.engine.isEngineUpdated) {
                    var rowCnt = 0;
                    var pivotValues = this.parent.pivotValues;
                    var start = type === 'value' ? this.rowStartPos : 0;
                    var end = type === 'value' ? pivotValues.length : this.rowStartPos;
                    for (var rCnt = start; rCnt < end; rCnt++) {
                        Eif (pivotValues[rCnt]) {
                            rowCnt = type === 'header' ? rCnt : rowCnt;
                            dataContent[rowCnt] = {};
                            for (var cCnt = 0; cCnt < pivotValues[rCnt].length; cCnt++) {
                                if (pivotValues[rCnt][cCnt]) {
                                    dataContent[rowCnt][cCnt] = pivotValues[rCnt][cCnt];
                                }
                            }
                            rowCnt++;
                        }
                    }
                }
                else {
                    dataContent = type === 'value' ? this.engine.valueContent : this.engine.headerContent;
                }
            }
            else {
                dataContent = this.frameEmptyData();
            }
            return dataContent;
        };
        Render.prototype.frameEmptyData = function () {
            var dataContent = [{
                    0: { formattedText: this.parent.localeObj.getConstant('grandTotal') },
                    1: { formattedText: this.parent.localeObj.getConstant('emptyData') }
                }];
            return dataContent;
        };
        Render.prototype.calculateColWidth = function (colCount) {
            var parWidth = isNaN(this.parent.width) ? (this.parent.width.toString().indexOf('%') > -1 ?
                ((parseFloat(this.parent.width.toString()) / 100) * this.parent.element.offsetWidth) : this.parent.element.offsetWidth) :
                Number(this.parent.width);
            parWidth = parWidth - (this.gridSettings.columnWidth > this.resColWidth ? this.gridSettings.columnWidth : this.resColWidth);
            colCount = colCount - 1;
            var colWidth = (colCount * this.gridSettings.columnWidth) < parWidth ? (parWidth / colCount) : this.gridSettings.columnWidth;
            return colWidth;
        };
        Render.prototype.resizeColWidth = function (colCount) {
            var parWidth = isNaN(this.parent.width) ? (this.parent.width.toString().indexOf('%') > -1 ?
                ((parseFloat(this.parent.width.toString()) / 100) * this.parent.element.offsetWidth) : this.parent.element.offsetWidth) :
                Number(this.parent.width);
            colCount = colCount - 1;
            parWidth = parWidth - (this.gridSettings.columnWidth > this.resColWidth ? this.gridSettings.columnWidth : this.resColWidth);
            var colWidth = (colCount * this.gridSettings.columnWidth) < parWidth ? (parWidth / colCount) : this.gridSettings.columnWidth;
            return colWidth;
        };
        Render.prototype.calculateGridWidth = function () {
            var parWidth = this.parent.width;
            var eleWidth = this.parent.element.getBoundingClientRect().width ?
                this.parent.element.getBoundingClientRect().width : this.parent.element.offsetWidth;
            Eif (this.gridSettings.width === 'auto') {
                if (this.parent.width === 'auto') {
                    parWidth = eleWidth;
                }
                else if (this.parent.width.toString().indexOf('%') > -1) {
                    parWidth = ((parseFloat(this.parent.width.toString()) / 100) * eleWidth);
                }
            }
            else {
                parWidth = this.gridSettings.width;
            }
            return parWidth;
        };
        Render.prototype.calculateGridHeight = function (elementCreated) {
            var gridHeight = this.parent.height;
            var parHeight = this.parent.getHeightAsNumber();
            if (isNaN(parHeight)) {
                parHeight = this.parent.element.offsetHeight > 0 ? this.parent.element.offsetHeight : 1;
            }
            if (this.parent.currentView !== 'Chart') {
                if (this.gridSettings.height === 'auto' && parHeight && this.parent.element.querySelector('.' + cls.GRID_HEADER)) {
                    var rowColHeight = this.parent.element.querySelector('.' + cls.GRID_HEADER).offsetHeight;
                    var gBarHeight = rowColHeight + (this.parent.element.querySelector('.' + cls.GROUPING_BAR_CLASS) ?
                        this.parent.element.querySelector('.' + cls.GROUPING_BAR_CLASS).offsetHeight : 0);
                    var toolBarHeight = this.parent.element.querySelector('.' + cls.GRID_TOOLBAR) ? 42 : 0;
                    gridHeight = parHeight - (gBarHeight + toolBarHeight) - 2;
                    Eif (elementCreated) {
                        var tableHeight = this.parent.element.querySelector('.' + cls.MOVABLECONTENT_DIV + ' .' + cls.TABLE).offsetHeight;
                        var contentHeight = this.parent.element.querySelector('.' + cls.MOVABLECONTENT_DIV).offsetHeight;
                        var tableWidth = this.parent.element.querySelector('.' + cls.MOVABLECONTENT_DIV + ' .' + cls.TABLE).offsetWidth;
                        var contentWidth = this.parent.element.querySelector('.' + cls.MOVABLECONTENT_DIV).offsetWidth;
                        var horizontalOverflow = contentWidth < tableWidth;
                        var verticalOverflow = contentHeight < tableHeight;
                        var commonOverflow = horizontalOverflow && ((gridHeight - tableHeight) < 18) ? true : false;
                        if (gridHeight >= tableHeight && (horizontalOverflow ? gridHeight >= contentHeight : true) &&
                            !verticalOverflow && !commonOverflow) {
                            this.parent.grid.height = 'auto';
                        }
                        else {
                            this.parent.grid.height = gridHeight;
                        }
                    }
                    else {
                        if (gridHeight > (this.engine.valueContent.length * this.gridSettings.rowHeight)) {
                            gridHeight = 'auto';
                        }
                    }
                }
                else {
                    gridHeight = this.gridSettings.height;
                }
            }
            return gridHeight < this.parent.gridSettings.rowHeight ? this.parent.gridSettings.rowHeight : gridHeight;
        };
        Render.prototype.frameStackedHeaders = function () {
            var integrateModel = [];
            if (this.parent.dataSourceSettings.values.length > 0 && !this.engine.isEmptyData) {
                var headerCnt = this.engine.headerContent.length;
                var headerSplit = [];
                var splitPos = [];
                var colWidth = this.calculateColWidth(this.engine.pivotValues[0].length);
                do {
                    var columnModel = [];
                    var actualCnt = 0;
                    headerCnt--;
                    var colField = this.engine.headerContent[headerCnt];
                    if (colField) {
                        for (var cCnt = 0; cCnt < Object.keys(colField).length + (colField[0] ? 0 : 1); cCnt++) {
                            var colSpan = (colField[cCnt] && colField[cCnt].colSpan) ? colField[cCnt].colSpan : 1;
                            var rowSpan = (colField[cCnt] && colField[cCnt].rowSpan) ? colField[cCnt].rowSpan : 1;
                            var formattedText = colField[cCnt] ?
                                (colField[cCnt].type === 'grand sum' ? this.parent.localeObj.getConstant('grandTotal') :
                                    (colField[cCnt].type === 'sum' ?
                                        colField[cCnt].formattedText.split('Total')[0] + this.parent.localeObj.getConstant('total') :
                                        colField[cCnt].formattedText)) : '';
                            if (headerCnt === this.engine.headerContent.length - 1) {
                                columnModel[actualCnt] = {
                                    field: (cCnt + '.formattedText'),
                                    headerText: formattedText,
                                    customAttributes: { 'cell': colField[cCnt] },
                                    width: colField[cCnt] ? this.setSavedWidth(colField[cCnt].valueSort.levelName, colWidth) : this.resColWidth,
                                    minWidth: 30,
                                    format: cCnt === 0 ? '' : this.formatList[(cCnt - 1) % this.parent.dataSourceSettings.values.length],
                                    allowReordering: this.parent.gridSettings.allowReordering,
                                    allowResizing: this.parent.gridSettings.allowResizing,
                                    visible: true
                                };
                            }
                            else Eif (headerSplit[cCnt]) {
                                var tmpSpan = colSpan;
                                var innerModel = [];
                                var innerPos = cCnt;
                                while (tmpSpan > 0) {
                                    if (columnModel[actualCnt]) {
                                        Iif (!integrateModel[splitPos[innerPos]]) {
                                            break;
                                        }
                                        innerModel.push(integrateModel[splitPos[innerPos]]);
                                    }
                                    else {
                                        columnModel[actualCnt] = {
                                            headerText: formattedText,
                                            customAttributes: { 'cell': colField[cCnt] },
                                            width: colField[cCnt] ? this.setSavedWidth(colField[cCnt].valueSort.levelName, colWidth) : this.resColWidth,
                                            minWidth: 30,
                                            allowReordering: this.parent.gridSettings.allowReordering,
                                            allowResizing: this.parent.gridSettings.allowResizing,
                                            visible: true
                                        };
                                        innerModel = [integrateModel[splitPos[innerPos]]];
                                    }
                                    tmpSpan = tmpSpan - headerSplit[innerPos];
                                    innerPos = innerPos + headerSplit[innerPos];
                                }
                                columnModel[actualCnt].columns = innerModel;
                            }
                            Eif (columnModel[actualCnt]) {
                                columnModel[actualCnt].clipMode = this.gridSettings.clipMode;
                            }
                            headerSplit[cCnt] = colSpan;
                            splitPos[cCnt] = actualCnt;
                            actualCnt++;
                            cCnt = cCnt + colSpan - 1;
                        }
                    }
                    integrateModel = columnModel.length > 0 ? columnModel : integrateModel;
                } while (headerCnt > 0);
                integrateModel[0] = {
                    field: (0 + '.formattedText'),
                    width: this.resColWidth,
                    minWidth: 30,
                    headerText: '',
                    allowReordering: false,
                    allowResizing: this.parent.gridSettings.allowResizing,
                    visible: true
                };
            }
            else {
                integrateModel = this.frameEmptyColumns();
            }
            if (integrateModel.length > 1) {
                integrateModel[integrateModel.length - 1].minWidth = integrateModel[integrateModel.length - 1].width;
                integrateModel[integrateModel.length - 1].width = 'auto';
            }
            this.parent.triggerColumnRenderEvent(integrateModel);
            return integrateModel;
        };
        Render.prototype.setSavedWidth = function (column, width) {
            width = this.parent.resizeInfo[column] ? this.parent.resizeInfo[column] : width;
            return width;
        };
        Render.prototype.frameEmptyColumns = function () {
            var columns = [];
            var colWidth = this.calculateColWidth(2);
            columns.push({ field: '0.formattedText', headerText: '', minWidth: 30, width: this.resColWidth });
            columns.push({ field: '1.formattedText', headerText: this.parent.localeObj.getConstant('grandTotal'), minWidth: 30, width: colWidth });
            return columns;
        };
        Render.prototype.getFormatList = function () {
            var formatArray = [];
            for (var vCnt = 0; vCnt < this.parent.dataSourceSettings.values.length; vCnt++) {
                var field = this.parent.dataSourceSettings.values[vCnt];
                if (this.parent.dataSourceSettings.formatSettings.length > 0) {
                    var format = '';
                    for (var fCnt = 0; fCnt < this.parent.dataSourceSettings.formatSettings.length; fCnt++) {
                        var formatSettings = this.parent.dataSourceSettings.formatSettings[fCnt];
                        if (field.name === formatSettings.name) {
                            format = formatSettings.format;
                            break;
                        }
                        else {
                            continue;
                        }
                    }
                    formatArray.push(format);
                }
                else {
                    formatArray.push('N');
                }
            }
            return formatArray;
        };
        Render.prototype.excelColumnEvent = function (args) {
            args = this.exportHeaderEvent(args);
            this.parent.trigger(events.excelHeaderQueryCellInfo, args);
        };
        Render.prototype.pdfColumnEvent = function (args) {
            args = this.exportHeaderEvent(args);
            this.parent.trigger(events.pdfHeaderQueryCellInfo, args);
        };
        Render.prototype.excelRowEvent = function (args) {
            if (args.column.field === '0.formattedText') {
                var isValueCell = args.data[0].type === 'value';
                var level = isValueCell ? (this.lastSpan + 1) : args.data[0].level;
                this.colPos = 0;
                args.style = { hAlign: 'Left', indent: level * 2 };
                this.lastSpan = isValueCell ? this.lastSpan : level;
            }
            else {
                this.colPos++;
                args.value = args.data[this.colPos].value || args.data[this.colPos].formattedText;
            }
            args = this.exportContentEvent(args);
            this.parent.trigger(events.excelQueryCellInfo, args);
        };
        Render.prototype.pdfRowEvent = function (args) {
            args = this.exportContentEvent(args);
            if (args.column.field === '0.formattedText') {
                var isValueCell = args.data[0].type === 'value';
                var level = isValueCell ? (this.lastSpan + 1) : args.data[0].level;
                args.style = { paragraphIndent: level * 10 };
                this.lastSpan = isValueCell ? this.lastSpan : level;
            }
            this.parent.trigger(events.pdfQueryCellInfo, args);
        };
        Render.prototype.exportHeaderEvent = function (args) {
            var rowSpan = 1;
            if (args.gridCell.column.customAttributes) {
                var cell = args.gridCell.column.customAttributes.cell;
                rowSpan = cell.rowSpan ? cell.rowSpan : 1;
            }
            else {
                rowSpan = Object.keys(this.engine.headerContent).length;
            }
            if (args.cell.rowSpan && args.cell.rowSpan !== rowSpan && rowSpan > -1) {
                args.cell.rowSpan = rowSpan;
            }
            return args;
        };
        Render.prototype.exportContentEvent = function (args) {
            args.value = args.data[Number(args.column.field.split('.formattedText')[0])].type === 'grand sum' ?
                this.parent.localeObj.getConstant('grandTotal') : args.value;
            return args;
        };
        Render.prototype.unWireEvents = function (cell) {
            if (cell.querySelector('.e-hyperlinkcell')) {
                ej2_base_1.EventHandler.remove(cell.querySelector('.e-hyperlinkcell'), this.parent.isAdaptive ? 'touchend' : 'click', this.onHyperCellClick);
            }
            else {
                return;
            }
        };
        Render.prototype.wireEvents = function (cell) {
            if (cell.querySelector('.e-hyperlinkcell')) {
                ej2_base_1.EventHandler.add(cell.querySelector('.e-hyperlinkcell'), this.parent.isAdaptive ? 'touchend' : 'click', this.onHyperCellClick, this);
            }
            else {
                return;
            }
        };
        return Render;
    }());
    exports.Render = Render;
});