all files / grid/actions/ row-reorder.js

92.89% Statements 575/619
84.2% Branches 485/576
96.08% Functions 49/51
93.15% Lines 571/613
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997   50× 50× 50× 50× 50× 50× 50× 50× 20× 20× 20×   20×       20× 20× 20×         18×     18× 18×     18× 18×       18× 18× 18× 18×     18× 18× 18× 18× 18×   18× 18× 18× 18×       18× 18× 18×   18× 18× 18× 18×   50× 17× 17×         17×   17× 17×     17× 17× 17×     17× 17×         17× 17× 17×       50× 20× 20× 20× 20× 11× 11× 11× 10×     20× 20×   20× 20× 20× 20× 20× 20×   19× 19×     19×       19× 19× 19×     19× 19× 18×     15×         19× 10× 10×                         19× 19×   16× 16×   16×       10×                                         19×                           50× 18×   18× 18×           18×     50× 18× 18×   17× 17×   17× 17× 17×     17× 17× 17× 17× 17× 17× 17× 12×     17× 17×     17×             17× 17×     15× 15× 15×                               15×     50× 18× 92×       50× 50×     50× 50× 50× 50× 50× 50× 50×                 10× 10× 10× 10× 12× 12×         12× 12×     12× 12×       10×   10×             68×                                 10×                         11× 11× 11×   11×     11× 11×     11×   11×             56× 56× 56×   56× 56× 56×     11×   10×             10×     10×     10×       10×                   10× 10× 10× 10×   10×   10× 10× 10× 12×   10×   10× 12×                 12×   10×       10× 13×         10×   36×     50× 50×                       16× 16× 16× 16× 16× 16× 16×   13× 1165×     1166×   11× 11×   11× 11×     10× 10×     10×     10× 10×   10× 10×       10×   10×         10× 10× 10×                                                         10×               34×       33× 33×             25× 25×       21×       21× 21×   25×     28× 28× 18×   28× 11× 304×       138×   28×             37× 37× 37× 37× 37×   56×                                                                         15× 15× 10×   10× 10× 10× 10×               93× 93×   48×   45× 45× 45× 45× 45× 45× 45×   20574×   71× 71× 71×   25×       25×   25× 25×             46× 55×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/util", "../base/util", "../base/constant", "../actions/scroll", "@syncfusion/ej2-data", "../base/string-literals"], function (require, exports, ej2_base_1, ej2_base_2, ej2_base_3, util_1, util_2, events, scroll_1, ej2_data_1, literals) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RowDD = (function () {
        function RowDD(parent) {
            var _this = this;
            this.selectedRows = [];
            this.isOverflowBorder = true;
            this.selectedRowColls = [];
            this.isRefresh = true;
            this.isReplaceDragEle = true;
            this.istargetGrid = false;
            this.helper = function (e) {
                var gObj = _this.parent;
                var target = _this.draggable.currentStateTarget;
                if (!ej2_base_1.isNullOrUndefined(target) && gObj.rowDropSettings.targetID && !ej2_base_1.isNullOrUndefined(target.classList) && !target.classList.contains('e-rowcell')) {
                    target = util_1.parentsUntil(target, 'e-rowcell');
                }
                var visualElement = _this.parent.createElement('div', {
                    className: 'e-cloneproperties e-draganddrop e-grid e-dragclone',
                    styles: 'height:"auto", z-index:2, width:' + gObj.element.offsetWidth
                });
                var table = _this.parent.createElement('table', { styles: 'width:' + gObj.element.offsetWidth, attrs: { role: 'grid' } });
                var tbody = _this.parent.createElement(literals.tbody, { attrs: { role: 'rowgroup' } });
                if (document.getElementsByClassName('e-griddragarea').length ||
                    (gObj.rowDropSettings.targetID && ((!ej2_base_1.isNullOrUndefined(target) && !target.classList.contains('e-selectionbackground')
                        && gObj.selectionSettings.type !== 'Single') || !util_1.parentsUntil(target, 'e-rowcell'))) ||
                    (!gObj.rowDropSettings.targetID && !util_1.parentsUntil(target, 'e-rowdragdrop'))) {
                    return false;
                }
                if (gObj.rowDropSettings.targetID &&
                    gObj.selectionSettings.mode === 'Row' && gObj.selectionSettings.type === 'Single') {
                    gObj.selectRow(parseInt(_this.draggable.currentStateTarget.parentElement.getAttribute(literals.dataRowIndex), 10));
                }
                _this.startedRow = ej2_base_3.closest(target, 'tr').cloneNode(true);
                if (_this.parent.isFrozenGrid()) {
                    var nodes = [].slice.call(_this.startedRow.querySelectorAll('.e-rowcell'));
                    for (var i = 0; i < nodes.length; i++) {
                        ej2_base_2.removeClass([nodes[parseInt(i.toString(), 10)]], ['e-leftfreeze', 'e-freezeleftborder', 'e-fixedfreeze', 'e-freezerightborder', 'e-rightfreeze', 'e-unfreeze']);
                        nodes[parseInt(i.toString(), 10)].removeAttribute('style');
                    }
                }
                _this.processArgs(target);
                var args = {
                    selectedRow: _this.rows, dragelement: target,
                    cloneElement: visualElement, cancel: false, data: _this.rowData
                };
                var selectedRows = gObj.getSelectedRows();
                gObj.trigger(events.rowDragStartHelper, args);
                var cancel = 'cancel';
                Iif (args["" + cancel]) {
                    return false;
                }
                util_1.removeElement(_this.startedRow, '.e-indentcell');
                util_1.removeElement(_this.startedRow, '.e-detailrowcollapse');
                util_1.removeElement(_this.startedRow, '.e-detailrowexpand');
                Eif (!(gObj.enableInfiniteScrolling && gObj.infiniteScrollSettings.enableCache)) {
                    _this.removeCell(_this.startedRow, literals.gridChkBox);
                }
                var exp = new RegExp('e-active', 'g');
                _this.startedRow.innerHTML = _this.startedRow.innerHTML.replace(exp, '');
                tbody.appendChild(_this.startedRow);
                if (gObj.getSelectedRowIndexes().length > 1 && _this.startedRow.hasAttribute('aria-selected')) {
                    var dropCountEle = _this.parent.createElement('span', {
                        className: 'e-dropitemscount', innerHTML: '' + selectedRows.length
                    });
                    visualElement.appendChild(dropCountEle);
                }
                var ele = ej2_base_3.closest(target, 'tr').querySelector('.e-icon-rowdragicon');
                Eif (ele) {
                    ele.classList.add('e-dragstartrow');
                }
                table.appendChild(tbody);
                visualElement.appendChild(table);
                gObj.element.appendChild(visualElement);
                return visualElement;
            };
            this.dragStart = function (e) {
                var gObj = _this.parent;
                if ((gObj.enableVirtualization || gObj.infiniteScrollSettings.enableCache) && gObj.allowGrouping &&
                    gObj.groupSettings.columns.length && !ej2_base_1.isNullOrUndefined(e.target.closest('tr'))) {
                    var dragTrs = e.dragElement.querySelectorAll('tr');
                    var indentCells = e.target.closest('tr').querySelectorAll('.e-indentcell');
                    for (var i = 0; i < dragTrs.length; i++) {
                        for (var j = 0; j < indentCells.length; j++) {
                            var cloneIndentCell = indentCells[parseInt(j.toString(), 10)].cloneNode(true);
                            dragTrs[parseInt(i.toString(), 10)].insertBefore(cloneIndentCell, dragTrs[parseInt(i.toString(), 10)].firstElementChild);
                        }
                    }
                }
                if (gObj.element.classList.contains('e-childgrid')) {
                    var parentGrid = _this.getParentGrid(gObj.element);
                    parentGrid.appendChild(e.dragElement);
                    gObj.element.appendChild(gObj.createElement('div', { className: 'e-drag-ref' }));
                }
                document.body.classList.add('e-prevent-select');
                Iif (document.getElementsByClassName('e-griddragarea').length) {
                    return;
                }
                var target = e.target;
                var spanCssEle = _this.parent.element.querySelector('.e-dropitemscount');
                if (_this.parent.getSelectedRecords().length > 1 && spanCssEle) {
                    spanCssEle.style.left = _this.parent.element.querySelector('.e-cloneproperties table')
                        .offsetWidth - 5 + 'px';
                }
                _this.processArgs(target);
                gObj.trigger(events.rowDragStart, {
                    rows: _this.rows, target: e.target,
                    draggableType: 'rows', fromIndex: parseInt(_this.rows[0].getAttribute(literals.dataRowIndex), 10),
                    data: (_this.rowData[0] && Object.keys(_this.rowData[0]).length > 0) ? _this.rowData : _this.currentViewData()
                });
                _this.dragStartData = _this.rowData;
                var dropElem = document.getElementById(gObj.rowDropSettings.targetID);
                if (gObj.rowDropSettings.targetID && dropElem && dropElem.ej2_instances &&
                    dropElem.ej2_instances[0].getModuleName() === 'grid') {
                    dropElem.ej2_instances[0].getContent().classList.add('e-allowRowDrop');
                }
            };
            this.drag = function (e) {
                var gObj = _this.parent;
                _this.isDropGrid = _this.parent;
                _this.istargetGrid = false;
                if (_this.parent.rowDropSettings.targetID) {
                    var dropElement = document.getElementById(gObj.rowDropSettings.targetID);
                    _this.isDropGrid = dropElement.ej2_instances[0];
                    if (util_1.parentsUntil(e.target, 'e-grid')) {
                        _this.istargetGrid = _this.parent.rowDropSettings.targetID === util_1.parentsUntil(e.target, 'e-grid').id;
                    }
                }
                var cloneElement = _this.parent.element.querySelector('.e-cloneproperties');
                if (gObj.element.classList.contains('e-childgrid')) {
                    var parentGrid = _this.getParentGrid(gObj.element);
                    cloneElement = parentGrid.querySelector('.e-cloneproperties');
                }
                var target = _this.getElementFromPosition(cloneElement, e.event);
                ej2_base_3.classList(cloneElement, ['e-defaultcur'], ['e-notallowedcur', 'e-movecur', 'e-grabcur']);
                _this.isOverflowBorder = true;
                _this.hoverState = gObj.enableHover;
                var trElement = util_1.parentsUntil(target, 'e-grid') ? ej2_base_3.closest(e.target, 'tr') : null;
                if (!e.target) {
                    return;
                }
                _this.processArgs(target);
                Iif (gObj.enableVirtualization && ej2_base_1.isNullOrUndefined(_this.rows[0])) {
                    ej2_base_3.classList(cloneElement, ['e-notallowedcur'], ['e-movecur']);
                }
                var args = {
                    rows: _this.rows, target: target, draggableType: 'rows',
                    data: _this.rowData, originalEvent: e, cancel: false
                };
                gObj.trigger(events.rowDrag, args);
                _this.stopTimer();
                Iif (args.cancel) {
                    return;
                }
                gObj.element.classList.add('e-rowdrag');
                if (trElement && (util_1.parentsUntil(target, 'e-grid').id === cloneElement.parentElement.id || util_1.parentsUntil(target, 'e-grid').id)) {
                    if (_this.isDropGrid.element.querySelector('.e-emptyrow')) {
                        _this.dragTarget = 0;
                    }
                    else {
                        _this.dragTarget = parseInt(trElement.getAttribute('data-rowindex'), 10);
                    }
                }
                else {
                    _this.dragTarget = parseInt(_this.startedRow.getAttribute('data-rowindex'), 10);
                }
                if (gObj.rowDropSettings.targetID) {
                    var dragParentElement = document.querySelector('.e-drag-ref');
                    if (!util_1.parentsUntil(target, 'e-grid') || (dragParentElement
                        && util_1.parentsUntil(dragParentElement.parentElement, 'e-grid').id === util_1.parentsUntil(target, 'e-grid').id) ||
                        util_1.parentsUntil(cloneElement.parentElement, 'e-grid').id === util_1.parentsUntil(target, 'e-grid').id) {
                        ej2_base_3.classList(cloneElement, ['e-notallowedcur'], ['e-defaultcur']);
                    }
                    else {
                        ej2_base_3.classList(cloneElement, ['e-grabcur'], ['e-notallowedcur']);
                    }
                }
                else {
                    var element = util_1.parentsUntil(target, 'e-grid');
                    if (element && element.id === cloneElement.parentElement.id && util_1.parentsUntil(target, 'e-row') &&
                        !util_1.parentsUntil(target, 'e-addedrow')) {
                        ej2_base_3.classList(cloneElement, ['e-movecur'], ['e-defaultcur']);
                    }
                    else {
                        ej2_base_3.classList(cloneElement, ['e-notallowedcur'], ['e-movecur']);
                    }
                }
                Eif (util_1.parentsUntil(_this.isDropGrid.element, 'e-grid')) {
                    if ((!_this.isDropGrid.groupSettings.columns.length || _this.isDropGrid.groupSettings.columns.length)
                        && !_this.isDropGrid.element.querySelector('.e-emptyrow')) {
                        Eif (util_1.parentsUntil(target, 'e-grid') && util_1.parentsUntil(target, 'e-grid').id === _this.isDropGrid.element.id) {
                            _this.updateScrollPostion(e.event);
                        }
                        if (((_this.isOverflowBorder || _this.parent.frozenRows > _this.dragTarget) &&
                            (parseInt(_this.startedRow.getAttribute(literals.dataRowIndex), 10) !== _this.dragTarget || _this.istargetGrid))
                            || (_this.istargetGrid && trElement && _this.isDropGrid.getRowByIndex(_this.isDropGrid.getCurrentViewRecords().length - 1).
                                getAttribute('data-uid') === trElement.getAttribute('data-uid'))) {
                            _this.moveDragRows(e, _this.startedRow, trElement);
                        }
                        else {
                            var islastRowIndex = void 0;
                            Iif (_this.parent.enableVirtualization) {
                                islastRowIndex = trElement && parseInt(trElement.getAttribute(literals.dataRowIndex), 10) ===
                                    _this.parent.renderModule.data.dataManager.dataSource.json.length - 1;
                            }
                            else {
                                var rowIndex = _this.parent.enableInfiniteScrolling && _this.parent.infiniteScrollSettings.enableCache &&
                                    !_this.parent.groupSettings.enableLazyLoading ?
                                    _this.parent.pageSettings.currentPage * _this.parent.pageSettings.pageSize - 1 :
                                    _this.parent.getCurrentViewRecords().length - 1;
                                var lastRow = _this.parent.getRowByIndex(rowIndex);
                                islastRowIndex = trElement && lastRow && lastRow.getAttribute('data-uid') === trElement.getAttribute('data-uid') &&
                                    lastRow.getAttribute('data-uid') !== _this.startedRow.getAttribute('data-uid');
                                Iif (_this.isNewRowAdded() && _this.parent.editSettings.newRowPosition === 'Bottom') {
                                    islastRowIndex = false;
                                }
                            }
                            if (islastRowIndex && !_this.parent.rowDropSettings.targetID) {
                                var bottomborder = _this.parent.createElement('div', { className: 'e-lastrow-dragborder' });
                                var gridcontentEle = _this.parent.getContent();
                                bottomborder.style.width = _this.parent.element.offsetWidth - _this.getScrollWidth() + 'px';
                                Iif (_this.parent.enableVirtualization) {
                                    bottomborder.style.zIndex = '1';
                                }
                                Eif (!gridcontentEle.getElementsByClassName('e-lastrow-dragborder').length &&
                                    (!(gObj.allowGrouping && gObj.groupSettings.columns.length) || ej2_base_1.isNullOrUndefined(trElement.nextSibling))) {
                                    gridcontentEle.classList.add('e-grid-relative');
                                    gridcontentEle.appendChild(bottomborder);
                                    bottomborder.style.bottom = _this.getScrollWidth() + 'px';
                                }
                            }
                            _this.removeBorder(trElement);
                        }
                    }
                    if (target && target.classList.contains(literals.content)
                        && !_this.isDropGrid.element.querySelector('.e-emptyrow') && _this.istargetGrid) {
                        _this.removeBorder(trElement);
                        var rowIndex = _this.isDropGrid.getCurrentViewRecords().length - 1;
                        var selector = '.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse';
                        var groupSelector = '.e-rowcell:not(.e-hide),.e-rowdragdrop:not(.e-hide),.e-detailrowcollapse:not(.e-hide)';
                        var rowElement = [];
                        Iif (_this.parent.allowGrouping && _this.parent.groupSettings.columns && _this.parent.groupSettings.columns.length) {
                            rowElement = [].slice.call(_this.isDropGrid.getRowByIndex(rowIndex).querySelectorAll(groupSelector));
                        }
                        else {
                            rowElement = [].slice.call(_this.isDropGrid.getRowByIndex(rowIndex).querySelectorAll(selector));
                        }
                        Eif (rowElement.length > 0) {
                            Iif (_this.parent.allowGrouping && _this.parent.groupSettings.columns && _this.parent.groupSettings.columns.length) {
                                _this.groupRowDDIndicator(rowElement, true);
                            }
                            else {
                                util_1.addRemoveActiveClasses(rowElement, true, 'e-dragborder');
                            }
                        }
                    }
                }
            };
            this.dragStop = function (e) {
                if (_this.parent.isCheckBoxSelection && _this.parent.enableInfiniteScrolling) {
                    window.getSelection().removeAllRanges();
                }
                document.body.classList.remove('e-prevent-select');
                Iif (util_1.isActionPrevent(_this.parent)) {
                    _this.parent.notify(events.preventBatch, {
                        instance: _this, handler: _this.processDragStop, arg1: e
                    });
                }
                else {
                    _this.processDragStop(e);
                }
            };
            this.processDragStop = function (e) {
                var gObj = _this.parent;
                if (_this.parent.isDestroyed) {
                    return;
                }
                var targetEle = _this.getElementFromPosition(e.helper, e.event);
                var target = targetEle && !targetEle.classList.contains('e-dlg-overlay') ?
                    targetEle : e.target;
                gObj.element.classList.remove('e-rowdrag');
                var dropElement = document.getElementById(gObj.rowDropSettings.targetID);
                if (gObj.rowDropSettings.targetID && dropElement && dropElement.ej2_instances &&
                    dropElement.ej2_instances[0].getModuleName() === 'grid') {
                    dropElement.ej2_instances[0].getContent().classList.remove('e-allowRowDrop');
                }
                Eif (util_1.parentsUntil(_this.isDropGrid.element, 'e-grid')) {
                    _this.stopTimer();
                    _this.isDropGrid.enableHover = _this.hoverState;
                    _this.isDropGrid.getContent().classList.remove('e-grid-relative');
                    _this.removeBorder(targetEle);
                    var stRow = _this.isDropGrid.element.querySelector('.e-dragstartrow');
                    if (stRow) {
                        stRow.classList.remove('e-dragstartrow');
                    }
                }
                _this.processArgs(target);
                Iif (gObj.enableVirtualization && ej2_base_1.isNullOrUndefined(_this.rows[0])) {
                    return;
                }
                var args = {
                    target: target, draggableType: 'rows',
                    cancel: false,
                    fromIndex: parseInt(_this.rows[0].getAttribute(literals.dataRowIndex), 10),
                    dropIndex: _this.dragTarget, rows: _this.rows,
                    data: (Object.keys(_this.dragStartData[0]).length > 0) ? _this.dragStartData : _this.currentViewData()
                };
                gObj.trigger(events.rowDrop, args, function () {
                    if (!(util_1.parentsUntil(target, literals.row) || util_1.parentsUntil(target, 'e-emptyrow')
                        || util_1.parentsUntil(target, literals.gridContent)) || args.cancel) {
                        _this.dragTarget = null;
                        ej2_base_3.remove(e.helper);
                        return;
                    }
                    _this.isRefresh = false;
                    var selectedIndexes = _this.parent.getSelectedRowIndexes();
                    if (gObj.isRowDragable()) {
                        if (!_this.parent.rowDropSettings.targetID &&
                            _this.startedRow.querySelector('td.e-selectionbackground') && selectedIndexes.length > 1 &&
                            selectedIndexes.length !== _this.parent.getCurrentViewRecords().length) {
                            _this.reorderRows(selectedIndexes, args.dropIndex);
                        }
                        else {
                            _this.reorderRows([parseInt(_this.startedRow.getAttribute(literals.dataRowIndex), 10)], _this.dragTarget);
                        }
                        _this.dragTarget = null;
                        Eif (!gObj.rowDropSettings.targetID) {
                            Eif (e.helper.classList.contains('e-cloneproperties') && document.querySelector('.' + e.helper.classList[0])) {
                                ej2_base_3.remove(e.helper);
                            }
                            Iif (gObj.enableVirtualization && !gObj.sortSettings.columns.length && !gObj.filterSettings.columns.length &&
                                (!_this.parent.allowGrouping || !gObj.groupSettings.columns.length)) {
                                gObj.refresh();
                            }
                            else {
                                _this.rowOrder(args);
                            }
                        }
                        Iif (_this.parent.getContentTable().scrollHeight < _this.parent.getContent().clientHeight) {
                            _this.parent.scrollModule.setLastRowCell();
                        }
                    }
                    _this.isRefresh = true;
                });
            };
            this.removeCell = function (targetRow, className) {
                return [].slice.call(targetRow.querySelectorAll('td')).filter(function (cell) {
                    if (cell.classList.contains(className)) {
                        targetRow.deleteCell(cell.cellIndex);
                    }
                });
            };
            this.parent = parent;
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.initialEnd, this.initializeDrag, this);
            this.parent.on(events.columnDrop, this.columnDrop, this);
            this.parent.on(events.rowDragAndDropComplete, this.onActionComplete, this);
            this.onDataBoundFn = this.onDataBound.bind(this);
            this.parent.addEventListener(events.dataBound, this.onDataBoundFn);
            this.parent.on(events.uiUpdate, this.enableAfterRender, this);
            this.parent.on(events.destroy, this.destroy, this);
        }
        RowDD.prototype.getParentGrid = function (childGrid) {
            var parentGrid = childGrid;
            var parentGridObtained = false;
            while (!parentGridObtained) {
                if (parentGrid.ej2_instances[0].parentDetails) {
                    parentGrid = document.getElementById(parentGrid.ej2_instances[0].parentDetails.parentID);
                }
                Eif (!parentGrid.classList.contains('e-childgrid')) {
                    parentGridObtained = true;
                }
            }
            return parentGrid;
        };
        RowDD.prototype.isNewRowAdded = function () {
            return this.parent.editSettings && this.parent.editSettings.showAddNewRow &&
                !(this.parent.enableInfiniteScrolling || this.parent.enableVirtualization);
        };
        RowDD.prototype.groupRowDDIndicator = function (rowElement, isAdd) {
            util_1.addRemoveActiveClasses([rowElement[0]], isAdd, 'e-dragleft');
            util_1.addRemoveActiveClasses(rowElement, isAdd, 'e-dragtop', 'e-dragbottom');
            util_1.addRemoveActiveClasses([rowElement[rowElement.length - 1]], isAdd, 'e-dragright');
        };
        RowDD.prototype.refreshRow = function (args, tbody, target) {
            var gObj = this.parent;
            var tbodyContent = gObj.getContentTable().querySelector(literals.tbody);
            var tbodyHeader = gObj.getHeaderTable().querySelector(literals.tbody);
            for (var i = 0, len = args.rows.length; i < len; i++) {
                var row = args.rows[parseInt(i.toString(), 10)];
                if (((gObj.enableVirtualization && gObj.allowGrouping && gObj.groupSettings.columns.length) ||
                    (gObj.enableInfiniteScrolling && gObj.infiniteScrollSettings.enableCache)) &&
                    args.rows.length === 1) {
                    var removeElem = gObj.getRowElementByUID(row.getAttribute('data-uid'));
                    Eif (!ej2_base_1.isNullOrUndefined(removeElem)) {
                        ej2_base_3.remove(removeElem);
                    }
                }
                var dragstartrow = row.querySelector('.e-dragstartrow');
                Iif (dragstartrow) {
                    dragstartrow.classList.remove('e-dragstartrow');
                }
                tbody.insertBefore(row, target);
                if (gObj.allowGrouping && gObj.groupSettings.columns.length) {
                    var dragRowUid = row.getAttribute('data-uid');
                    var dropRowUid = args.target.parentElement.getAttribute('data-uid');
                    var dragRowObject = gObj.getRowObjectFromUID(dragRowUid);
                    var dropRowObject = gObj.getRowObjectFromUID(dropRowUid);
                    Eif (dragRowObject.parentUid !== dropRowObject.parentUid) {
                        gObj['groupModule'].groupReorderHandler(dragRowObject, dropRowObject);
                    }
                }
            }
            var tr = [].slice.call(gObj.editSettings.showAddNewRow ?
                tbody.querySelectorAll('.e-row:not(.e-addedrow)') : tbody.getElementsByClassName(literals.row));
            if (gObj.allowGrouping && gObj.groupSettings.columns.length) {
                Iif (gObj.groupSettings.enableLazyLoading || (gObj.enableInfiniteScrolling &&
                    gObj.infiniteScrollSettings.enableCache && tr.length > gObj.pageSettings.pageSize * 3)) {
                    gObj.refresh();
                }
                else {
                    util_2.groupReorderRowObject(this.parent, args, tr);
                    if (gObj.enableVirtualization || (gObj.enableInfiniteScrolling && gObj.infiniteScrollSettings.enableCache)) {
                        util_2.resetCachedRowIndex(gObj);
                    }
                    else {
                        util_2.resetRowIndex(this.parent, gObj.getRowsObject().filter(function (data) { return data.isDataRow; }), tr);
                    }
                    this.parent.notify(events.refreshExpandandCollapse, {
                        rows: gObj.enableVirtualization ? this.parent.vRows : this.parent.getRowsObject()
                    });
                }
            }
            else Iif (gObj.enableInfiniteScrolling && gObj.infiniteScrollSettings.enableCache &&
                !gObj.groupSettings.columns.length) {
                if (tr.length > gObj.pageSettings.pageSize * 3) {
                    gObj.refresh();
                }
                else {
                    util_2.groupReorderRowObject(this.parent, args, tr);
                    util_2.resetCachedRowIndex(gObj);
                }
            }
            else {
                this.refreshData(tr);
            }
            if (this.parent.frozenRows) {
                for (var i = 0, len = tr.length; i < len; i++) {
                    if (i < this.parent.frozenRows) {
                        tbodyHeader.appendChild(tr[parseInt(i.toString(), 10)]);
                    }
                    else {
                        tbodyContent.appendChild(tr[parseInt(i.toString(), 10)]);
                    }
                }
            }
        };
        RowDD.prototype.updateFrozenRowreOrder = function (args) {
            var gObj = this.parent;
            var tbodyC = gObj.getContentTable().querySelector(literals.tbody);
            var tbodyH = gObj.getHeaderTable().querySelector(literals.tbody);
            var tr = [].slice.call(tbodyH.getElementsByClassName(literals.row)).concat([].slice.call(tbodyC.getElementsByClassName(literals.row)));
            var tbody = gObj.createElement(literals.tbody, { attrs: { role: 'rowgroup' } });
            Eif (!gObj.selectionSettings.persistSelection && Object.keys(gObj.selectionModule.selectedRowState).length === 0) {
                this.parent.clearSelection();
            }
            else {
                this.parent.clearRowSelection();
            }
            var targetRow = this.refreshRowTarget(args);
            for (var i = 0, len = tr.length; i < len; i++) {
                tbody.appendChild(tr[parseInt(i.toString(), 10)]);
            }
            this.refreshRow(args, tbody, targetRow);
        };
        RowDD.prototype.refreshRowTarget = function (args) {
            var gObj = this.parent;
            var targetIdx = parseInt(args.target.parentElement.getAttribute(literals.dataRowIndex), 10);
            if (gObj.enableVirtualization && gObj.allowGrouping && gObj.groupSettings.columns.length) {
                targetIdx = this.parent.getDataRows().indexOf(args.target.parentElement);
            }
            if ((args.fromIndex < args.dropIndex || args.fromIndex === args.dropIndex) && (!gObj.allowGrouping ||
                !gObj.groupSettings.columns.length)) {
                targetIdx = targetIdx + 1;
            }
            var targetTR = gObj.getRowByIndex(targetIdx);
            Iif (targetIdx === gObj.getRows().length && this.isNewRowAdded() && this.parent.editSettings.newRowPosition === 'Bottom') {
                targetTR = this.parent.element.querySelector('.e-row.e-addedrow');
            }
            var tr = gObj.allowGrouping && gObj.groupSettings.columns.length && targetIdx !== -1 &&
                args.fromIndex < args.dropIndex && targetTR ? targetTR.nextSibling : targetTR;
            return tr;
        };
        RowDD.prototype.updateFrozenColumnreOrder = function (args) {
            var gObj = this.parent;
            var tbody = gObj.getContentTable().querySelector(literals.tbody);
            Eif (!gObj.selectionSettings.persistSelection && Object.keys(gObj.selectionModule.selectedRowState).length === 0) {
                this.parent.clearSelection();
            }
            else {
                this.parent.clearRowSelection();
            }
            var targetRow = this.refreshRowTarget(args);
            this.refreshRow(args, tbody, targetRow);
        };
        RowDD.prototype.refreshData = function (tr) {
            var rowObj = {};
            var recordobj = {};
            var rowObjects = this.parent.getRowsObject();
            var currentViewData = this.parent.getCurrentViewRecords();
            for (var i = 0, len = tr.length; i < len; i++) {
                var index = parseInt(tr[parseInt(i.toString(), 10)].getAttribute(literals.dataRowIndex), 10);
                rowObj[parseInt(i.toString(), 10)] = rowObjects[parseInt(index.toString(), 10)];
                recordobj[parseInt(i.toString(), 10)] = currentViewData[parseInt(index.toString(), 10)];
            }
            var rows = this.parent.getRows();
            for (var i = 0, len = tr.length; i < len; i++) {
                rows[parseInt(i.toString(), 10)] = tr[parseInt(i.toString(), 10)];
                rowObjects[parseInt(i.toString(), 10)] = rowObj[parseInt(i.toString(), 10)];
                currentViewData[parseInt(i.toString(), 10)] = recordobj[parseInt(i.toString(), 10)];
            }
            util_2.resetRowIndex(this.parent, rowObjects, tr);
        };
        RowDD.prototype.rowOrder = function (args) {
            if (args.dropIndex === args.fromIndex || isNaN(args.dropIndex)) {
                return;
            }
            if (this.parent.isDetail()) {
                this.parent.detailCollapseAll();
                var rows = [].slice.call(this.parent.getContentTable().querySelector(literals.tbody).children);
                var rowObjects = this.parent.getRowsObject();
                rows.filter(function (row) {
                    if (row.classList.contains('e-detailrow')) {
                        row.remove();
                    }
                });
                for (var i = 0, len = rowObjects.length; i < len; i++) {
                    if (!rowObjects[parseInt(i.toString(), 10)]) {
                        break;
                    }
                    if (rowObjects[parseInt(i.toString(), 10)].isDetailRow) {
                        this.parent.getRowsObject().splice(i, 1);
                        i--;
                    }
                }
            }
            if (args.target.classList.contains('e-rowcelldrag') || args.target.classList.contains('e-dtdiagonalright')
                || args.target.classList.contains('e-dtdiagonaldown')) {
                args.target = args.target.parentElement;
            }
            Iif (!args.target.classList.contains('e-rowcell') && util_1.parentsUntil(args.target, 'e-rowcell')) {
                args.target = util_1.parentsUntil(args.target, 'e-rowcell');
            }
            if (this.parent.frozenRows) {
                this.updateFrozenRowreOrder(args);
            }
            else {
                this.updateFrozenColumnreOrder(args);
            }
            if ((!this.parent.allowGrouping || !this.parent.groupSettings.columns.length) && this.selectedRowColls.length > 0) {
                this.parent.selectRows(this.selectedRowColls);
                var indexes = [];
                if (this.parent.filterSettings.columns.length || this.parent.sortSettings.columns.length) {
                    for (var i = 0, len = args.rows.length; i < len; i++) {
                        indexes.push(parseInt(args.rows[parseInt(i.toString(), 10)].getAttribute(literals.dataRowIndex), 10));
                    }
                    this.selectedRowColls = indexes;
                }
                this.selectedRowColls = [];
            }
            else {
                this.selectedRowColls = [];
            }
        };
        RowDD.prototype.currentViewData = function () {
            var selectedIndexes = this.parent.getSelectedRowIndexes();
            var currentVdata = [];
            var fromIdx = parseInt(this.startedRow.getAttribute(literals.dataRowIndex), 10);
            for (var i = 0, n = selectedIndexes.length; i < n; i++) {
                var currentV = 'currentViewData';
                currentVdata[parseInt(i.toString(), 10)] = this.parent["" + currentV][selectedIndexes[parseInt(i.toString(), 10)]];
            }
            if (!this.parent.rowDropSettings.targetID && selectedIndexes.length === 0) {
                currentVdata[0] = this.parent.currentViewData[parseInt(fromIdx.toString(), 10)];
            }
            return currentVdata;
        };
        RowDD.prototype.reorderRows = function (fromIndexes, toIndex) {
            var selectedIndexes = this.parent.getSelectedRowIndexes();
            var selectedRecords = [];
            var draggedRecords = [];
            var currentViewData = this.parent.getDataModule().isRemote() ? this.parent.getCurrentViewRecords() :
                this.parent.renderModule.data.dataManager.dataSource.json;
            var skip = this.parent.allowPaging ?
                (this.parent.pageSettings.currentPage * this.parent.pageSettings.pageSize) - this.parent.pageSettings.pageSize : 0;
            var dropIdx = toIndex + skip;
            var actualIdx = fromIndexes[0] + skip;
            for (var i = 0, len = fromIndexes.length; i < len; i++) {
                draggedRecords[parseInt(i.toString(), 10)] = currentViewData[fromIndexes[parseInt(i.toString(), 10)] + skip];
            }
            for (var i = 0, len = selectedIndexes.length; i < len; i++) {
                selectedRecords[parseInt(i.toString(), 10)] = currentViewData[selectedIndexes[parseInt(i.toString(), 10)] + skip];
            }
            for (var i = 0, len = draggedRecords.length; i < len; i++) {
                if (i !== 0) {
                    for (var j = 0, len1 = currentViewData.length; j < len1; j++) {
                        if (JSON.stringify(currentViewData[parseInt(j.toString(), 10)]) ===
                            JSON.stringify(draggedRecords[parseInt(i.toString(), 10)])) {
                            actualIdx = j;
                            break;
                        }
                    }
                    for (var j = 0, len1 = currentViewData.length; j < len1; j++) {
                        if (JSON.stringify(currentViewData[parseInt(j.toString(), 10)]) === JSON
                            .stringify(draggedRecords[i - 1])) {
                            if (actualIdx > j) {
                                dropIdx = j + 1;
                            }
                            break;
                        }
                    }
                }
                this.reorderRow(actualIdx - skip, dropIdx - skip);
            }
            if (this.isRefresh) {
                this.parent.notify(events.modelChanged, {
                    type: events.actionBegin, requestType: 'rowdraganddrop'
                });
            }
            for (var i = 0, len = selectedRecords.length; i < len; i++) {
                for (var j = 0, len1 = currentViewData.length; j < len1; j++) {
                    if (JSON.stringify(currentViewData[parseInt(j.toString(), 10)]) === JSON
                        .stringify(selectedRecords[parseInt(i.toString(), 10)])) {
                        selectedIndexes[parseInt(i.toString(), 10)] = j - skip;
                        break;
                    }
                }
            }
            this.selectedRowColls = selectedIndexes;
        };
        RowDD.prototype.stopTimer = function () {
            window.clearInterval(this.timer);
        };
        RowDD.prototype.onActionComplete = function (e) {
            this.parent.trigger(events.actionComplete, ej2_base_3.extend(e, { type: events.actionComplete, requestType: 'rowdraganddrop' }));
        };
        RowDD.prototype.initializeDrag = function () {
            var gObj = this.parent;
            this.draggable = new ej2_base_1.Draggable(gObj.element, {
                dragTarget: '.e-rowcelldrag, .e-rowdragdrop, .e-rowcell',
                distance: 5,
                helper: this.helper,
                dragStart: this.dragStart,
                drag: this.drag,
                dragStop: this.dragStop,
                isReplaceDragEle: this.isReplaceDragEle,
                isPreventSelect: false,
                isPreventScroll: true
            });
        };
        RowDD.prototype.updateScrollPostion = function (e) {
            var _this = this;
            var y = util_1.getPosition(e).y;
            var cliRect = this.isDropGrid.getContent().getBoundingClientRect();
            var rowHeight = this.isDropGrid.getRowHeight() - 15;
            var scrollElem = this.isDropGrid.getContent().firstElementChild;
            var virtualScrollbtm = this.parent.enableVirtualization ? 20 : 0;
            if (cliRect.top >= y) {
                var scrollPixel_1 = -(this.isDropGrid.getRowHeight());
                this.isOverflowBorder = false;
                this.timer = window.setInterval(function () { _this.setScrollDown(scrollElem, scrollPixel_1); }, 200);
            }
            else if (cliRect.top + this.isDropGrid.getContent().clientHeight - rowHeight - 33 - virtualScrollbtm <= y) {
                var scrollPixel_2 = (this.isDropGrid.getRowHeight());
                this.isOverflowBorder = false;
                this.timer = window.setInterval(function () { _this.setScrollDown(scrollElem, scrollPixel_2); }, 200);
            }
        };
        RowDD.prototype.setScrollDown = function (scrollElem, scrollPixel) {
            scrollElem.scrollTop = scrollElem.scrollTop + scrollPixel;
        };
        RowDD.prototype.moveDragRows = function (e, startedRow, targetRow) {
            var cloneElement = this.parent.element.querySelector('.e-cloneproperties');
            if (this.parent.element.classList.contains('e-childgrid')) {
                var parentGrid = this.getParentGrid(this.parent.element);
                cloneElement = parentGrid.querySelector('.e-cloneproperties');
            }
            var element = ej2_base_3.closest(e.target, 'tr');
            if (util_1.parentsUntil(element, 'e-grid') &&
                ((!this.parent.rowDropSettings.targetID &&
                    util_1.parentsUntil(cloneElement.parentElement, 'e-grid').id === util_1.parentsUntil(element, 'e-grid').id) || this.istargetGrid)) {
                var targetElement = element;
                Iif (!element) {
                    targetElement = startedRow;
                }
                this.setBorder(targetElement, e.event, startedRow, targetRow);
            }
        };
        RowDD.prototype.setBorder = function (element, event, startedRow, targetRow) {
            var node = this.parent.element;
            if (this.istargetGrid) {
                node = this.isDropGrid.element;
            }
            var cloneElement = this.parent.element.querySelector('.e-cloneproperties');
            if (this.parent.allowGrouping && this.parent.groupSettings.columns.length) {
                this.removeBorder(element);
            }
            else {
                this.removeFirstRowBorder(element);
                this.removeLastRowBorder(element);
            }
            Eif (util_1.parentsUntil(element, 'e-grid') && element.classList.contains(literals.row) && ((!this.parent.rowDropSettings.targetID &&
                util_1.parentsUntil(cloneElement.parentElement, 'e-grid').id === util_1.parentsUntil(element, 'e-grid').id) || this.istargetGrid)) {
                if (this.parent.allowGrouping && this.parent.groupSettings.columns && this.parent.groupSettings.columns.length) {
                    ej2_base_2.removeClass(node.querySelectorAll('.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse'), ['e-dragtop', 'e-dragright',
                        'e-dragbottom', 'e-dragleft']);
                }
                else {
                    ej2_base_2.removeClass(node.querySelectorAll('.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse'), ['e-dragborder']);
                }
                var rowElement = [];
                var targetRowIndex = parseInt(targetRow.getAttribute(literals.dataRowIndex), 10);
                if (targetRow && targetRowIndex === 0 &&
                    !(this.isNewRowAdded() && this.parent.editSettings.newRowPosition === 'Top')) {
                    if (this.parent.allowGrouping && this.parent.groupSettings.columns.length) {
                        element = targetRow;
                        rowElement = [].slice.call(element
                            .querySelectorAll('.e-groupcaption,.e-summarycell,.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse'));
                    }
                    else {
                        var div = this.parent.createElement('div', { className: 'e-firstrow-dragborder' });
                        var gridheaderEle = this.isDropGrid.getHeaderContent();
                        gridheaderEle.classList.add('e-grid-relative');
                        div.style.width = node.offsetWidth - this.getScrollWidth() + 'px';
                        Eif (!gridheaderEle.getElementsByClassName('e-firstrow-dragborder').length) {
                            Iif (this.parent.frozenRows) {
                                if (this.parent.isFrozenGrid()) {
                                    div.style.width = this.parent.getContent().firstElementChild.scrollWidth + 'px';
                                }
                                gridheaderEle.querySelector('thead').appendChild(div);
                                div.style.position = 'relative';
                            }
                            else {
                                gridheaderEle.appendChild(div);
                            }
                        }
                    }
                }
                else if (this.parent.rowDropSettings.targetID && targetRow) {
                    element = this.isDropGrid.getRowByIndex(targetRowIndex - 1);
                    rowElement = [].slice.call(element.querySelectorAll('.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse'));
                }
                else if (targetRow && parseInt(startedRow.getAttribute(literals.dataRowIndex), 10) > targetRowIndex) {
                    if (this.parent.enableVirtualization && this.parent.allowGrouping && this.parent.groupSettings.columns.length) {
                        targetRowIndex = this.parent.getDataRows().indexOf(targetRow);
                    }
                    if (this.parent.allowGrouping && this.parent.groupSettings.columns.length) {
                        element = targetRow;
                        rowElement = [].slice.call(element
                            .querySelectorAll(".e-groupcaption,.e-summarycell,.e-rowcell:not(.e-hide),.e-rowdragdrop:not(.e-hide),\n                        .e-detailrowcollapse:not(.e-hide)"));
                    }
                    else {
                        Iif (targetRowIndex === 0 && this.isNewRowAdded() && this.parent.editSettings.newRowPosition === 'Top') {
                            element = this.parent.element.querySelector('.e-row.e-addedrow tr');
                        }
                        else {
                            element = this.parent.getRowByIndex(targetRowIndex - 1);
                        }
                        rowElement = [].slice.call(element.querySelectorAll('.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse,.e-dragindentcell'));
                    }
                }
                else {
                    rowElement = [].slice.call(element.querySelectorAll('.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse'));
                }
                if (rowElement.length > 0) {
                    if (this.parent.allowGrouping && this.parent.groupSettings.columns && this.parent.groupSettings.columns.length) {
                        this.groupRowDDIndicator(rowElement, true);
                    }
                    else {
                        util_1.addRemoveActiveClasses(rowElement, true, 'e-dragborder');
                    }
                }
            }
        };
        RowDD.prototype.getScrollWidth = function () {
            var scrollElem = this.parent.getContent().firstElementChild;
            return scrollElem.scrollWidth > scrollElem.offsetWidth ? scroll_1.Scroll.getScrollBarWidth() : 0;
        };
        RowDD.prototype.removeFirstRowBorder = function (element) {
            if (this.isDropGrid.element.getElementsByClassName('e-firstrow-dragborder').length > 0 && element &&
                (element.rowIndex !== 0 || element.classList.contains('e-columnheader'))) {
                ej2_base_3.remove(this.isDropGrid.element.getElementsByClassName('e-firstrow-dragborder')[0]);
            }
            else {
                var addNewRow = this.parent.element.querySelector('.e-row.e-addedrow tr');
                Iif (addNewRow && addNewRow.querySelector('.e-dragborder')) {
                    var rowElement = [].slice.call(addNewRow.
                        querySelectorAll('.e-rowcell,.e-rowdragdrop,.e-detailrowcollapse,.e-dragindentcell'));
                    util_1.addRemoveActiveClasses(rowElement, false, 'e-dragborder');
                }
            }
        };
        RowDD.prototype.removeLastRowBorder = function (element) {
            var islastRowIndex;
            if (this.parent.enableVirtualization) {
                islastRowIndex = element && parseInt(element.getAttribute(literals.dataRowIndex), 10) !==
                    this.parent.renderModule.data.dataManager.dataSource.json.length - 1;
            }
            else {
                var rowIndex = this.parent.enableInfiniteScrolling && this.parent.infiniteScrollSettings.enableCache &&
                    !this.parent.groupSettings.enableLazyLoading ?
                    this.parent.pageSettings.currentPage * this.parent.pageSettings.pageSize - 1 :
                    this.parent.getCurrentViewRecords().length - 1;
                var lastRow = this.parent.getRowByIndex(rowIndex);
                islastRowIndex = element && lastRow && lastRow.getAttribute('data-uid') !== element.getAttribute('data-uid');
            }
            if (this.parent.element.getElementsByClassName('e-lastrow-dragborder').length > 0 && element && islastRowIndex) {
                ej2_base_3.remove(this.parent.element.getElementsByClassName('e-lastrow-dragborder')[0]);
            }
        };
        RowDD.prototype.removeBorder = function (element) {
            this.removeFirstRowBorder(element);
            if (!this.parent.rowDropSettings.targetID) {
                this.removeLastRowBorder(element);
            }
            if (this.parent.allowGrouping && this.parent.groupSettings.columns.length) {
                element = ([].slice.call(this.isDropGrid.getContentTable().querySelectorAll('tr'))).filter(function (row) {
                    return row.querySelector('td.e-dragtop.e-dragbottom');
                })[0];
            }
            else {
                element = (this.isDropGrid.getRows()).filter(function (row) { return row.querySelector('td.e-dragborder'); })[0];
            }
            if (element) {
                var rowElement = this.parent.allowGrouping && this.parent.groupSettings.columns.length ? [].slice.call(element
                    .querySelectorAll('.e-dragtop.e-dragbottom')) : [].slice.call(element.getElementsByClassName('e-dragborder'));
                if (this.parent.allowGrouping && this.parent.groupSettings.columns && this.parent.groupSettings.columns.length) {
                    this.groupRowDDIndicator(rowElement, false);
                }
                else {
                    util_1.addRemoveActiveClasses(rowElement, false, 'e-dragborder');
                }
            }
        };
        RowDD.prototype.getElementFromPosition = function (element, event) {
            var position = util_1.getPosition(event);
            element.style.display = 'none';
            var target = document.elementFromPoint(position.x, position.y);
            element.style.display = '';
            return target;
        };
        RowDD.prototype.onDataBound = function () {
            if (this.selectedRowColls.length > 0 && (this.parent.enableVirtualization || this.parent.allowRowDragAndDrop)) {
                this.parent.selectRows(this.selectedRowColls);
                this.selectedRowColls = [];
            }
        };
        RowDD.prototype.getTargetIdx = function (targetRow) {
            return targetRow ? parseInt(targetRow.getAttribute(literals.dataRowIndex), 10) : 0;
        };
        RowDD.prototype.singleRowDrop = function (e) {
            var targetRow = ej2_base_3.closest(e.target, 'tr');
            var srcControl = e.droppedElement.parentElement.ej2_instances[0];
            var currentIndex = targetRow ? targetRow.rowIndex : srcControl.currentViewData.length - 1;
            this.reorderRow(this.startedRowIndex, currentIndex);
        };
        RowDD.prototype.columnDrop = function (e) {
            var gObj = this.parent;
            if (e.droppedElement.getAttribute('action') !== 'grouping' &&
                (util_1.parentsUntil(e.target, literals.row) || util_1.parentsUntil(e.target, 'e-emptyrow') || util_1.parentsUntil(e.target, literals.gridContent))) {
                var targetRow = ej2_base_3.closest(e.target, 'tr');
                var srcControl = void 0;
                var currentIndex = void 0;
                var dragParentElement = document.querySelector('.e-drag-ref');
                if ((e.droppedElement.querySelector('tr').getAttribute('single-dragrow') !== 'true' &&
                    (e.droppedElement.parentElement.id === gObj.element.id || (dragParentElement
                        && dragParentElement.parentElement.id === gObj.element.id)))
                    || (e.droppedElement.querySelector('tr').getAttribute('single-dragrow') === 'true' &&
                        e.droppedElement.parentElement.id !== gObj.element.id)) {
                    return;
                }
                if (e.droppedElement.parentElement.id !== gObj.element.id) {
                    Iif (dragParentElement) {
                        srcControl = dragParentElement.parentElement.ej2_instances[0];
                        ej2_base_3.remove(dragParentElement);
                    }
                    else {
                        srcControl = e.droppedElement.parentElement.ej2_instances[0];
                    }
                }
                else Eif (this.isSingleRowDragDrop || e.droppedElement.querySelector('tr').getAttribute('single-dragrow') === 'true') {
                    this.singleRowDrop(e);
                    return;
                }
                Iif (srcControl.element.id !== gObj.element.id && srcControl.rowDropSettings.targetID !== gObj.element.id) {
                    return;
                }
                var records = srcControl.getSelectedRecords();
                var targetIndex = currentIndex = this.getTargetIdx(targetRow);
                Iif (e.target && e.target.classList.contains('e-content') && gObj.getCurrentViewRecords().length) {
                    var lastrow = gObj.getContentTable().querySelector('tr:last-child');
                    if (lastrow) {
                        targetIndex = currentIndex = parseInt(lastrow.getAttribute(literals.ariaRowIndex), 10);
                    }
                }
                if (isNaN(targetIndex)) {
                    targetIndex = currentIndex = 0;
                }
                Eif (gObj.allowPaging) {
                    targetIndex = targetIndex + (gObj.pageSettings.currentPage * gObj.pageSettings.pageSize) - gObj.pageSettings.pageSize;
                }
                gObj.notify(events.rowsAdded, { toIndex: targetIndex, records: records });
                gObj.notify(events.modelChanged, {
                    type: events.actionBegin, requestType: 'rowdraganddrop'
                });
                var selectedRows = srcControl.getSelectedRowIndexes();
                var skip = srcControl.allowPaging ?
                    (srcControl.pageSettings.currentPage * srcControl.pageSettings.pageSize) - srcControl.pageSettings.pageSize : 0;
                this.selectedRows = [];
                for (var i = 0, len = records.length; i < len; i++) {
                    this.selectedRows.push(skip + selectedRows[parseInt(i.toString(), 10)]);
                }
                srcControl.notify(events.rowsRemoved, { indexes: this.selectedRows, records: records });
                Iif (srcControl.dataSource instanceof ej2_data_1.DataManager && srcControl.dataSource.dataSource.offline) {
                    srcControl.notify(events.modelChanged, {
                        type: events.actionBegin, requestType: 'rowdraganddrop'
                    });
                }
            }
        };
        RowDD.prototype.reorderRow = function (fromIndexes, toIndex) {
            var gObj = this.parent;
            if (!gObj.groupSettings.columns.length) {
                var skip = gObj.allowPaging ?
                    (gObj.pageSettings.currentPage * gObj.pageSettings.pageSize) - gObj.pageSettings.pageSize : 0;
                var fromIndex = fromIndexes;
                toIndex = toIndex + skip;
                this.selectedRows = gObj.getSelectedRowIndexes();
                gObj.notify(events.rowPositionChanged, {
                    fromIndex: fromIndexes + skip,
                    toIndex: toIndex
                });
            }
        };
        RowDD.prototype.enableAfterRender = function (e) {
            if (e.module === this.getModuleName() && e.enable) {
                this.initializeDrag();
            }
        };
        RowDD.prototype.destroy = function () {
            var gridElement = this.parent.element;
            if (this.parent.isDestroyed || !gridElement || (!gridElement.querySelector('.' + literals.gridHeader) &&
                !gridElement.querySelector('.' + literals.gridContent))) {
                return;
            }
            this.draggable.destroy();
            this.parent.off(events.initialEnd, this.initializeDrag);
            this.parent.off(events.columnDrop, this.columnDrop);
            this.parent.off(events.rowDragAndDropComplete, this.onActionComplete);
            this.parent.removeEventListener(events.dataBound, this.onDataBoundFn);
            this.parent.off(events.uiUpdate, this.enableAfterRender);
            this.parent.off(events.destroy, this.destroy);
        };
        RowDD.prototype.getModuleName = function () {
            return 'rowDragAndDrop';
        };
        RowDD.prototype.processArgs = function (target) {
            var gObj = this.parent;
            var dragIdx = parseInt(this.startedRow.getAttribute(literals.dataRowIndex), 10);
            if ((gObj.getSelectedRecords().length > 0 && this.startedRow.cells[0].classList.contains('e-selectionbackground') === false)
                || gObj.getSelectedRecords().length === 0) {
                Iif (gObj.enableInfiniteScrolling && gObj.infiniteScrollSettings.enableCache) {
                    this.rows = [this.startedRow];
                }
                else {
                    this.rows = [gObj.getRowByIndex(dragIdx)];
                }
                this.rowData = [gObj.getRowInfo((this.startedRow).querySelector('.' + literals.rowCell)).rowData];
                Iif ((gObj.enableVirtualization || (gObj.enableInfiniteScrolling && gObj.infiniteScrollSettings.enableCache))
                    && gObj.allowGrouping && gObj.groupSettings.columns.length && gObj.getSelectedRows().length) {
                    this.rows = gObj.getSelectedRows();
                    this.rowData = Array.from(this.rows, function (row) { return gObj.getRowObjectFromUID(row.getAttribute('data-uid')).data; });
                }
            }
            else {
                this.rows = gObj.getSelectedRows();
                this.rowData = Array.from(this.rows, function (row) { return gObj.getRowObjectFromUID(row.getAttribute('data-uid')).data; });
            }
        };
        return RowDD;
    }());
    exports.RowDD = RowDD;
});