all files / grid/renderer/ header-renderer.js

96.38% Statements 426/442
91.91% Branches 318/346
100% Functions 43/43
96.35% Lines 422/438
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 6511×   1× 1× 1× 1784× 1784× 1784× 1784× 1784× 1784× 15× 15× 15× 15×   1×   14× 14× 14× 1×   13× 13× 13× 13× 13× 13× 1×   13× 13×     13×   13× 1× 1× 1× 1× 1×   1×     1×         1× 1×       12×     13× 13× 13× 13× 13×   1784× 12× 12× 12×   1784× 7× 7× 7× 6× 6× 6×                   6×     1784× 7× 7× 7× 7×     1× 1×   7×   1784× 6× 6× 6× 6× 6×       6×   1784× 1784× 1784× 1784× 1784×     1784× 1692×   1784× 1784× 1784× 18×     1× 1737× 1737× 1737× 1737×   1737× 1737× 1737× 1737× 1733×     1× 1740× 1740× 1740× 1740× 1740× 1740×   1× 52102×   1× 1738×   1× 33315×   1× 1741×   1× 83×   1× 2442×   1× 1× 1×   1× 1740× 1740× 1740× 1740×   1× 1742× 1742× 1742× 5×   1742× 1742× 1742× 1742× 1742×     1742× 1742× 1742×   1742× 1742× 1742× 1792× 8484× 8484×     1742× 647×   1742× 1742× 1742× 1742× 1742× 1742× 1742×   1× 1741× 1741×   1× 2444× 2444× 2444× 2444× 2444× 2444× 2444× 2444× 2444× 2444× 2532× 2532×   2444× 2444× 2444× 2× 3×     11580× 2444× 2×   2444× 119× 118×       2325× 2324×     2444× 2532× 2532× 12×   2532× 2532×   2444× 2444× 128× 6× 6×   122×           2444×       2444×   1× 2442× 2442× 2442× 2442× 2442× 746× 592× 1×   591× 591×     2442× 114× 114×   2442× 60× 60×   2442× 11572× 11572× 807×   11572×   2442× 2× 2×   2442×   1× 2445× 2445× 2445× 2533× 2533× 773× 607× 1×   606× 606× 28×   606×     2533× 114× 114× 114× 114×     114×   2533× 60× 60×     60×     2445×   1× 2444× 2444×   2444× 2444× 2444× 5× 25× 25×     2444× 11388× 11388× 11388×   2444×   1× 11801× 11801×   11801× 11612× 11584×   11612× 57×   6×     51×       11555×       189× 189× 189× 176× 176×     176× 170×             189× 6× 9×     189× 183× 378× 378×   378× 378×       11801×   1× 606× 222× 429×     384× 1×   606×   1× 171× 171×   1× 2532×   1× 12367×                       12367× 12163×   12367×   1× 61× 61× 61× 61× 76× 76× 76× 76× 76× 2×     61× 61× 2×     1× 67×   1× 702× 702× 702× 702× 702× 700× 700× 136× 136×   700× 700×   1× 1×   700× 700× 700× 700× 700× 700× 700× 700× 700× 697× 697× 697× 695× 695× 695× 695× 731× 731× 731× 339×     695× 695×     695× 7×     697× 697× 691×     1× 2439× 15661×   2439× 71×     2368×     1× 666×   1× 644× 235× 455×       409× 353×     644×   1× 2435× 2435× 1559×   876×                   876×   1× 2435× 2435×       2435×   1× 2338× 2332×   2338× 845×     1× 1738× 1738× 1738×   2× 2× 2× 2× 2× 3× 3×   3× 3× 3× 3×     3× 3× 2×     1×     1×     3× 3×   2× 2× 2×     1736× 21×       1× 5× 5× 3× 1×     2×       1×   1×    
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/enum", "./row-renderer", "../models/cell", "../models/row", "../base/constant", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "../base/util", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, ej2_base_3, enum_1, row_renderer_1, cell_1, row_1, events, ej2_base_4, ej2_buttons_1, util_1, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var HeaderRender = (function () {
        function HeaderRender(parent, serviceLocator) {
            var _this = this;
            this.frzIdx = 0;
            this.notfrzIdx = 0;
            this.isFirstCol = false;
            this.isReplaceDragEle = true;
            this.helper = function (e) {
                var gObj = _this.parent;
                var target = _this.draggable.currentStateTarget;
                var parentEle = util_1.parentsUntil(target, 'e-headercell');
                if (!(gObj.allowReordering || gObj.allowGrouping) || (!ej2_base_1.isNullOrUndefined(parentEle)
                    && parentEle.getElementsByClassName('e-checkselectall').length > 0)) {
                    return false;
                }
                var visualElement = _this.parent.createElement('div', { className: 'e-cloneproperties e-dragclone e-headerclone' });
                var element = target.classList.contains('e-headercell') ? target : parentEle;
                if (!element || (!gObj.allowReordering && element.classList.contains('e-stackedheadercell'))) {
                    return false;
                }
                var height = element.offsetHeight;
                var headercelldiv = element.querySelector('.e-headercelldiv') || element.querySelector('.e-stackedheadercelldiv');
                var col;
                Eif (headercelldiv) {
                    col = gObj.getColumnByUid(headercelldiv.getAttribute('data-mappinguid'));
                    if (!col && element.querySelector('.e-stackedheadercelldiv') && !headercelldiv.innerHTML.includes('<')) {
                        col = gObj.getStackedHeaderColumnByHeaderText(headercelldiv.innerText.trim(), gObj.columns);
                    }
                    _this.column = col;
                    Iif (!_this.column || _this.column.lockColumn) {
                        return false;
                    }
                    visualElement.setAttribute('data-mappinguid', _this.column.uid);
                }
                if (col && !ej2_base_1.isNullOrUndefined(col.headerTemplate)) {
                    Eif (!ej2_base_1.isNullOrUndefined(col.headerTemplate)) {
                        var colIndex = gObj.getColumnIndexByField(col.field);
                        var result = col.getHeaderTemplate()(ej2_base_1.extend({ 'index': colIndex }, col), gObj, 'headerTemplate', null, null, null, null, gObj.root);
                        var isReactCompiler = gObj.isReact && typeof (col.headerTemplate) !== 'string';
                        var isReactChild = gObj.parentDetails && gObj.parentDetails.parentInstObj &&
                            gObj.parentDetails.parentInstObj.isReact;
                        Iif (isReactCompiler || isReactChild) {
                            gObj.renderTemplates();
                        }
                        util_1.appendChildren(visualElement, result);
                    }
                    else {
                        visualElement.innerHTML = col.headerTemplate;
                    }
                    Eif (!ej2_base_1.isNullOrUndefined(visualElement.firstChild) && visualElement.firstChild.nodeType === 1) {
                        visualElement.firstChild.style.pointerEvents = 'none';
                    }
                }
                else {
                    visualElement.innerHTML = headercelldiv ?
                        col.headerText : element.firstElementChild.innerHTML;
                }
                visualElement.style.width = element.offsetWidth + 'px';
                visualElement.style.height = element.offsetHeight + 'px';
                visualElement.style.lineHeight = (height - 6).toString() + 'px';
                gObj.element.appendChild(visualElement);
                return visualElement;
            };
            this.dragStart = function (e) {
                var gObj = _this.parent;
                gObj.element.querySelector('.e-gridpopup').style.display = 'none';
                gObj.notify(events.columnDragStart, { target: _this.draggable.currentStateTarget, column: _this.column, event: e.event });
            };
            this.drag = function (e) {
                var gObj = _this.parent;
                var target = e.target;
                if (target) {
                    var closest = ej2_base_2.closest(target, '.e-grid');
                    var cloneElement = _this.parent.element.querySelector('.e-cloneproperties');
                    Iif (!closest || closest.getAttribute('id') !== gObj.element.getAttribute('id')) {
                        ej2_base_3.classList(cloneElement, ['e-notallowedcur'], ['e-defaultcur']);
                        if (gObj.allowReordering) {
                            gObj.element.querySelector('.e-reorderuparrow').style.display = 'none';
                            gObj.element.querySelector('.e-reorderdownarrow').style.display = 'none';
                        }
                        if (!gObj.groupSettings.allowReordering) {
                            return;
                        }
                    }
                    gObj.notify(events.columnDrag, { target: e.target, column: _this.column, event: e.event });
                }
            };
            this.dragStop = function (e) {
                var gObj = _this.parent;
                var cancel;
                gObj.element.querySelector('.e-gridpopup').style.display = 'none';
                if ((!util_1.parentsUntil(e.target, 'e-headercell') && !util_1.parentsUntil(e.target, 'e-groupdroparea')) ||
                    (!gObj.allowReordering && util_1.parentsUntil(e.target, 'e-headercell')) ||
                    (!e.helper.getAttribute('data-mappinguid') && util_1.parentsUntil(e.target, 'e-groupdroparea'))) {
                    ej2_base_2.remove(e.helper);
                    cancel = true;
                }
                gObj.notify(events.columnDragStop, { target: e.target, event: e.event, column: _this.column, cancel: cancel });
            };
            this.drop = function (e) {
                var gObj = _this.parent;
                var uid = e.droppedElement.getAttribute('data-mappinguid');
                var closest = ej2_base_2.closest(e.target, '.e-grid');
                ej2_base_2.remove(e.droppedElement);
                Iif (closest && closest.getAttribute('id') !== gObj.element.getAttribute('id') ||
                    !(gObj.allowReordering || gObj.allowGrouping)) {
                    return;
                }
                gObj.notify(events.headerDrop, { target: e.target, uid: uid, droppedElement: e.droppedElement });
            };
            this.parent = parent;
            this.serviceLocator = serviceLocator;
            this.ariaService = this.serviceLocator.getService('ariaService');
            this.widthService = this.serviceLocator.getService('widthService');
            Iif (this.parent.isDestroyed) {
                return;
            }
            if (!this.parent.enableColumnVirtualization) {
                this.parent.on(events.columnVisibilityChanged, this.setVisible, this);
            }
            this.parent.on(events.columnPositionChanged, this.colPosRefresh, this);
            this.parent.on(events.initialEnd, this.renderCustomToolbar, this);
            if (this.parent.rowRenderingMode === 'Vertical') {
                this.parent.on(events.uiUpdate, this.updateCustomResponsiveToolbar, this);
            }
        }
        HeaderRender.prototype.renderPanel = function () {
            var div = this.parent.element.querySelector('.' + literals.gridHeader);
            var isRendered = (div != null);
            div = isRendered ? div : this.parent.createElement('div', { className: 'e-gridheader' });
            var innerDiv = isRendered ? div.querySelector('.' + literals.headerContent) :
                this.parent.createElement('div', { className: literals.headerContent });
            this.toggleStackClass(div);
            div.appendChild(innerDiv);
            this.setPanel(div);
            if (!isRendered) {
                this.parent.element.appendChild(div);
            }
        };
        HeaderRender.prototype.renderTable = function () {
            var headerDiv = this.getPanel();
            headerDiv.appendChild(this.createHeaderTable());
            this.setTable(headerDiv.querySelector('.' + literals.table));
            this.initializeHeaderDrag();
            this.initializeHeaderDrop();
            this.parent.notify(events.headerRefreshed, { rows: this.rows });
        };
        HeaderRender.prototype.getPanel = function () {
            return this.headerPanel;
        };
        HeaderRender.prototype.setPanel = function (panel) {
            this.headerPanel = panel;
        };
        HeaderRender.prototype.getTable = function () {
            return this.headerTable;
        };
        HeaderRender.prototype.setTable = function (table) {
            this.headerTable = table;
        };
        HeaderRender.prototype.getColGroup = function () {
            return this.colgroup;
        };
        HeaderRender.prototype.setColGroup = function (colGroup) {
            return this.colgroup = colGroup;
        };
        HeaderRender.prototype.getRows = function () {
            var table = this.getTable();
            return table.tHead.rows;
        };
        HeaderRender.prototype.createHeaderTable = function () {
            var table = this.createTable();
            var innerDiv = this.getPanel().querySelector('.' + literals.headerContent);
            innerDiv.appendChild(table);
            return innerDiv;
        };
        HeaderRender.prototype.createHeader = function (tableEle, tableName) {
            if (tableEle === void 0) { tableEle = null; }
            var gObj = this.parent;
            if (this.getTable()) {
                ej2_base_2.remove(this.getTable());
            }
            var table = this.parent.createElement('table', { className: literals.table, attrs: { role: 'presentation' } });
            table.style.cssText = 'border-collapse: separate; border-spacing: .25px;';
            var findHeaderRow = this.createHeaderContent(tableName);
            var thead = findHeaderRow.thead;
            var tbody = this.parent.createElement(literals.tbody, { className: this.parent.frozenRows || this.parent.isRowPinned ||
                    ((this.parent.enableVirtualization || this.parent.isRowDomVirtualization() || this.parent.enableInfiniteScrolling) && this.parent.editSettings.showAddNewRow) ? '' :
                    'e-hide', attrs: { role: 'rowgroup' } });
            this.caption = this.parent.createElement('caption', { innerHTML: this.parent.element.id + '_header_table', className: 'e-hide' });
            var colGroup = this.parent.createElement(literals.colGroup);
            var rowBody = this.parent.createElement('tr', { attrs: { role: 'row' }, className: (this.parent.enableVirtualization ||
                    this.parent.enableInfiniteScrolling) && this.parent.editSettings.showAddNewRow ? 'e-hide' : '' });
            var bodyCell;
            var rows = this.rows = findHeaderRow.rows;
            for (var i = 0, len = rows.length; i < len; i++) {
                for (var j = 0, len_1 = rows[parseInt(i.toString(), 10)].cells.length; j < len_1; j++) {
                    bodyCell = this.parent.createElement('td');
                    rowBody.appendChild(bodyCell);
                }
            }
            if (gObj.allowFiltering || gObj.allowSorting || gObj.allowGrouping) {
                table.classList.add('e-sortfilter');
            }
            this.updateColGroup(colGroup);
            tbody.appendChild(rowBody);
            table.appendChild(this.caption);
            table.appendChild(this.setColGroup(colGroup));
            table.appendChild(thead);
            table.appendChild(tbody);
            return table;
        };
        HeaderRender.prototype.createTable = function (tableEle) {
            if (tableEle === void 0) { tableEle = null; }
            return this.createHeader(tableEle);
        };
        HeaderRender.prototype.createHeaderContent = function (tableName) {
            var gObj = this.parent;
            var columns = gObj.getColumns();
            var thead = this.parent.createElement('thead', { attrs: { 'role': 'rowgroup' } });
            var colHeader = this.parent.createElement('tr', { className: 'e-columnheader', attrs: { role: 'row' } });
            var rowRenderer = new row_renderer_1.RowRenderer(this.serviceLocator, enum_1.CellType.Header, gObj);
            rowRenderer.element = colHeader;
            var rows = [];
            var headerRow;
            this.colDepth = util_1.measureColumnDepth(gObj.columns);
            for (var i = 0, len = this.colDepth; i < len; i++) {
                rows[parseInt(i.toString(), 10)] = this.generateRow(i);
                rows[parseInt(i.toString(), 10)].cells = [];
            }
            rows = this.ensureColumns(rows);
            rows = this.getHeaderCells(rows, tableName);
            if (gObj.isRowDragable() && this.parent.getFrozenMode() === 'Right') {
                for (var i = 0, len = rows.length; i < len; i++) {
                    rows[parseInt(i.toString(), 10)].cells.push(this.generateCell({}, enum_1.CellType.RowDragHIcon));
                }
            }
            var headerTemplateColumn = columns.filter(function (a) { return a.headerTemplate; });
            if (headerTemplateColumn.length && (this.parent.isReact || this.parent.isVue)) {
                util_1.clearReactVueTemplates(this.parent, ['headerTemplate']);
            }
            if (columns && columns.length && !columns[0].visible) {
                if (this.parent && this.parent.renderModule) {
                    this.parent.renderModule.isFirstColumnHidden = true;
                }
            }
            else {
                if (this.parent && this.parent.renderModule) {
                    this.parent.renderModule.isFirstColumnHidden = false;
                }
            }
            for (var i = 0, len = this.colDepth; i < len; i++) {
                headerRow = rowRenderer.render(rows[parseInt(i.toString(), 10)], columns);
                if (this.parent.rowHeight && headerRow.querySelector('.e-headercell')) {
                    headerRow.style.height = this.parent.rowHeight + 'px';
                }
                util_1.addFixedColumnBorder(headerRow);
                thead.appendChild(headerRow);
            }
            var headerVisibleCell = Array.from(thead.querySelectorAll('.e-headercell:not(.e-hide)'));
            if (this.parent.allowResizing && headerVisibleCell.length > 0) {
                if (thead.querySelector('.e-lastcell') && thead.querySelector('.e-lastcell').classList.contains('e-hide')) {
                    var lastVisibleCell = headerVisibleCell[headerVisibleCell.length - 1];
                    lastVisibleCell.classList.add('e-last-visible-cell');
                }
                else Iif (thead.querySelector('.e-laststackcell') &&
                    thead.querySelector('.e-laststackcell').classList.contains('e-hide')) {
                    var lastVisibleStackedCell = headerVisibleCell[headerVisibleCell.length - 1];
                    lastVisibleStackedCell.classList.add('e-last-visible-stack-cell');
                }
            }
            var findHeaderRow = {
                thead: thead,
                rows: rows
            };
            return findHeaderRow;
        };
        HeaderRender.prototype.updateColGroup = function (colGroup) {
            var cols = this.parent.getColumns();
            var col;
            var indexes = this.parent.getColumnIndexesInView();
            colGroup.id = this.parent.element.id + literals.colGroup;
            if (this.parent.allowGrouping) {
                for (var i = 0, len = this.parent.groupSettings.columns.length; i < len; i++) {
                    if (this.parent.enableColumnVirtualization && indexes.indexOf(i) === -1) {
                        continue;
                    }
                    col = this.parent.createElement('col', { className: 'e-group-intent' });
                    colGroup.appendChild(col);
                }
            }
            if (this.parent.detailTemplate || this.parent.childGrid) {
                col = this.parent.createElement('col', { className: 'e-detail-intent' });
                colGroup.appendChild(col);
            }
            if (this.parent.isRowDragable() && this.parent.getFrozenMode() !== 'Right') {
                col = this.parent.createElement('col', { className: 'e-drag-intent' });
                colGroup.appendChild(col);
            }
            for (var i = 0, len = cols.length; i < len; i++) {
                col = this.parent.createElement('col');
                if (cols[parseInt(i.toString(), 10)].visible === false) {
                    ej2_base_2.setStyleAttribute(col, { 'display': 'none' });
                }
                colGroup.appendChild(col);
            }
            if (this.parent.isRowDragable() && this.parent.getFrozenMode() === 'Right') {
                col = this.parent.createElement('col', { className: 'e-drag-intent' });
                colGroup.appendChild(col);
            }
            return colGroup;
        };
        HeaderRender.prototype.ensureColumns = function (rows) {
            var gObj = this.parent;
            var indexes = this.parent.getColumnIndexesInView();
            for (var i = 0, len = rows.length; i < len; i++) {
                var rowSpan = i === 0 ? this.colDepth : 0;
                if (gObj.allowGrouping) {
                    for (var c = 0, len_2 = gObj.groupSettings.columns.length; c < len_2; c++) {
                        if (this.parent.enableColumnVirtualization && indexes.indexOf(c) === -1) {
                            continue;
                        }
                        var indentCell = this.generateCell({}, enum_1.CellType.HeaderIndent);
                        if (this.colDepth > 1) {
                            indentCell.rowSpan = rowSpan;
                        }
                        rows[parseInt(i.toString(), 10)].cells.push(indentCell);
                    }
                }
                if (gObj.detailTemplate || gObj.childGrid) {
                    var args = {};
                    this.parent.notify(events.detailIndentCellInfo, args);
                    var indentCell = this.generateCell(args, enum_1.CellType.DetailHeader);
                    Iif (this.colDepth > 1) {
                        indentCell.rowSpan = rowSpan;
                    }
                    rows[parseInt(i.toString(), 10)].cells.push(indentCell);
                }
                if (gObj.isRowDragable() && this.parent.getFrozenMode() !== 'Right') {
                    var indentCell = this.generateCell({}, enum_1.CellType.RowDragHIcon);
                    Iif (this.colDepth > 1) {
                        indentCell.rowSpan = rowSpan;
                    }
                    rows[parseInt(i.toString(), 10)].cells.push(indentCell);
                }
            }
            return rows;
        };
        HeaderRender.prototype.getHeaderCells = function (rows, tableName) {
            var thead = this.parent.getHeaderTable() && this.parent.getHeaderTable().querySelector('thead');
            var cols = this.parent.enableColumnVirtualization ?
                this.parent.getColumns(this.parent.enablePersistence) : this.parent.columns;
            this.frzIdx = 0;
            this.notfrzIdx = 0;
            if (this.parent.lockcolPositionCount) {
                for (var i = 0; i < (!ej2_base_1.isNullOrUndefined(cols) ? cols.length : 0); i++) {
                    this.lockColsRendered = false;
                    rows = this.appendCells(cols[parseInt(i.toString(), 10)], rows, 0, i === 0, false, i === (cols.length - 1), thead, tableName, false);
                }
            }
            for (var i = 0, len = (!ej2_base_1.isNullOrUndefined(cols) ? cols.length : 0); i < len; i++) {
                this.notfrzIdx = 0;
                this.lockColsRendered = true;
                rows = this.appendCells(cols[parseInt(i.toString(), 10)], rows, 0, i === 0, false, i === (len - 1), thead, tableName, false);
            }
            return rows;
        };
        HeaderRender.prototype.appendCells = function (cols, rows, index, isFirstObj, isFirstCol, isLastCol, isMovable, tableName, isStackLastCol) {
            var lastCol = isLastCol ? isStackLastCol ? 'e-laststackcell' : 'e-lastcell' : '';
            var isLockColumn = !this.parent.lockcolPositionCount
                || (cols.lockColumn && !this.lockColsRendered) || (!cols.lockColumn && this.lockColsRendered);
            if (!cols.columns) {
                if (isLockColumn) {
                    rows[parseInt(index.toString(), 10)].cells.push(this.generateCell(cols, enum_1.CellType.Header, this.colDepth - index, (isFirstObj ? '' : (isFirstCol ? 'e-firstcell' : '')) + lastCol, index, this.parent.getColumnIndexByUid(cols.uid)));
                }
                if (this.parent.lockcolPositionCount) {
                    if ((this.frzIdx + this.notfrzIdx < this.parent.frozenColumns) &&
                        ((cols.lockColumn && !this.lockColsRendered) || (!cols.lockColumn && this.lockColsRendered))) {
                        this.frzIdx++;
                    }
                    else {
                        this.notfrzIdx++;
                    }
                }
                else {
                    this.frzIdx++;
                }
            }
            else {
                this.isFirstCol = false;
                var colSpan = this.getCellCnt(cols, 0);
                if (colSpan) {
                    var stackedLockColsCount = this.getStackedLockColsCount(cols, 0);
                    var isStackedLockColumn = this.parent.lockcolPositionCount === 0
                        || (!this.lockColsRendered && stackedLockColsCount !== 0)
                        || (this.lockColsRendered && (colSpan - stackedLockColsCount) !== 0);
                    if (isStackedLockColumn) {
                        rows[parseInt(index.toString(), 10)].cells.push(new cell_1.Cell({
                            cellType: enum_1.CellType.StackedHeader, column: cols,
                            colSpan: this.getColSpan(colSpan, stackedLockColsCount),
                            className: isFirstObj ? '' : (isFirstCol ? 'e-firstcell' : '')
                        }));
                    }
                }
                if (this.parent.lockcolPositionCount && !this.lockColsRendered) {
                    for (var i = 0; i < cols.columns.length; i++) {
                        rows = this.appendCells(cols.columns[parseInt(i.toString(), 10)], rows, index + 1, isFirstObj, i === 0, i === (cols.columns.length - 1) && isLastCol, isMovable, tableName, false);
                    }
                }
                if (this.lockColsRendered) {
                    for (var i = 0, len = cols.columns.length; i < len; i++) {
                        isFirstObj = isFirstObj && i === 0;
                        var isFirstCol_1 = this.isFirstCol = cols.columns[parseInt(i.toString(), 10)].visible
                            && !isFirstObj;
                        var isLaststackedCol = i === (len - 1) && isLastCol;
                        rows = this.appendCells(cols.columns[parseInt(i.toString(), 10)], rows, index + 1, isFirstObj, isFirstCol_1 && !isLaststackedCol, isLaststackedCol, isMovable, tableName, true);
                    }
                }
            }
            return rows;
        };
        HeaderRender.prototype.getStackedLockColsCount = function (col, lockColsCount) {
            if (col.columns) {
                for (var i = 0; i < col.columns.length; i++) {
                    lockColsCount = this.getStackedLockColsCount(col.columns[parseInt(i.toString(), 10)], lockColsCount);
                }
            }
            else if (col.lockColumn) {
                lockColsCount++;
            }
            return lockColsCount;
        };
        HeaderRender.prototype.getColSpan = function (colSpan, stackedLockColsCount) {
            colSpan = !this.lockColsRendered ? stackedLockColsCount : colSpan - stackedLockColsCount;
            return colSpan;
        };
        HeaderRender.prototype.generateRow = function (index) {
            return new row_1.Row({});
        };
        HeaderRender.prototype.generateCell = function (column, cellType, rowSpan, className, rowIndex, colIndex) {
            var opt = {
                'visible': column.visible,
                'isDataCell': false,
                'isTemplate': !ej2_base_1.isNullOrUndefined(column.headerTemplate),
                'rowID': '',
                'column': column,
                'cellType': cellType,
                'rowSpan': rowSpan,
                'className': className,
                'index': rowIndex,
                'colIndex': colIndex
            };
            if (!opt.rowSpan || opt.rowSpan < 2) {
                delete opt.rowSpan;
            }
            return new cell_1.Cell(opt);
        };
        HeaderRender.prototype.setVisible = function (columns) {
            var gObj = this.parent;
            var displayVal;
            var idx;
            for (var c = 0, clen = columns.length; c < clen; c++) {
                var column = columns[parseInt(c.toString(), 10)];
                idx = gObj.getNormalizedColumnIndex(column.uid);
                displayVal = column.visible ? '' : 'none';
                ej2_base_2.setStyleAttribute(this.getColGroup().children[parseInt(idx.toString(), 10)], { 'display': displayVal });
                if (gObj.editSettings.showAddNewRow && gObj.element.querySelector('.e-addedrow')) {
                    ej2_base_2.setStyleAttribute(gObj.element.querySelector('.e-addedrow').querySelector('colgroup').childNodes[parseInt(idx.toString(), 10)], { 'display': displayVal });
                }
            }
            this.refreshUI();
            if (this.parent.editSettings.showAddNewRow) {
                this.parent.isAddNewRow = true;
            }
        };
        HeaderRender.prototype.colPosRefresh = function () {
            this.refreshUI();
        };
        HeaderRender.prototype.refreshUI = function () {
            var headerDiv = this.getPanel();
            this.toggleStackClass(headerDiv);
            var table = this.getTable();
            var tableName = undefined;
            if (table) {
                this.droppableDestroy();
                if (this.parent.reorderModule) {
                    this.parent.reorderModule.element = null;
                    this.parent.reorderModule.destElement = null;
                }
                ej2_base_2.remove(table);
                if (this.parent.editSettings.showAddNewRow && !this.parent.isAddNewRow && table.querySelector('.e-addedrow') &&
                    (this.parent.enableVirtualization || this.parent.enableInfiniteScrolling)) {
                    (table.querySelector('.e-addedrow')).classList.add('e-addrow-removed');
                    this.parent.isAddNewRow = true;
                }
                table.removeChild(table.childNodes[1]);
                table.removeChild(table.childNodes[1]);
                var colGroup = this.parent.createElement(literals.colGroup);
                var findHeaderRow = this.createHeaderContent(tableName);
                this.rows = findHeaderRow.rows;
                table.insertBefore(findHeaderRow.thead, table.childNodes[1]);
                this.updateColGroup(colGroup);
                table.insertBefore(this.setColGroup(colGroup), table.childNodes[1]);
                this.appendContent(table);
                this.parent.notify(events.colGroupRefresh, {});
                this.widthService.setWidthToColumns();
                this.parent.updateDefaultCursor();
                this.initializeHeaderDrag();
                this.initializeHeaderDrop();
                var rows = [].slice.call(headerDiv.querySelectorAll('tr.e-columnheader'));
                for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
                    var row = rows_1[_i];
                    var gCells = [].slice.call(row.getElementsByClassName('e-grouptopleftcell'));
                    if (gCells.length) {
                        gCells[gCells.length - 1].classList.add('e-lastgrouptopleftcell');
                    }
                }
                this.parent.notify(events.headerRefreshed, { rows: this.rows });
                Iif (this.parent.enableColumnVirtualization && util_1.parentsUntil(table, literals.movableHeader)) {
                    this.parent.notify(events.headerRefreshed, { rows: this.rows, args: { isFrozen: false, isXaxis: true } });
                }
                if (this.parent.allowTextWrap && this.parent.textWrapSettings.wrapMode === 'Header') {
                    util_1.wrap(rows, true);
                }
            }
            var firstHeaderCell = this.parent.getHeaderContent().querySelector('.e-headercell:not(.e-hide)');
            if (!ej2_base_1.isNullOrUndefined(firstHeaderCell)) {
                firstHeaderCell.tabIndex = 0;
            }
        };
        HeaderRender.prototype.toggleStackClass = function (div) {
            var column = this.parent.columns;
            var stackedHdr = (!ej2_base_1.isNullOrUndefined(column) ? column.some(function (column) { return !ej2_base_1.isNullOrUndefined(column.columns); })
                : false);
            if (stackedHdr) {
                div.classList.add('e-stackedheader');
            }
            else {
                div.classList.remove('e-stackedheader');
            }
        };
        HeaderRender.prototype.appendContent = function (table) {
            this.getPanel().querySelector('.' + literals.headerContent).appendChild(table);
        };
        HeaderRender.prototype.getCellCnt = function (col, cnt) {
            if (col.columns) {
                for (var i = 0, len = col.columns.length; i < len; i++) {
                    cnt = this.getCellCnt(col.columns[parseInt(i.toString(), 10)], cnt);
                }
            }
            else {
                if (col.visible) {
                    cnt++;
                }
            }
            return cnt;
        };
        HeaderRender.prototype.initializeHeaderDrag = function () {
            var gObj = this.parent;
            if (!(this.parent.allowReordering || (this.parent.allowGrouping && this.parent.groupSettings.showDropArea))) {
                return;
            }
            this.draggable = new ej2_base_4.Draggable(gObj.getHeaderContent(), {
                dragTarget: '.e-headercell',
                distance: 5,
                helper: this.helper,
                dragStart: this.dragStart,
                drag: this.drag,
                dragStop: this.dragStop,
                abort: '.e-rhandler',
                isReplaceDragEle: this.isReplaceDragEle
            });
            this.parent.on(events.destroy, this.droppableDestroy, this);
        };
        HeaderRender.prototype.initializeHeaderDrop = function () {
            var gObj = this.parent;
            this.droppable = new ej2_base_4.Droppable(gObj.getHeaderContent(), {
                accept: '.e-dragclone',
                drop: this.drop
            });
            this.parent.on(events.destroy, this.droppableDestroy, this);
        };
        HeaderRender.prototype.droppableDestroy = function () {
            if (this.droppable && !this.droppable.isDestroyed) {
                this.droppable.destroy();
            }
            if (this.draggable && !this.draggable.isDestroyed) {
                this.draggable.destroy();
            }
        };
        HeaderRender.prototype.renderCustomToolbar = function () {
            var _this = this;
            var gObj = this.parent;
            if (gObj.rowRenderingMode === 'Vertical' && !gObj.toolbar
                && (gObj.allowSorting || (gObj.allowFiltering && gObj.filterSettings.type !== 'FilterBar'))) {
                var div = gObj.createElement('div', { className: 'e-res-toolbar e-toolbar' });
                var toolbarItems = gObj.createElement('div', { className: 'e-toolbar-items' });
                var toolbarLeft = gObj.createElement('div', { className: 'e-toolbar-left' });
                var count = this.parent.allowFiltering && this.parent.allowSorting ? 2 : 1;
                for (var i = 0; i < count; i++) {
                    var toolbarItem = gObj.createElement('div', { className: 'e-toolbar-item e-gridresponsiveicons e-icons e-tbtn-align' });
                    var cls = count === 1 ? this.parent.allowSorting ? 'sort'
                        : 'filter' : i === 1 ? 'sort' : 'filter';
                    var button = gObj.createElement('button', { className: 'e-tbar-btn e-control e-btn e-lib e-icon-btn' });
                    var span = gObj.createElement('span', { className: 'e-btn-icon e-res' + cls + '-icon e-icons' });
                    button.appendChild(span);
                    var btnObj = new ej2_buttons_1.Button({
                        cssClass: this.parent.cssClass ? this.parent.cssClass : ''
                    });
                    btnObj.appendTo(button);
                    button.onclick = function (e) {
                        if (e.target.classList.contains('e-ressort-btn')
                            || e.target.classList.contains('e-ressort-icon') ||
                            e.target.querySelector('.e-ressort-icon')) {
                            _this.parent.showResponsiveCustomSort();
                        }
                        else {
                            _this.parent.showResponsiveCustomFilter();
                        }
                    };
                    toolbarItem.appendChild(button);
                    toolbarLeft.appendChild(toolbarItem);
                }
                toolbarItems.appendChild(toolbarLeft);
                div.appendChild(toolbarItems);
                gObj.element.insertBefore(div, this.parent.element.querySelector('.' + literals.gridHeader));
            }
            else {
                if (gObj.enableAdaptiveUI && !gObj.toolbar) {
                    gObj.getContent().classList.add('e-responsive-header');
                }
            }
        };
        HeaderRender.prototype.updateCustomResponsiveToolbar = function (args) {
            var resToolbar = this.parent.element.querySelector('.e-responsive-toolbar');
            if (args.module === 'toolbar') {
                if (resToolbar) {
                    ej2_base_2.remove(resToolbar);
                }
                else {
                    this.renderCustomToolbar();
                }
            }
        };
        return HeaderRender;
    }());
    exports.HeaderRender = HeaderRender;
});