all files / treegrid/actions/ selection.js

91.96% Statements 309/336
85.71% Branches 252/294
92.59% Functions 25/27
91.96% Lines 309/336
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   621× 621× 621× 621× 621× 621×   11279×   621× 621× 621× 621× 621×   605× 603×     605×   200× 200× 200× 200× 200× 12× 12× 12× 12× 12×   188× 19×   19× 19× 19×   200×                 31× 31×     31×   1192× 1192× 1192× 1192× 1192× 1192× 6079× 75×     1192× 1192× 6060× 6060× 74×     1192×   1192× 1192× 50× 50× 50× 50× 50× 50× 50× 50×   50× 41×     1142× 24× 24× 24×       1734× 1734× 1734× 1734× 1734× 1734× 1734× 1734× 12×   1734×   1734× 1734×   1734× 1734× 1734× 1321× 1319×       413× 413× 413× 413× 413× 413× 413× 413×     37×       37× 42× 42× 42× 42× 42× 42× 42× 751× 751×     42× 42× 40×       46× 46× 46× 19×   46× 29× 29×     29× 29× 115× 114×     110×           47× 47× 142×   47×   716× 716× 716× 716× 551×   716×   45×   716× 716× 716× 716× 716× 1891× 1891× 1891× 1808× 191×   1617× 827×       716× 388×   328×     325×   233×     92×   716× 716× 455×       111× 111× 111× 111× 111× 14× 14× 12×   14×     11×         11×       111× 15×   15×     111× 111×           111×     111× 111× 20× 662× 436× 36×   400×     400× 400×     226× 226× 226× 226× 226× 226×           111×               111× 111× 111× 58× 43× 43×     15× 15×       53×     1570× 20861×   1570× 1570× 1570× 1570× 1570× 1570× 726× 726×   726×   726× 726×     1570× 1570×   1570× 1570× 643× 310×   643×   28×   643×   643×   538×   643×       927× 927× 927× 292×   927× 97× 97×     1570× 1570× 726× 726× 726×       385× 385× 385× 385× 385× 23× 18× 48× 48×       14×                 13×   12×   10× 10× 10×   10× 38×                                       38× 15×     23×       10×         49×   31×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-buttons", "@syncfusion/ej2-grids", "../base/constant", "../utils"], function (require, exports, ej2_base_1, ej2_buttons_1, ej2_grids_1, events, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Selection = (function () {
        function Selection(parent) {
            this.parent = parent;
            this.selectedItems = [];
            this.selectedIndexes = [];
            this.filteredList = [];
            this.searchingRecords = [];
            this.addEventListener();
        }
        Selection.prototype.getModuleName = function () {
            return 'selection';
        };
        Selection.prototype.addEventListener = function () {
            this.parent.on('dataBoundArg', this.headerCheckbox, this);
            this.parent.on('columnCheckbox', this.columnCheckbox, this);
            this.parent.on('updateGridActions', this.updateGridActions, this);
            this.parent.grid.on('colgroup-refresh', this.headerCheckbox, this);
            this.parent.on('checkboxSelection', this.checkboxSelection, this);
        };
        Selection.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off('dataBoundArg', this.headerCheckbox);
            this.parent.off('columnCheckbox', this.columnCheckbox);
            this.parent.grid.off('colgroup-refresh', this.headerCheckbox);
            this.parent.off('checkboxSelection', this.checkboxSelection);
            this.parent.off('updateGridActions', this.updateGridActions);
        };
        Selection.prototype.destroy = function () {
            this.removeEventListener();
        };
        Selection.prototype.checkboxSelection = function (args) {
            var _a;
            var target = ej2_grids_1.getObject('target', args);
            var checkWrap = ej2_grids_1.parentsUntil(target, 'e-checkbox-wrapper');
            var checkBox;
            if (checkWrap && checkWrap.querySelectorAll('.e-treecheckselect').length > 0) {
                checkBox = checkWrap.querySelector('input[type="checkbox"]');
                var rowIndex = [];
                rowIndex.push(target.closest('tr').rowIndex);
                this.selectCheckboxes(rowIndex);
                this.triggerChkChangeEvent(checkBox, checkBox.nextElementSibling.classList.contains('e-check'), target.closest('tr'));
            }
            else if (checkWrap && checkWrap.querySelectorAll('.e-treeselectall').length > 0 && this.parent.autoCheckHierarchy) {
                var checkBoxvalue = !checkWrap.querySelector('.e-frame').classList.contains('e-check')
                    && !checkWrap.querySelector('.e-frame').classList.contains('e-stop');
                this.headerSelection(checkBoxvalue);
                checkBox = checkWrap.querySelector('input[type="checkbox"]');
                this.triggerChkChangeEvent(checkBox, checkBoxvalue, target.closest('tr'));
            }
            Iif (!ej2_base_1.isNullOrUndefined(this.parent['parentQuery']) && this.parent.selectionSettings.persistSelection
                && this.parent['columnModel'].filter(function (col) { return col.type === 'checkbox'; }).length > 0
                && utils_1.isRemoteData(this.parent)) {
                if (this.parent['parentQuery'].length > 0) {
                    (_a = this.parent.query.queries).push.apply(_a, this.parent['parentQuery']);
                    this.parent['parentQuery'] = [];
                }
            }
        };
        Selection.prototype.triggerChkChangeEvent = function (checkBox, checkState, rowElement) {
            var data = this.parent.getCurrentViewRecords()[rowElement.rowIndex];
            var args = { checked: checkState, target: checkBox, rowElement: rowElement,
                rowData: checkBox.classList.contains('e-treeselectall')
                    ? this.parent.getCheckedRecords() : data };
            this.parent.trigger(events.checkboxChange, args);
        };
        Selection.prototype.getCheckboxcolumnIndex = function () {
            var mappingUid;
            var columnIndex;
            var stackedHeader = 'stackedHeader';
            var columnModel = 'columnModel';
            var columns = this.parent["" + stackedHeader] ? this.parent["" + columnModel] : (this.parent.columns);
            for (var col = 0; col < columns.length; col++) {
                if (columns[parseInt(col.toString(), 10)].showCheckbox) {
                    mappingUid = columns[parseInt(col.toString(), 10)].uid;
                }
            }
            var headerCelllength = this.parent.getHeaderContent().querySelectorAll('.e-headercelldiv').length;
            for (var j = 0; j < headerCelllength; j++) {
                var headercell = this.parent.getHeaderContent().querySelectorAll('.e-headercelldiv')[parseInt(j.toString(), 10)];
                if (headercell.getAttribute('e-mappinguid') === mappingUid) {
                    columnIndex = j;
                }
            }
            return columnIndex;
        };
        Selection.prototype.headerCheckbox = function () {
            this.columnIndex = this.getCheckboxcolumnIndex();
            if (this.columnIndex > -1 && this.parent.getHeaderContent().querySelectorAll('.e-treeselectall').length === 0) {
                var headerElement = this.parent.getHeaderContent().querySelectorAll('.e-headercelldiv')[this.columnIndex];
                var value = false;
                var rowChkBox = this.parent.createElement('input', { className: 'e-treeselectall', attrs: { 'type': 'checkbox' } });
                var checkWrap = ej2_buttons_1.createCheckBox(this.parent.createElement, false, { checked: value, label: ' ' });
                checkWrap.classList.add('e-hierarchycheckbox');
                checkWrap.insertBefore(rowChkBox.cloneNode(), checkWrap.firstChild);
                Eif (!ej2_base_1.isNullOrUndefined(headerElement)) {
                    headerElement.insertBefore(checkWrap, headerElement.firstChild);
                }
                if (this.parent.autoCheckHierarchy) {
                    this.headerSelection();
                }
            }
            else if (this.columnIndex > -1 && this.parent.getHeaderContent().querySelectorAll('.e-treeselectall').length > 0) {
                var checkWrap = this.parent.getHeaderContent().querySelectorAll('.e-checkbox-wrapper')[0];
                var checkBoxvalue = checkWrap.querySelector('.e-frame').classList.contains('e-check');
                if (this.parent.autoCheckHierarchy && checkBoxvalue) {
                    this.headerSelection(checkBoxvalue);
                }
            }
        };
        Selection.prototype.renderColumnCheckbox = function (args) {
            var rowChkBox = this.parent.createElement('input', { className: 'e-treecheckselect', attrs: { 'type': 'checkbox', 'aria-label': 'checkbox' } });
            var data = args.data;
            args.cell.classList.add('e-treegridcheckbox');
            args.cell.setAttribute('aria-label', 'checkbox');
            var value = (ej2_base_1.isNullOrUndefined(data.checkboxState) || data.checkboxState === 'uncheck') ? false : true;
            var checkWrap = ej2_buttons_1.createCheckBox(this.parent.createElement, false, { checked: value, label: ' ' });
            checkWrap.classList.add('e-hierarchycheckbox');
            if (this.parent.allowTextWrap) {
                checkWrap.querySelector('.e-frame').style.width = '18px';
            }
            if (data.checkboxState === 'indeterminate') {
                var checkbox = checkWrap.querySelectorAll('.e-frame')[0];
                ej2_base_1.removeClass([checkbox], ['e-check', 'e-stop', 'e-uncheck']);
                checkWrap.querySelector('.e-frame').classList.add('e-stop');
            }
            checkWrap.insertBefore(rowChkBox.cloneNode(), checkWrap.firstChild);
            return checkWrap;
        };
        Selection.prototype.columnCheckbox = function (container) {
            var checkWrap = this.renderColumnCheckbox(container);
            var containerELe = container.cell.querySelector('.e-treecolumn-container');
            if (!ej2_base_1.isNullOrUndefined(containerELe)) {
                if (!container.cell.querySelector('.e-hierarchycheckbox')) {
                    containerELe.insertBefore(checkWrap, containerELe.querySelectorAll('.e-treecell')[0]);
                }
            }
            else {
                var spanEle = this.parent.createElement('span', { className: 'e-treecheckbox' });
                var data = container.cell.innerHTML;
                container.cell.innerHTML = '';
                spanEle.innerHTML = data;
                var divEle = this.parent.createElement('div', { className: 'e-treecheckbox-container' });
                divEle.appendChild(checkWrap);
                divEle.appendChild(spanEle);
                container.cell.appendChild(divEle);
            }
        };
        Selection.prototype.selectCheckboxes = function (rowIndexes) {
            Iif (ej2_base_1.isNullOrUndefined(rowIndexes)) {
                var error = 'The provided value for the rowIndexes is undefined. Please ensure the rowIndexes contains number.';
                this.parent.trigger(events.actionFailure, { error: error });
            }
            for (var i = 0; i < rowIndexes.length; i++) {
                var record = this.parent.getCurrentViewRecords()[rowIndexes[parseInt(i.toString(), 10)]];
                var flatRecord = utils_1.getParentData(this.parent, record.uniqueID);
                record = flatRecord;
                var checkboxState = (record.checkboxState === 'uncheck') ? 'check' : 'uncheck';
                record.checkboxState = checkboxState;
                var keys = Object.keys(record);
                for (var j = 0; j < keys.length; j++) {
                    Eif (Object.prototype.hasOwnProperty.call(flatRecord, keys[parseInt(j.toString(), 10)])) {
                        flatRecord[keys[parseInt(j.toString(), 10)]] = record[keys[parseInt(j.toString(), 10)]];
                    }
                }
                this.traverSelection(record, checkboxState, false);
                if (this.parent.autoCheckHierarchy) {
                    this.headerSelection();
                }
            }
        };
        Selection.prototype.traverSelection = function (record, checkboxState, ischildItem) {
            var length = 0;
            this.updateSelectedItems(record, checkboxState);
            if (!ischildItem && record.parentItem && this.parent.autoCheckHierarchy) {
                this.updateParentSelection(record.parentItem);
            }
            if (record.childRecords && this.parent.autoCheckHierarchy) {
                var childRecords = record.childRecords;
                if (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) &&
                    this.parent.filterModule.filteredResult.length > 0 && this.parent.autoCheckHierarchy) {
                    childRecords = this.getFilteredChildRecords(childRecords);
                }
                length = childRecords.length;
                for (var count = 0; count < length; count++) {
                    if (!childRecords[parseInt(count.toString(), 10)].isSummaryRow) {
                        if (childRecords[parseInt(count.toString(), 10)].hasChildRecords) {
                            this.traverSelection(childRecords[parseInt(count.toString(), 10)], checkboxState, true);
                        }
                        else {
                            this.updateSelectedItems(childRecords[parseInt(count.toString(), 10)], checkboxState);
                        }
                    }
                }
            }
        };
        Selection.prototype.getFilteredChildRecords = function (childRecords) {
            var _this = this;
            var filteredChildRecords = childRecords.filter(function (e) {
                return _this.parent.filterModule.filteredResult.indexOf(e) > -1;
            });
            return filteredChildRecords;
        };
        Selection.prototype.updateParentSelection = function (parentRecord) {
            var length = 0;
            var childRecords = [];
            var record = utils_1.getParentData(this.parent, parentRecord.uniqueID);
            if (record && record.childRecords) {
                childRecords = record.childRecords;
            }
            if (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) &&
                this.parent.filterModule.filteredResult.length > 0 && this.parent.autoCheckHierarchy) {
                childRecords = this.getFilteredChildRecords(childRecords);
            }
            length = childRecords && childRecords.length;
            var indeter = 0;
            var checkChildRecords = 0;
            Eif (!ej2_base_1.isNullOrUndefined(record)) {
                for (var i = 0; i < childRecords.length; i++) {
                    var currentRecord = utils_1.getParentData(this.parent, childRecords[parseInt(i.toString(), 10)].uniqueID);
                    var checkBoxRecord = currentRecord;
                    if (!ej2_base_1.isNullOrUndefined(checkBoxRecord)) {
                        if (checkBoxRecord.checkboxState === 'indeterminate') {
                            indeter++;
                        }
                        else if (checkBoxRecord.checkboxState === 'check') {
                            checkChildRecords++;
                        }
                    }
                }
                if (indeter > 0 || (checkChildRecords > 0 && checkChildRecords !== length)) {
                    record.checkboxState = 'indeterminate';
                }
                else if (checkChildRecords === 0 && (!record.hasFilteredChildRecords || ej2_base_1.isNullOrUndefined(record.hasFilteredChildRecords)) && !ej2_base_1.isNullOrUndefined(this.parent['dataResults']['actionArgs']) &&
                    (this.parent['dataResults']['actionArgs'].requestType === 'searching' || this.parent['dataResults']['actionArgs'].requestType === 'filtering') && record.checkboxState === 'check') {
                    record.checkboxState = 'check';
                }
                else if ((checkChildRecords === 0 && indeter === 0) || (checkChildRecords === 0 && record.hasFilteredChildRecords && !ej2_base_1.isNullOrUndefined(this.parent['dataResults']['actionArgs']) &&
                    (this.parent['dataResults']['actionArgs'].requestType === 'searching' || this.parent['dataResults']['actionArgs'].requestType === 'filtering') && record.checkboxState === 'check')) {
                    record.checkboxState = 'uncheck';
                }
                else {
                    record.checkboxState = 'check';
                }
                this.updateSelectedItems(record, record.checkboxState);
                if (record.parentItem) {
                    this.updateParentSelection(record.parentItem);
                }
            }
        };
        Selection.prototype.headerSelection = function (checkAll) {
            var _this = this;
            var index = -1;
            var length = 0;
            var multiFilterCheckState = false;
            if (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) && this.parent.filterModule.filteredResult.length > 0) {
                var filterResult = this.parent.filterModule.filteredResult;
                if (this.filteredList.length === 0) {
                    this.filteredList = filterResult;
                }
                if (this.parent.grid.searchSettings.key.length) {
                    this.searchingRecords = filterResult;
                }
                else {
                    Iif (this.filteredList !== filterResult) {
                        this.filteredList = filterResult;
                        multiFilterCheckState = true;
                    }
                    else {
                        multiFilterCheckState = false;
                    }
                }
            }
            if (this.filteredList.length > 0) {
                if (!this.parent.filterSettings.columns.length && this.filteredList.length && !this.parent.grid.searchSettings.key.length) {
                    this.filteredList = [];
                }
                if (this.searchingRecords.length && !ej2_base_1.isNullOrUndefined(checkAll)) {
                    this.filteredList = this.searchingRecords;
                }
            }
            var data;
            Iif (!(ej2_base_1.isNullOrUndefined(this.parent.filterModule)) &&
                this.parent.filterModule.filteredResult.length === 0 && this.parent.getCurrentViewRecords().length === 0 &&
                this.parent.filterSettings.columns.length > 0) {
                data = this.filteredList;
            }
            else {
                data = (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) &&
                    (this.filteredList.length > 0)) ? this.filteredList : this.parent.flatData;
            }
            data = utils_1.isRemoteData(this.parent) ? this.parent.getCurrentViewRecords() : data;
            if (!ej2_base_1.isNullOrUndefined(checkAll)) {
                for (var i = 0; i < data.length; i++) {
                    if (checkAll) {
                        if (data[parseInt(i.toString(), 10)].checkboxState === 'check') {
                            continue;
                        }
                        Iif (multiFilterCheckState) {
                            continue;
                        }
                        data[parseInt(i.toString(), 10)].checkboxState = 'check';
                        this.updateSelectedItems(data[parseInt(i.toString(), 10)], data[parseInt(i.toString(), 10)].checkboxState);
                    }
                    else {
                        index = this.selectedItems.indexOf(data[parseInt(i.toString(), 10)]);
                        Eif (index > -1) {
                            data[parseInt(i.toString(), 10)].checkboxState = 'uncheck';
                            this.updateSelectedItems(data[parseInt(i.toString(), 10)], data[parseInt(i.toString(), 10)].checkboxState);
                            Eif (this.parent.autoCheckHierarchy) {
                                this.updateParentSelection(data[parseInt(i.toString(), 10)]);
                            }
                        }
                    }
                }
            }
            Iif (checkAll === false && this.parent.enableVirtualization) {
                this.selectedItems = [];
                this.selectedIndexes = [];
                data.filter(function (rec) {
                    rec.checkboxState = 'uncheck';
                    _this.updateSelectedItems(rec, rec.checkboxState);
                });
            }
            length = this.selectedItems.length;
            var checkbox = this.parent.getHeaderContent().querySelectorAll('.e-frame')[0];
            if (length > 0 && data.length > 0) {
                if (length !== data.length && !checkAll) {
                    ej2_base_1.removeClass([checkbox], ['e-check']);
                    checkbox.classList.add('e-stop');
                }
                else {
                    ej2_base_1.removeClass([checkbox], ['e-stop']);
                    checkbox.classList.add('e-check');
                }
            }
            else {
                ej2_base_1.removeClass([checkbox], ['e-check', 'e-stop']);
            }
        };
        Selection.prototype.updateSelectedItems = function (currentRecord, checkState) {
            var record = this.parent.grid.currentViewData.filter(function (e) {
                return e.uniqueID === currentRecord.uniqueID;
            });
            var checkedRecord;
            var recordIndex = this.parent.grid.currentViewData.indexOf(record[0]);
            var checkboxRecord = utils_1.getParentData(this.parent, currentRecord.uniqueID);
            var tr = this.parent.getRows()[parseInt(recordIndex.toString(), 10)];
            var checkbox;
            if (recordIndex > -1) {
                var movableTr = void 0;
                if (this.parent.frozenRows || this.parent.getFrozenColumns()) {
                    movableTr = this.parent.getDataRows()[parseInt(recordIndex.toString(), 10)];
                }
                checkbox = tr.querySelectorAll('.e-hierarchycheckbox .e-frame')[0] ? tr.querySelectorAll('.e-hierarchycheckbox .e-frame')[0]
                    : movableTr.querySelectorAll('.e-hierarchycheckbox .e-frame')[0];
                Eif (!ej2_base_1.isNullOrUndefined(checkbox)) {
                    ej2_base_1.removeClass([checkbox], ['e-check', 'e-stop', 'e-uncheck']);
                }
            }
            checkedRecord = checkboxRecord;
            if (ej2_base_1.isNullOrUndefined(checkedRecord)) {
                checkedRecord = currentRecord;
            }
            checkedRecord.checkboxState = checkState;
            if (checkState === 'check' && ej2_base_1.isNullOrUndefined(currentRecord.isSummaryRow)) {
                if (recordIndex !== -1 && this.selectedIndexes.indexOf(recordIndex) === -1) {
                    this.selectedIndexes.push(recordIndex);
                }
                if (this.selectedItems.indexOf(checkedRecord) === -1 && (recordIndex !== -1 &&
                    (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) && this.parent.filterModule.filteredResult.length > 0))) {
                    this.selectedItems.push(checkedRecord);
                }
                if (this.selectedItems.indexOf(checkedRecord) === -1 && (this.parent.enableVirtualization || this.parent.allowPaging) && ((!ej2_base_1.isNullOrUndefined(this.parent.filterModule) && this.parent.filterModule.filteredResult.length > 0))) {
                    this.selectedItems.push(checkedRecord);
                }
                if (this.selectedItems.indexOf(checkedRecord) === -1 && (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) &&
                    this.parent.filterModule.filteredResult.length === 0)) {
                    this.selectedItems.push(checkedRecord);
                }
                Iif (this.selectedItems.indexOf(checkedRecord) === -1 && ej2_base_1.isNullOrUndefined(this.parent.filterModule)) {
                    this.selectedItems.push(checkedRecord);
                }
            }
            else Eif ((checkState === 'uncheck' || checkState === 'indeterminate') && ej2_base_1.isNullOrUndefined(currentRecord.isSummaryRow)) {
                var index = this.selectedItems.indexOf(checkedRecord);
                if (index !== -1) {
                    this.selectedItems.splice(index, 1);
                }
                if (this.selectedIndexes.indexOf(recordIndex) !== -1) {
                    var checkedIndex = this.selectedIndexes.indexOf(recordIndex);
                    this.selectedIndexes.splice(checkedIndex, 1);
                }
            }
            var checkBoxclass = checkState === 'indeterminate' ? 'e-stop' : 'e-' + checkState;
            if (recordIndex > -1) {
                Eif (!ej2_base_1.isNullOrUndefined(checkbox)) {
                    checkbox.classList.add(checkBoxclass);
                    tr.querySelector('.e-treecheckselect').setAttribute('aria-checked', checkState === 'check' ? 'true' : checkState === 'uncheck' ? 'false' : 'mixed');
                }
            }
        };
        Selection.prototype.updateGridActions = function (args) {
            var _this = this;
            var requestType = args.requestType;
            var childData;
            var childLength;
            if (utils_1.isCheckboxcolumn(this.parent)) {
                if (this.parent.autoCheckHierarchy) {
                    if ((requestType === 'sorting' || requestType === 'paging')) {
                        var rows = this.parent.grid.getRows();
                        childData = this.parent.getCurrentViewRecords();
                        childLength = childData.length;
                        this.selectedIndexes = [];
                        for (var i = 0; i < childLength; i++) {
                            Eif (!rows[parseInt(i.toString(), 10)].classList.contains('e-summaryrow')) {
                                this.updateSelectedItems(childData[parseInt(i.toString(), 10)], childData[parseInt(i.toString(), 10)].checkboxState);
                            }
                        }
                    }
                    else if (requestType === 'delete' || args.action === 'add') {
                        var updatedData = [];
                        Eif (requestType === 'delete') {
                            updatedData = args.data;
                        }
                        else {
                            updatedData.push(args.data);
                        }
                        for (var i = 0; i < updatedData.length; i++) {
                            Eif (requestType === 'delete') {
                                var index = this.parent.flatData.indexOf(updatedData[parseInt(i.toString(), 10)]);
                                var checkedIndex = this.selectedIndexes.indexOf(index);
                                this.selectedIndexes.splice(checkedIndex, 1);
                                this.updateSelectedItems(updatedData[parseInt(i.toString(), 10)], 'uncheck');
                            }
                            Eif (!ej2_base_1.isNullOrUndefined(updatedData[parseInt(i.toString(), 10)].parentItem)) {
                                this.updateParentSelection(updatedData[parseInt(i.toString(), 10)].parentItem);
                            }
                        }
                    }
                    else if (args.requestType === 'add' && this.parent.autoCheckHierarchy) {
                        args.data.checkboxState = 'uncheck';
                    }
                    else if (requestType === 'filtering' || requestType === 'searching' || requestType === 'refresh'
                        && !utils_1.isRemoteData(this.parent)) {
                        this.selectedItems = [];
                        this.selectedIndexes = [];
                        childData = (!ej2_base_1.isNullOrUndefined(this.parent.filterModule) && this.parent.filterModule.filteredResult.length > 0) ?
                            this.parent.filterModule.filteredResult : this.parent.flatData;
                        childData.forEach(function (record) {
                            Iif (_this.parent.enableVirtualization) {
                                if (record.hasChildRecords && record.childRecords.length > 0) {
                                    _this.updateParentSelection(record);
                                }
                                else {
                                    _this.updateSelectedItems(record, record.checkboxState);
                                }
                                var child = utils_1.findChildrenRecords(record);
                                child = _this.getFilteredChildRecords(child);
                                for (var i = 0; i < child.length; i++) {
                                    if (child[parseInt(i.toString(), 10)].hasChildRecords) {
                                        _this.updateParentSelection(child[parseInt(i.toString(), 10)]);
                                    }
                                    else if (!(child[parseInt(i.toString(), 10)].hasChildRecords) &&
                                        !ej2_base_1.isNullOrUndefined(child[parseInt(i.toString(), 10)])) {
                                        _this.updateSelectedItems(child[parseInt(i.toString(), 10)], child[parseInt(i.toString(), 10)].checkboxState);
                                    }
                                }
                            }
                            else {
                                if (record.hasChildRecords) {
                                    _this.updateParentSelection(record);
                                }
                                else {
                                    _this.updateSelectedItems(record, record.checkboxState);
                                }
                            }
                        });
                        this.headerSelection();
                    }
                }
            }
        };
        Selection.prototype.getCheckedrecords = function () {
            return this.selectedItems;
        };
        Selection.prototype.getCheckedRowIndexes = function () {
            return this.selectedIndexes;
        };
        return Selection;
    }());
    exports.Selection = Selection;
});