all files / spreadsheet/actions/ show-hide.js

92.36% Statements 556/602
86.1% Branches 446/518
95.65% Functions 22/23
92.47% Lines 553/598
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   885× 885×   1061× 1061× 1061× 1061×       1061×         1061× 1061× 33× 33× 33× 33×     33×   1061× 1065× 84× 84×       981× 981× 30×       1061× 1061×         1052×   1061× 33× 33× 33×     33× 33× 33× 33× 46× 46× 12× 12×     33× 48× 48× 12× 12×       1032× 1032× 1032× 1032× 1032× 1032× 1032× 1032× 1032× 1032× 1032× 1032× 1032× 26×     26×     26×   1032× 1032× 552× 552× 552× 552× 552× 552× 552× 763× 83×     83×   680× 469×     466× 466×   469× 469×   680× 680× 428×   680× 252×   680× 680× 252×   680× 23×   657× 24×   657× 657× 249×   657× 657× 552× 552× 5453× 5453×   12× 12×       552× 12×   540× 540×   540× 540× 540× 540× 429× 429× 429×   429× 19552× 19552×                       105×     103×       552×   551× 12×     10× 10×         12×   539× 106×   433× 433× 433× 431× 431×       426× 425×   426× 423×         433× 410× 410× 410×           408× 408× 408× 408× 408× 408×                           407× 407× 407× 407× 407×     406×   407×     432×     480× 480× 480× 480× 480× 480× 480× 480× 480× 480× 480× 480× 480× 480× 480×                       480× 480× 1226× 648× 333×   315× 171×     144×   315×   578× 51× 51×   527× 527× 295×   527× 103× 103×     103×   424× 146×   424× 424× 23×   401×   401× 401× 140× 140× 140× 140×     139× 139× 139×     140×   401× 401× 401× 401× 304×   401× 401× 304× 304×               401× 23136× 23136×                 147× 147× 147×   140× 139×     138×   138×   138× 138×       139× 139× 139× 139× 137× 137× 125×   137×   137× 12×     125× 124×       139× 137× 137× 5956× 5956×                                   139×   137×   137×     136× 136× 136×           136× 136× 136×           136× 136×   136× 136× 51× 51×         84× 84× 84× 84× 84× 84× 84× 84× 84× 84× 84× 84× 190× 18×   172× 172× 172× 172× 172× 172×         169× 169×     84×   83×   75× 75× 75× 75× 67× 67× 63×       67×     63× 63×   67×   75× 45×     45×   44×   45× 39×     37× 37× 37× 37×     37×                       35× 34× 34× 34×                   41×     30×     27×     23× 23× 21×   23×           44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44× 44×   44× 2453× 18× 18×   2435× 2435× 4803× 70× 70× 70×   70×   4803× 4803× 2435× 2435×         4803× 2435× 2435× 2435×           2435× 2435×                 2435×     2433× 2433×     44× 41×   44× 42×     23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 23×   23× 23× 23× 23× 23× 23× 23× 23× 23× 23× 1237×   1234× 1234× 3236× 45× 45× 45× 45× 43×   22×   43× 22×       45× 44× 43× 43× 43×           44× 43× 43× 43×     44× 23× 23×       3236× 3187×   3236× 3236×           3236× 3187×   3236× 3236× 1234× 1234×               3236× 3236×                   1234×     1233× 1233×     23× 23×   1230×   568×   885× 885×   885× 885×   885× 885×        
define(["require", "exports", "../common/index", "../common/index", "../common/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, index_3, index_4, index_5, index_6, index_7, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ShowHide = (function () {
        function ShowHide(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        ShowHide.prototype.hideShow = function (args) {
            var _this = this;
            var sheetIndex = ej2_base_1.isUndefined(args.sheetIndex) ? this.parent.activeSheetIndex : args.sheetIndex;
            var sheet = index_4.getSheet(this.parent, sheetIndex);
            Iif (index_1.isReadOnlyCells(this.parent, index_6.getRangeIndexes(this.parent.getActiveSheet().selectedRange))) {
                this.parent.notify(index_1.readonlyAlert, null);
                return;
            }
            Iif (args.startIndex > args.endIndex) {
                var temp = args.startIndex;
                args.startIndex = args.endIndex;
                args.endIndex = temp;
            }
            var actionArgs;
            if (args.actionUpdate) {
                args.sheetIndex = sheetIndex;
                actionArgs = { eventArgs: args, action: 'hideShow' };
                this.parent.notify(index_5.beginAction, actionArgs);
                Iif (args.cancel) {
                    return;
                }
                delete args.cancel;
            }
            var performHideShow = function (updateViewport) {
                if (args.isCol) {
                    _this.hideCol(args);
                    if (updateViewport) {
                        _this.parent.sheetModule.colWidthChanged({ colIdx: args.startIndex, isHideShow: true });
                    }
                }
                else {
                    _this.hideRow(args);
                    if (updateViewport) {
                        _this.parent.sheetModule.rowHeightChanged({ rowIdx: args.startIndex, isHideShow: true });
                    }
                }
            };
            var freezePane = args.isCol ? this.parent.frozenColCount(sheet) : this.parent.frozenRowCount(sheet);
            if (freezePane && args.startIndex < freezePane) {
                var endIndex = void 0;
                args.freezePane = true;
                if (args.endIndex >= freezePane) {
                    endIndex = args.endIndex;
                    args.endIndex = freezePane - 1;
                }
                performHideShow(true);
                delete args.freezePane;
                if (endIndex !== undefined) {
                    var startIndex = args.startIndex;
                    args.endIndex = endIndex;
                    args.startIndex = freezePane;
                    performHideShow(!this.parent.scrollSettings.enableVirtualization);
                    args.startIndex = startIndex;
                }
            }
            else {
                performHideShow(!this.parent.scrollSettings.enableVirtualization);
            }
            if (args.actionUpdate) {
                this.updateIndexOnlyForHiddenColumnsAndRows(args, sheet);
                this.parent.notify(index_2.completeAction, actionArgs);
                index_2.focus(this.parent.element);
            }
        };
        ShowHide.prototype.updateIndexOnlyForHiddenColumnsAndRows = function (args, sheet) {
            var startIndex = args.startIndex;
            var endIndex = args.endIndex;
            var model;
            for (var sIdx = args.startIndex; sIdx <= endIndex; sIdx++) {
                model = args.isCol ? index_4.getColumn(sheet, sIdx) : index_4.getRow(sheet, sIdx) || {};
                if (model.hidden === false) {
                    args.startIndex = sIdx;
                    break;
                }
            }
            for (var eIdx = args.endIndex; eIdx >= startIndex; eIdx--) {
                model = args.isCol ? index_4.getColumn(sheet, eIdx) : index_4.getRow(sheet, eIdx) || {};
                if (model.hidden === false) {
                    args.endIndex = eIdx;
                    break;
                }
            }
        };
        ShowHide.prototype.hideRow = function (eventArgs) {
            var _this = this;
            var sheetIndex = ej2_base_1.isUndefined(eventArgs.sheetIndex) ? this.parent.activeSheetIndex : eventArgs.sheetIndex;
            var sheet = index_4.getSheet(this.parent, sheetIndex);
            var cell;
            var count = 0;
            var idx;
            var nextIdx;
            var merge;
            var model;
            var args = Object.assign({}, eventArgs);
            var isFinite = this.parent.scrollSettings.isFinite && !args.freezePane;
            var height;
            if (isFinite) {
                Iif (args.startIndex >= sheet.rowCount) {
                    return;
                }
                Iif (args.endIndex >= sheet.rowCount) {
                    args.endIndex = sheet.rowCount - 1;
                }
                height = 0;
            }
            var frozenRow = this.parent.frozenRowCount(sheet);
            if (args.hide) {
                var content = void 0;
                var rowHdr_1;
                var row = void 0;
                var prevChartIndexes = [];
                var currentChartIndexes = [];
                var updateBtmIdx = isFinite && args.endIndex === index_7.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                for (var i = args.startIndex; i <= args.endIndex; i++) {
                    if (index_4.isHiddenRow(sheet, i)) {
                        Iif (args.isFiltering && !index_7.isFilterHidden(sheet, i)) {
                            index_4.setRow(sheet, i, { isFiltered: true });
                        }
                        continue;
                    }
                    if (idx === undefined) {
                        if (args.freezePane) {
                            rowHdr_1 = this.parent.sheetModule.getSelectAllTable();
                            content = this.parent.getColHeaderTable();
                        }
                        else {
                            rowHdr_1 = this.parent.getRowHeaderTable();
                            content = this.parent.getContentTable();
                        }
                        idx = this.parent.getViewportIndex(i);
                        count = 0;
                    }
                    model = { hidden: true };
                    if (args.isFiltering) {
                        model.isFiltered = true;
                    }
                    if (!args.isFiltering) {
                        prevChartIndexes = index_1.getChartsIndexes(this.parent);
                    }
                    index_4.setRow(sheet, i, model);
                    if (!args.isFiltering) {
                        currentChartIndexes = index_1.getChartsIndexes(this.parent);
                    }
                    if (sheetIndex !== this.parent.activeSheetIndex) {
                        continue;
                    }
                    if (isFinite) {
                        height += index_6.getRowHeight(sheet, i, true, true);
                    }
                    this.refreshChart(i, 'rows');
                    if (!args.isFiltering) {
                        this.refreshChartCellModel(prevChartIndexes, currentChartIndexes);
                    }
                    row = content && content.rows[idx];
                    if (row) {
                        Eif (!merge) {
                            for (var j = 0; j <= sheet.usedRange.colIndex; j++) {
                                cell = index_4.getCell(i, j, sheet) || {};
                                if ((cell.colSpan || cell.rowSpan) && (args.startIndex >= this.parent.viewport.topIndex ||
                                    this.parent.scrollSettings.enableVirtualization)) {
                                    merge = true;
                                    break;
                                }
                            }
                        }
                        if (merge) {
                            continue;
                        }
                        Eif (rowHdr_1.rows[idx]) {
                            ej2_base_1.detach(rowHdr_1.rows[idx]);
                        }
                        ej2_base_1.detach(row);
                        count++;
                        row = content.rows[idx];
                        if (row && i === args.endIndex) {
                            var cell_1 = void 0;
                            nextIdx = index_7.skipHiddenIdx(sheet, i + 1, true);
                            var first = nextIdx !== index_7.skipHiddenIdx(sheet, 0, true) && nextIdx ===
                                (this.parent.viewport.topIndex >= args.startIndex ? args.endIndex + 1 : this.parent.viewport.topIndex) ? 'Row' : '';
                            for (var j = this.parent.viewport.leftIndex; j <= this.parent.viewport.rightIndex; j++) {
                                var borderTop = this.parent.getCellStyleValue(['borderTop'], [nextIdx, j]).borderTop;
                                Iif (borderTop !== '') {
                                    cell_1 = row.cells[j];
                                    this.parent.notify(index_5.applyCellFormat, {
                                        onActionUpdate: false, rowIdx: nextIdx, colIdx: j,
                                        style: { borderTop: borderTop }, row: row, pRow: row.previousElementSibling,
                                        first: first, td: cell_1
                                    });
                                }
                            }
                        }
                    }
                    else {
                        if (i <= this.parent.viewport.bottomIndex) {
                            count++;
                        }
                        else {
                            count--;
                        }
                    }
                }
                if (args.refreshUI) {
                    return;
                }
                if (merge && (args.startIndex >= this.parent.viewport.topIndex || !this.parent.scrollSettings.enableVirtualization)) {
                    if (args.isFiltering) {
                        eventArgs.refreshUI = true;
                    }
                    else {
                        this.parent.selectRange(sheet.selectedRange);
                        if (sheet.frozenRows || sheet.frozenColumns) {
                            this.parent.renderModule.refreshSheet(false, false, true);
                            eventArgs.refreshUI = true;
                        }
                        else {
                            this.parent.renderModule.refreshUI({ rowIndex: this.parent.viewport.topIndex, colIndex: this.parent.viewport.leftIndex, refresh: 'Row' });
                        }
                    }
                    return;
                }
                if (!count) {
                    return;
                }
                this.parent.selectRange(sheet.selectedRange);
                var updateHideClass = function () {
                    if (sheet.showHeaders) {
                        var firstIdx = args.freezePane ? 1 : 0;
                        if (idx === firstIdx) {
                            Eif (rowHdr_1.rows[firstIdx]) {
                                rowHdr_1.rows[firstIdx].classList.add('e-hide-end');
                            }
                        }
                        else {
                            if (rowHdr_1 && rowHdr_1.rows[idx - 1]) {
                                rowHdr_1.rows[idx - 1].classList.add('e-hide-start');
                            }
                            if (rowHdr_1 && rowHdr_1.rows[idx]) {
                                rowHdr_1.rows[idx].classList.add('e-hide-end');
                            }
                        }
                    }
                };
                if (!args.freezePane && this.parent.scrollSettings.enableVirtualization) {
                    var startIndex = args.startIndex;
                    var endIndex = args.startIndex;
                    if (args.startIndex < index_5.getCellIndexes(sheet.paneTopLeftCell)[0] || count > this.parent.viewport.rowCount) {
                        Iif (args.isFiltering) {
                            eventArgs.refreshUI = true;
                            return;
                        }
                        this.parent.updateTopLeftCell(index_7.skipHiddenIdx(sheet, args.startIndex - 1 < frozenRow ? frozenRow : args.startIndex - 1, true) - frozenRow, null, 'col');
                        this.parent.renderModule.refreshSheet(false, false, true);
                    }
                    else {
                        startIndex = this.parent.viewport.bottomIndex + 1;
                        endIndex = startIndex + count - 1;
                        var indexes = this.parent.skipHidden(startIndex, endIndex, 'rows', false);
                        startIndex = indexes[0];
                        endIndex = indexes[1];
                        if (isFinite) {
                            if (startIndex >= sheet.rowCount) {
                                Eif (this.parent.viewport.topIndex + frozenRow === index_7.skipHiddenIdx(sheet, frozenRow, true)) {
                                    updateHideClass();
                                    this.parent.notify(index_3.updateTranslate, { isHide: true, height: height });
                                    Iif (updateBtmIdx) {
                                        this.parent.viewport.bottomIndex = index_7.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                                    }
                                }
                                else {
                                    this.parent.renderModule.refreshSheet(false, false, true);
                                }
                                return;
                            }
                            else Iif (endIndex >= sheet.rowCount) {
                                this.parent.renderModule.refreshSheet(false, false, true);
                                return;
                            }
                            else {
                                this.parent.notify(index_3.updateTranslate, { isHide: true, height: height });
                            }
                        }
                        this.parent.viewport.bottomIndex = endIndex;
                        var colIndex = void 0;
                        var frozenCol = this.parent.frozenColCount(sheet);
                        var frozenIdxes = [];
                        if (frozenCol) {
                            frozenIdxes.push(frozenRow);
                            frozenIdxes.push(this.parent.viewport.leftIndex + frozenCol);
                            colIndex = index_5.getCellIndexes(sheet.topLeftCell)[1];
                        }
                        else {
                            colIndex = this.parent.viewport.leftIndex;
                        }
                        this.parent.renderModule.refreshUI({ colIndex: colIndex, rowIndex: startIndex, direction: '', refresh: 'RowPart', frozenIndexes: frozenIdxes }, index_4.getCellAddress(startIndex, colIndex) + ":" + index_4.getCellAddress(endIndex, this.parent.viewport.rightIndex));
                    }
                }
                updateHideClass();
            }
            else {
                var hFrag = void 0;
                var frag = void 0;
                var hRow = void 0;
                var row = void 0;
                var newStartRow = void 0;
                var rowRenderer = void 0;
                var content = void 0;
                var rowHdr = void 0;
                var startRow = void 0;
                var endRow = args.startIndex - 1;
                var mergeCollection = [];
                var skipDetach = args.freezePane;
                var direction = 'lastElementChild';
                var detachedHeight = 0;
                if (isFinite) {
                    var lastIdx = index_7.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                    if (this.parent.viewport.bottomIndex === lastIdx) {
                        Eif (this.parent.viewport.topIndex + frozenRow === index_7.skipHiddenIdx(sheet, frozenRow, true)) {
                            skipDetach = true;
                        }
                        else {
                            var topLeftCell = index_6.getRangeIndexes(sheet.paneTopLeftCell)[0];
                            var count_1 = (((sheet.rowCount - 1) - topLeftCell) + 1) -
                                this.parent.hiddenCount(topLeftCell, sheet.rowCount - 1);
                            if (count_1 < this.parent.viewport.rowCount + Math.round(this.parent.getThreshold('row') / 2)) {
                                direction = 'firstElementChild';
                            }
                        }
                    }
                }
                var prevChartIndexes = index_1.getChartsIndexes(this.parent);
                for (var i = args.startIndex, len = args.endIndex; i <= len; i++) {
                    if (!index_4.isHiddenRow(sheet, i)) {
                        if (args.startIndex === args.endIndex) {
                            return;
                        }
                        if (idx === undefined) {
                            endRow++;
                        }
                        else {
                            newStartRow = i;
                        }
                        continue;
                    }
                    if (newStartRow !== undefined) {
                        len = i;
                        continue;
                    }
                    model = { hidden: false };
                    if (args.isFiltering) {
                        model.isFiltered = false;
                    }
                    if (!skipDetach && i > this.parent.viewport.bottomIndex) {
                        index_4.setRow(sheet, i, model);
                        Iif (startRow === undefined) {
                            return;
                        }
                        continue;
                    }
                    if (startRow === undefined) {
                        startRow = i;
                    }
                    index_4.setRow(sheet, i, model);
                    if (sheetIndex !== this.parent.activeSheetIndex) {
                        continue;
                    }
                    if (isFinite) {
                        height += index_6.getRowHeight(sheet, i, true, true);
                    }
                    this.refreshChart(i, 'rows');
                    if (idx === undefined) {
                        hFrag = document.createDocumentFragment();
                        frag = document.createDocumentFragment();
                        rowRenderer = this.parent.serviceLocator.getService('row');
                        if (args.freezePane) {
                            rowHdr = this.parent.sheetModule.getSelectAllTable();
                            content = this.parent.getColHeaderTable();
                        }
                        else {
                            rowHdr = this.parent.getRowHeaderTable();
                            content = this.parent.getContentTable();
                            if (i < this.parent.viewport.topIndex + frozenRow) {
                                this.parent.viewport.topIndex = i - frozenRow;
                            }
                        }
                        idx = this.parent.getViewportIndex(i);
                    }
                    endRow++;
                    hRow = rowRenderer.refresh(i, null, null, true, true);
                    hFrag.appendChild(hRow);
                    if (rowHdr && rowHdr.rows.length && !skipDetach) {
                        ej2_base_1.detach(rowHdr.tBodies[0]["" + direction]);
                    }
                    row = frag.appendChild(rowRenderer.refresh(i, row, hRow));
                    if (content && content.rows.length && !skipDetach) {
                        ej2_base_1.detach(content.tBodies[0]["" + direction]);
                        Iif (direction === 'firstElementChild') {
                            if (idx !== undefined && idx - 1 > -1) {
                                idx -= 1;
                            }
                            detachedHeight += index_6.getRowHeight(sheet, this.parent.viewport.topIndex, true);
                            this.parent.viewport.topIndex = index_7.skipHiddenIdx(sheet, this.parent.viewport.topIndex + 1, true);
                        }
                    }
                    for (var j = this.parent.viewport.leftIndex; j <= this.parent.viewport.rightIndex; j++) {
                        cell = index_4.getCell(i, j, sheet) || {};
                        if (cell.rowSpan !== undefined || cell.colSpan !== undefined) {
                            var mergeArgs = {
                                range: [i, j, i, j], isAction: false, merge: true,
                                type: 'All', skipChecking: true
                            };
                            this.parent.notify(index_6.activeCellMergedRange, mergeArgs);
                            if (!mergeCollection.length || mergeArgs.range[1] !== mergeCollection[mergeCollection.length - 1].range[1] ||
                                mergeArgs.range[0] !== mergeCollection[mergeCollection.length - 1].range[0]) {
                                mergeCollection.push(mergeArgs);
                            }
                        }
                    }
                }
                var currentChartIndexes = index_1.getChartsIndexes(this.parent);
                this.refreshChartCellModel(prevChartIndexes, currentChartIndexes);
                if (idx === undefined) {
                    return;
                }
                if (!args.freezePane) {
                    if (args.isFiltering && args.startIndex < index_5.getCellIndexes(sheet.paneTopLeftCell)[0]) {
                        eventArgs.refreshUI = true;
                        Eif (newStartRow === undefined || newStartRow === args.endIndex) {
                            return;
                        }
                    }
                    this.parent.viewport.bottomIndex = this.parent.viewport.topIndex + frozenRow + this.parent.viewport.rowCount +
                        (this.parent.getThreshold('row') * 2);
                    count = this.parent.hiddenCount(this.parent.viewport.topIndex + frozenRow, args.startIndex) +
                        this.parent.hiddenCount(args.endIndex + 1, this.parent.viewport.bottomIndex);
                    this.parent.viewport.bottomIndex += count;
                    Iif (isFinite && this.parent.viewport.bottomIndex >= sheet.rowCount) {
                        this.parent.viewport.bottomIndex = index_7.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                    }
                }
                args.insertIdx = eventArgs.insertIdx = idx;
                args.row = eventArgs.row = frag.querySelector('.e-row');
                args.mergeCollection = eventArgs.mergeCollection = mergeCollection;
                if (sheet.showHeaders) {
                    eventArgs.hdrRow = args.hdrRow = hFrag.querySelector('.e-row');
                    if (idx !== 0 && !index_4.isHiddenRow(sheet, endRow - 1) && rowHdr.rows[idx - 1]) {
                        rowHdr.rows[idx - 1].classList.remove('e-hide-start');
                    }
                    if (args.startIndex !== 0 && index_4.isHiddenRow(sheet, args.startIndex - 1)) {
                        args.hdrRow.classList.add('e-hide-end');
                    }
                    if (index_4.isHiddenRow(sheet, endRow + 1)) {
                        hFrag.lastElementChild.classList.add('e-hide-start');
                    }
                    else {
                        if (rowHdr.rows[idx]) {
                            rowHdr.rows[idx].classList.remove('e-hide-end');
                        }
                    }
                }
                if (row && content && content.rows[idx]) {
                    nextIdx = index_7.skipHiddenIdx(sheet, endRow + 1, true);
                    for (var i = this.parent.viewport.leftIndex; i <= this.parent.viewport.rightIndex; i++) {
                        var borderTop = this.parent.getCellStyleValue(['borderTop'], [nextIdx, i]).borderTop;
                        Iif (borderTop !== '') {
                            this.parent.notify(index_5.applyCellFormat, {
                                onActionUpdate: false, rowIdx: nextIdx, colIdx: i, style: { borderTop: borderTop }, pRow: row,
                                td: content.rows[idx].cells[i], first: ''
                            });
                            var prevIdx = index_7.skipHiddenIdx(sheet, startRow - 1, false);
                            if (prevIdx > -1) {
                                if (content.rows[idx - 1] && !this.parent.getCellStyleValue(['borderBottom'], [prevIdx, i]).borderBottom &&
                                    !this.parent.getCellStyleValue(['borderTop'], [startRow, i]).borderTop) {
                                    content.rows[idx - 1].cells[i].style.borderBottom = '';
                                }
                            }
                            else {
                                content.rows[idx].cells[i].style.borderTop = '';
                            }
                        }
                    }
                }
                if (args.skipAppend) {
                    return;
                }
                if (isFinite) {
                    this.parent.notify(index_3.updateTranslate, { height: height, size: detachedHeight });
                }
                if (Math.abs(endRow - startRow) > this.parent.viewport.rowCount + (this.parent.getThreshold('row') * 2)) {
                    this.parent.renderModule.refreshSheet(false, false, true);
                }
                else {
                    Eif (rowHdr) {
                        Eif (rowHdr.tBodies[0].rows.length) {
                            rowHdr.tBodies[0].insertBefore(hFrag, rowHdr.rows[idx]);
                        }
                        else {
                            rowHdr.tBodies[0].appendChild(hFrag);
                        }
                    }
                    Eif (content && content.tBodies[0]) {
                        Eif (content.tBodies[0].rows.length) {
                            content.tBodies[0].insertBefore(frag, content.rows[idx]);
                        }
                        else {
                            content.tBodies[0].appendChild(frag);
                        }
                    }
                    this.parent.selectRange(sheet.selectedRange);
                    if (args.autoFit && sheet.showHeaders) {
                        this.parent.notify(index_2.autoFit, { startIndex: args.startIndex, endIndex: args.endIndex, isRow: true });
                    }
                    mergeCollection.forEach(function (mergeArgs) { _this.parent.notify(index_6.setMerge, mergeArgs); });
                    if (newStartRow !== undefined && newStartRow !== args.endIndex) {
                        args.startIndex = newStartRow;
                        this.hideRow(args);
                    }
                }
            }
        };
        ShowHide.prototype.hideCol = function (args) {
            var _this = this;
            var sheetIndex = ej2_base_1.isUndefined(args.sheetIndex) ? this.parent.activeSheetIndex : args.sheetIndex;
            var sheet = index_4.getSheet(this.parent, sheetIndex);
            var hiddenIndex = [];
            var beforeViewportIdx = [];
            var paneTopLeftIdx = index_5.getCellIndexes(sheet.paneTopLeftCell);
            var frozenCol = this.parent.frozenColCount(sheet);
            var frozenRow = this.parent.frozenRowCount(sheet);
            var viewportLeftIdx = this.parent.viewport.leftIndex + frozenCol;
            var scrollable;
            var skipColCount = index_7.skipHiddenIdx(sheet, sheet.colCount - 1, false, 'columns');
            for (var i = args.startIndex; i <= args.endIndex; i++) {
                if (args.hide ? index_4.isHiddenCol(sheet, i) : !index_4.isHiddenCol(sheet, i)) {
                    continue;
                }
                var prevChartIndexes = index_1.getChartsIndexes(this.parent);
                index_4.setColumn(sheet, i, { hidden: args.hide });
                var currentChartIndexes = index_1.getChartsIndexes(this.parent);
                this.refreshChart(i, 'columns');
                this.refreshChartCellModel(prevChartIndexes, currentChartIndexes);
                if (this.parent.scrollSettings.enableVirtualization && !args.freezePane && (i < viewportLeftIdx ||
                    (i > this.parent.viewport.rightIndex && (!this.parent.scrollSettings.isFinite ||
                        !(skipColCount === this.parent.viewport.rightIndex && i >= skipColCount && i < sheet.colCount))))) {
                    Eif (i < viewportLeftIdx) {
                        beforeViewportIdx.push(i);
                    }
                    continue;
                }
                hiddenIndex.push(i);
                if (args.hide && i <= paneTopLeftIdx[1]) {
                    scrollable = true;
                }
            }
            if (!beforeViewportIdx.length && !hiddenIndex.length) {
                return;
            }
            if (sheetIndex !== this.parent.activeSheetIndex) {
                return;
            }
            var topLeftIdx = index_5.getCellIndexes(sheet.topLeftCell);
            var table;
            var hTable;
            var getRowIndexes = function () {
                var idx;
                if (_this.parent.scrollSettings.enableVirtualization) {
                    idx = [frozenRow ? topLeftIdx[0] : _this.parent.viewport.topIndex, _this.parent.viewport.bottomIndex];
                }
                else {
                    idx = [0, sheet.rowCount - 1];
                }
                if (args.freezePane) {
                    table = _this.parent.getRowHeaderTable();
                    hTable = _this.parent.sheetModule.getSelectAllTable();
                }
                else {
                    table = _this.parent.getContentTable();
                    hTable = _this.parent.getColHeaderTable();
                }
                return idx;
            };
            if (args.hide) {
                Iif (!hiddenIndex.length) {
                    return;
                }
                if (hiddenIndex.length <= this.parent.getThreshold('col') || !this.parent.scrollSettings.enableVirtualization ||
                    args.freezePane) {
                    this.removeCell(sheet, hiddenIndex, getRowIndexes(), table, hTable);
                }
                if (!args.freezePane && this.parent.scrollSettings.enableVirtualization) {
                    if (scrollable) {
                        this.parent.updateTopLeftCell(null, index_7.skipHiddenIdx(sheet, hiddenIndex[0] - 1 < frozenCol ? frozenCol : hiddenIndex[0] - 1, true, 'columns') -
                            frozenCol, 'row');
                        this.parent.renderModule.refreshSheet(false, false, true);
                        return;
                    }
                    var fIndexes = [];
                    var viewportRowIdx = this.parent.viewport.topIndex;
                    var rowIdx = frozenRow ? topLeftIdx[0] : viewportRowIdx;
                    Iif (frozenRow) {
                        fIndexes = [frozenRow + viewportRowIdx, frozenCol];
                    }
                    if (this.parent.scrollSettings.isFinite) {
                        var colCount = index_7.skipHiddenIdx(sheet, sheet.colCount - 1, false, 'columns');
                        var startIdx = this.parent.viewport.leftIndex + frozenCol;
                        var endIndex = this.parent.viewport.rightIndex;
                        Eif (endIndex + hiddenIndex.length >= colCount) {
                            var index = index_7.skipHiddenIdx(sheet, startIdx - ((endIndex + hiddenIndex.length) - colCount), false, 'columns');
                            Iif (index >= frozenCol) {
                                this.parent.viewport.leftIndex = index;
                                this.parent.viewport.leftIndex -= this.parent.hiddenCount(endIndex, colCount);
                            }
                            this.parent.viewport.rightIndex = colCount;
                            if (startIdx !== (this.parent.viewport.leftIndex + frozenCol) || endIndex !== this.parent.viewport.rightIndex) {
                                this.parent.renderModule.refreshUI({ colIndex: this.parent.viewport.leftIndex, refresh: 'Column', frozenIndexes: fIndexes, rowIndex: rowIdx,
                                    skipUpdateOnFirst: this.parent.viewport.leftIndex + frozenCol === index_7.skipHiddenIdx(sheet, frozenCol, true, 'columns') });
                                Iif (frozenRow) {
                                    this.parent.viewport.topIndex = viewportRowIdx;
                                }
                            }
                            else {
                                this.parent.notify(index_3.updateTableWidth, { refresh: 'Column', isUpdate: true });
                            }
                            this.parent.selectRange(sheet.selectedRange);
                            return;
                        }
                    }
                    if (hiddenIndex.length <= this.parent.getThreshold('col')) {
                        var indexes = this.parent.skipHidden(this.parent.viewport.rightIndex + 1, this.parent.viewport.rightIndex + hiddenIndex.length, 'columns');
                        this.parent.viewport.rightIndex = indexes[1];
                        this.parent.renderModule.refreshUI({ rowIndex: rowIdx, colIndex: indexes[0], direction: '', refresh: 'ColumnPart', frozenIndexes: fIndexes }, "" + index_4.getRangeAddress([rowIdx, indexes[0], this.parent.viewport.bottomIndex, indexes[1]]));
                    }
                    else {
                        this.parent.renderModule.refreshUI({
                            skipUpdateOnFirst: this.parent.viewport.leftIndex + frozenCol === index_7.skipHiddenIdx(sheet, frozenCol, true, 'columns'), rowIndex: rowIdx, colIndex: this.parent.viewport.leftIndex,
                            refresh: 'Column', frozenIndexes: fIndexes
                        });
                        Iif (frozenRow) {
                            this.parent.viewport.topIndex = viewportRowIdx;
                        }
                    }
                }
                this.parent.selectRange(sheet.selectedRange);
            }
            else {
                if (beforeViewportIdx.length && this.parent.scrollSettings.enableVirtualization) {
                    beforeViewportIdx.sort(function (i, j) { return i - j; });
                    var leftIdx = beforeViewportIdx[0] - 1 < frozenCol ? frozenCol : beforeViewportIdx[0] - 1;
                    this.parent.updateTopLeftCell(null, index_7.skipHiddenIdx(sheet, leftIdx, true, 'columns') - frozenCol, 'row');
                    this.parent.renderModule.refreshSheet(false, false, true);
                    if (args.autoFit) {
                        args.autoFit = false;
                    }
                    return;
                }
                if ((!this.parent.scrollSettings.isFinite || this.parent.viewport.rightIndex < skipColCount) &&
                    (hiddenIndex.length <= this.parent.getThreshold('col') || !this.parent.scrollSettings.enableVirtualization
                        || args.freezePane)) {
                    this.appendCell(sheet, hiddenIndex, getRowIndexes(), table, hTable, args.freezePane);
                    if (this.parent.scrollSettings.enableVirtualization && !args.freezePane) {
                        this.parent.notify(index_2.virtualContentLoaded, { refresh: 'Column', prevRowColCnt: { rowCount: sheet.rowCount, colCount: sheet.colCount } });
                    }
                    this.parent.selectRange(sheet.selectedRange);
                }
                else {
                    this.parent.renderModule.refreshSheet(false, false, true);
                }
            }
        };
        ShowHide.prototype.removeCell = function (sheet, indexes, rowIdxs, table, hTable) {
            var _this = this;
            var startIdx = rowIdxs[0];
            var endIdx = rowIdxs[1];
            var rowIdx = 0;
            var len = indexes.length - 1;
            var frozenRow = this.parent.frozenRowCount(sheet);
            var colgrp = table.getElementsByTagName('colgroup')[0];
            var cellIdx = this.parent.getViewportIndex(indexes[0], true) + 1;
            var lastFreezeRow = index_7.skipHiddenIdx(sheet, frozenRow - 1, false);
            var hRow;
            var row;
            var hColgrp;
            var cell;
            var nextIdx;
            Eif (sheet.showHeaders) {
                hColgrp = hTable.getElementsByTagName('colgroup')[0];
                hRow = hTable.rows[0];
            }
            while (startIdx <= endIdx) {
                if (index_4.isHiddenRow(sheet, startIdx)) {
                    startIdx++;
                    continue;
                }
                row = frozenRow && startIdx < frozenRow ? hTable.rows[rowIdx + 1] : table.rows[rowIdx];
                indexes.forEach(function (idx, index) {
                    if (rowIdx === 0 && startIdx >= frozenRow) {
                        Eif (sheet.showHeaders) {
                            ej2_base_1.detach(hColgrp.children[cellIdx]);
                            ej2_base_1.detach(hRow.cells[cellIdx]);
                        }
                        ej2_base_1.detach(colgrp.children[cellIdx]);
                    }
                    ej2_base_1.detach(row.cells[cellIdx]);
                    if (index === 0) {
                        cell = index_4.getCell(startIdx, idx, sheet, false, true);
                        if ((cell.colSpan !== undefined && (cell.rowSpan === undefined || cell.colSpan > 1)) || (cell.rowSpan < 0 &&
                            startIdx - 1 > -1 && index_4.isHiddenRow(sheet, startIdx - 1) && Math.abs(cell.rowSpan) ===
                            _this.parent.hiddenCount(startIdx + cell.rowSpan, startIdx, 'rows', sheet))) {
                            _this.parent.notify(index_3.hiddenMerge, { rowIdx: startIdx, colIdx: idx, model: 'col', start: indexes[0], end: indexes[len] });
                        }
                    }
                    if (index === len) {
                        nextIdx = index_7.skipHiddenIdx(sheet, idx + 1, true, 'columns');
                        var borderLeft = _this.parent.getCellStyleValue(['borderLeft'], [rowIdx, nextIdx]).borderLeft;
                        Iif (borderLeft !== '') {
                            _this.parent.notify(index_5.applyCellFormat, {
                                onActionUpdate: false, rowIdx: rowIdx, colIdx: nextIdx,
                                style: { borderLeft: borderLeft }, row: row, first: ''
                            });
                        }
                        cell = index_4.getCell(startIdx, idx, sheet) || {};
                        if ((cell.colSpan !== undefined && (cell.rowSpan === undefined || cell.colSpan > 1)) || (cell.rowSpan < 0 &&
                            startIdx - 1 > -1 && index_4.isHiddenRow(sheet, startIdx - 1) && Math.abs(cell.rowSpan) ===
                            _this.parent.hiddenCount(startIdx + cell.rowSpan, startIdx, 'rows', sheet))) {
                            _this.parent.notify(index_3.hiddenMerge, {
                                rowIdx: startIdx, colIdx: idx, model: 'col',
                                start: indexes[0], end: indexes[len], isEnd: true
                            });
                        }
                    }
                });
                if (frozenRow && startIdx === lastFreezeRow) {
                    rowIdx = 0;
                    startIdx = this.parent.viewport.topIndex + frozenRow;
                }
                else {
                    rowIdx++;
                    startIdx++;
                }
            }
            if (cellIdx - 1 > -1 && sheet.showHeaders && hRow.cells[cellIdx - 1]) {
                hRow.cells[cellIdx - 1].classList.add('e-hide-start');
            }
            if (sheet.showHeaders && hRow.cells[cellIdx]) {
                hRow.cells[cellIdx].classList.add('e-hide-end');
            }
        };
        ShowHide.prototype.appendCell = function (sheet, indexes, rowIdxs, table, hTable, skip) {
            var _this = this;
            var startIdx = rowIdxs[0];
            var endIdx = rowIdxs[1];
            var rowIdx = 0;
            var len = indexes.length - 1;
            var hRow;
            var row;
            var hColgrp;
            var prevIdx;
            var frozenRow = this.parent.frozenRowCount(sheet);
            var colgrp = table.getElementsByTagName('colgroup')[0];
            Eif (sheet.showHeaders) {
                hColgrp = hTable.getElementsByTagName('colgroup')[0];
                hRow = hTable.rows[0];
            }
            var cellRenderer = this.parent.serviceLocator.getService('cell');
            indexes.sort(function (i, j) { return i - j; });
            var mergeCollection = [];
            var cellIdx = [];
            var cell;
            var refCell;
            var cellModel;
            var firstFrozenRow = index_7.skipHiddenIdx(sheet, frozenRow - 1, false);
            var cellArgs;
            while (startIdx <= endIdx) {
                if (index_4.isHiddenRow(sheet, startIdx)) {
                    startIdx++;
                    continue;
                }
                row = frozenRow && startIdx < frozenRow ? hTable.rows[rowIdx + 1] : table.rows[rowIdx];
                indexes.forEach(function (idx, index) {
                    if (rowIdx === 0) {
                        cellIdx[index] = _this.parent.getViewportIndex(idx, true);
                        Eif (sheet.showHeaders) {
                            refCell = hRow.cells[cellIdx[index]];
                            if (refCell) {
                                if (index === 0 && indexes[index] && !index_4.isHiddenCol(sheet, indexes[index] - 1) &&
                                    refCell.previousSibling) {
                                    refCell.previousElementSibling.classList.remove('e-hide-start');
                                }
                                if (index === len) {
                                    refCell.classList.remove('e-hide-end');
                                }
                            }
                        }
                        if (startIdx >= frozenRow) {
                            if (colgrp.children[cellIdx[index]]) {
                                colgrp.insertBefore(_this.parent.sheetModule.updateCol(sheet, idx), colgrp.children[cellIdx[index]]);
                                Eif (sheet.showHeaders) {
                                    cellRenderer.renderColHeader(idx, hRow, refCell);
                                }
                            }
                            else {
                                colgrp.appendChild(_this.parent.sheetModule.updateCol(sheet, idx));
                                Eif (sheet.showHeaders) {
                                    cellRenderer.renderColHeader(idx, hRow);
                                }
                            }
                            if (!skip) {
                                ej2_base_1.detach(colgrp.lastChild);
                                Eif (sheet.showHeaders) {
                                    ej2_base_1.detach(hRow.lastChild);
                                }
                            }
                            if (sheet.showHeaders && index === len) {
                                ej2_base_1.detach(hColgrp);
                                hTable.insertBefore(colgrp.cloneNode(true), hTable.tHead);
                            }
                        }
                    }
                    if (!skip) {
                        ej2_base_1.detach(row.lastChild);
                    }
                    refCell = row.cells[cellIdx[index]];
                    cellArgs = {
                        rowIdx: startIdx, colIdx: idx, cell: index_4.getCell(startIdx, idx, sheet), row: row,
                        address: index_4.getCellAddress(startIdx, idx), lastCell: idx === len, isHeightCheckNeeded: true,
                        first: idx !== index_7.skipHiddenIdx(sheet, 0, true, 'columns') && idx === _this.parent.viewport.leftIndex ? 'Column' : '',
                        checkNextBorder: index === len ? 'Column' : '', checkCF: true
                    };
                    if (refCell) {
                        cellArgs.refChild = refCell;
                    }
                    cell = cellRenderer.render(cellArgs);
                    if (index === 0 && cell.previousSibling) {
                        var borderLeft = _this.parent.getCellStyleValue(['borderLeft'], [rowIdx, index_7.skipHiddenIdx(sheet, indexes[indexes.length - 1] + 1, true, 'columns')]).borderLeft;
                        Iif (borderLeft !== '') {
                            prevIdx = index_7.skipHiddenIdx(sheet, indexes[0] - 1, false, 'columns');
                            if (prevIdx > -1 && !_this.parent.getCellStyleValue(['borderRight'], [rowIdx, prevIdx]).borderRight &&
                                !_this.parent.getCellStyleValue(['borderLeft'], [rowIdx, indexes[0]]).borderLeft) {
                                cell.previousSibling.style.borderRight = '';
                            }
                        }
                    }
                    cellModel = index_4.getCell(startIdx, idx, sheet) || {};
                    if ((cellModel.colSpan !== undefined && (cellModel.rowSpan === undefined || cellModel.colSpan > 1)) ||
                        (cellModel.rowSpan < 0 && startIdx - 1 > -1 && index_4.isHiddenRow(sheet, startIdx - 1) &&
                            Math.abs(cellModel.rowSpan) === _this.parent.hiddenCount(startIdx + cellModel.rowSpan, startIdx, 'rows', sheet))) {
                        var mergeArgs = {
                            range: [startIdx, idx, startIdx, idx], isAction: false, merge: true,
                            type: 'All', skipChecking: true
                        };
                        _this.parent.notify(index_6.activeCellMergedRange, mergeArgs);
                        Eif (!mergeCollection.length || mergeArgs.range[1] !== mergeCollection[mergeCollection.length - 1].range[1] ||
                            mergeArgs.range[0] !== mergeCollection[mergeCollection.length - 1].range[0]) {
                            mergeCollection.push(mergeArgs);
                        }
                    }
                });
                if (frozenRow && startIdx === firstFrozenRow) {
                    startIdx = this.parent.viewport.topIndex + frozenRow;
                    rowIdx = 0;
                }
                else {
                    startIdx++;
                    rowIdx++;
                }
            }
            mergeCollection.forEach(function (mergeArgs) { _this.parent.notify(index_6.setMerge, mergeArgs); });
            this.parent.viewport.rightIndex = index_7.skipHiddenIdx(sheet, this.parent.viewport.rightIndex - indexes.length, false, 'columns');
        };
        ShowHide.prototype.refreshChart = function (index, showHide) {
            this.parent.notify(index_5.refreshChart, { rIdx: index, showHide: showHide });
        };
        ShowHide.prototype.refreshChartCellModel = function (prevChartIndexes, currentChartIndexes) {
            this.parent.notify(index_1.refreshChartCellModel, { prevChartIndexes: prevChartIndexes, currentChartIndexes: currentChartIndexes });
        };
        ShowHide.prototype.addEventListener = function () {
            this.parent.on(index_6.hideShow, this.hideShow, this);
            this.parent.on(index_1.spreadsheetDestroyed, this.destroy, this);
        };
        ShowHide.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        ShowHide.prototype.removeEventListener = function () {
            this.parent.off(index_6.hideShow, this.hideShow);
            this.parent.off(index_1.spreadsheetDestroyed, this.destroy);
        };
        return ShowHide;
    }());
    exports.ShowHide = ShowHide;
});