all files / treegrid/base/ data.js

73.23% Statements 413/564
64.41% Branches 333/517
82.05% Functions 32/39
73.32% Lines 404/551
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   622× 622× 622× 622× 622× 622× 622× 622× 622× 622× 622×   622× 622× 622× 622× 622×   606× 605×     606×         658× 658×     658× 658× 15× 15× 13×   13× 13× 13× 13× 13×     13×                                                     643× 638×     638× 638× 638× 527×     111× 111× 5097× 5097× 5097× 5089×       638× 111× 111×   111× 1210× 1210× 1210× 1102× 1097× 1097× 1097×     113×   111×   638× 11× 11× 11×     627×   638×   111× 111× 4733× 4733× 3565×     1168× 1168×     111×   32× 32×     32× 32×     32×           32× 30× 416×   20×   416× 80× 80× 80× 3200×       80×     80×       416× 336× 336× 336× 336× 336×     336× 336×   331×   336×     30× 30× 416×               32×     32×     30×   32×             32×                                                                                                                                                                     10×     10×             10× 10×                     10×                                             10× 10× 10× 10× 10×   10× 10× 10× 10×             10× 10×                                                                         10×                                                               41× 41×             25752× 25752× 25752× 68352× 68352× 68352× 68352× 68352× 68345×   68352× 68352× 68352× 68352× 68352× 12545×     55807×   68352×   25138×   727×     24411×       68352×     68352× 1165×   68352× 68352× 68352× 47998× 47998× 47998× 47998× 3929×   47998× 47998× 47998×   68352× 68345×   68352× 68352× 68352×                                     68352× 68347× 68347×   68352× 19186×   68352× 25125× 25125×   68352×   25752×   1209× 1209× 1209× 1209× 1209× 1209× 1209× 1209× 1209× 1209× 1209× 1209× 1209×     1209× 1160× 1160× 1160× 1160× 142×   1160× 1160×     1208×     1207×     1208× 1208×   1208× 1208× 1208× 1208× 1208× 1069× 1069×   1208×     92×   121× 121× 92× 92× 92× 92× 92× 92×           1208×   37× 37×   62× 37×   1208× 70× 70× 70× 70× 70× 73× 73×   73×     73×   70× 70×           70× 70× 70× 70× 70× 70× 70×     1208×   1208× 1208× 1208× 1208× 1208× 1208×   1208×   265× 265× 265×     943×   165× 165× 165× 165×   1208× 1208× 1208×   126× 126× 126×       1208× 1208×   523×   1160× 126×   1159× 57×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "@syncfusion/ej2-popups", "@syncfusion/ej2-grids", "../utils", "./constant"], function (require, exports, ej2_base_1, ej2_data_1, ej2_popups_1, ej2_grids_1, utils_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DataManipulation = (function () {
        function DataManipulation(grid) {
            this.addedRecords = 'addedRecords';
            this.parent = grid;
            this.parentItems = [];
            this.taskIds = [];
            this.hierarchyData = [];
            this.storedIndex = -1;
            this.sortedData = [];
            this.isSortAction = false;
            this.addEventListener();
            this.dataResults = {};
            this.isSelfReference = !ej2_base_1.isNullOrUndefined(this.parent.parentIdMapping);
        }
        DataManipulation.prototype.addEventListener = function () {
            this.parent.on('updateRemoteLevel', this.updateParentRemoteData, this);
            this.parent.grid.on('sorting-begin', this.beginSorting, this);
            this.parent.on('updateAction', this.updateData, this);
            this.parent.on(events.remoteExpand, this.collectExpandingRecs, this);
            this.parent.on('dataProcessor', this.dataProcessor, this);
        };
        DataManipulation.prototype.removeEventListener = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(events.remoteExpand, this.collectExpandingRecs);
            this.parent.off('updateRemoteLevel', this.updateParentRemoteData);
            this.parent.off('updateAction', this.updateData);
            this.parent.off('dataProcessor', this.dataProcessor);
            this.parent.grid.off('sorting-begin', this.beginSorting);
        };
        DataManipulation.prototype.destroy = function () {
            this.removeEventListener();
        };
        DataManipulation.prototype.isRemote = function () {
            Eif (!(this.parent.dataSource instanceof ej2_data_1.DataManager)) {
                return false;
            }
            return true;
        };
        DataManipulation.prototype.convertToFlatData = function (data) {
            var _this = this;
            this.parent.flatData = (!ej2_base_1.isNullOrUndefined(data) && Object.keys(data).length === 0
                && !(this.parent.dataSource instanceof ej2_data_1.DataManager) ?
                this.parent.dataSource : []);
            this.parent.parentData = [];
            if ((utils_1.isRemoteData(this.parent) && !utils_1.isOffline(this.parent)) && data instanceof ej2_data_1.DataManager && !(data instanceof Array)) {
                var dm = this.parent.dataSource;
                if (this.parent.parentIdMapping) {
                    this.parent.query = ej2_base_1.isNullOrUndefined(this.parent.query) ?
                        new ej2_data_1.Query() : this.parent.query;
                    Eif (this.parent.parentIdMapping) {
                        var filterKey = this.parent.query.params.filter(function (param) { return param.key === 'IdMapping'; });
                        Eif (this.parent.initialRender && !filterKey.length) {
                            this.parent.query.where(this.parent.parentIdMapping, 'equal', null);
                            this.parent.query.addParams('IdMapping', this.parent.idMapping);
                        }
                    }
                    Iif (!this.parent.hasChildMapping) {
                        var qry = this.parent.query.clone();
                        qry.queries = [];
                        qry = qry.select([this.parent.parentIdMapping]);
                        qry.isCountRequired = true;
                        dm.executeQuery(qry).then(function (e) {
                            _this.parentItems = ej2_data_1.DataUtil.distinct(e.result, _this.parent.parentIdMapping, false);
                            var req;
                            if (e.result) {
                                req = 0;
                            }
                            else {
                                req = 1;
                            }
                            if (req === 0) {
                                ej2_base_1.setValue('grid.contentModule.isLoaded', true, _this.parent);
                                if (!ej2_base_1.isNullOrUndefined(_this.zerothLevelData)) {
                                    ej2_base_1.setValue('cancel', false, _this.zerothLevelData);
                                    ej2_base_1.getValue('grid.renderModule', _this.parent).dataManagerSuccess(_this.zerothLevelData);
                                    _this.zerothLevelData = null;
                                }
                                _this.parent.grid.hideSpinner();
                            }
                        });
                    }
                }
            }
            else if (data instanceof Array) {
                this.convertJSONData(data);
            }
        };
        DataManipulation.prototype.convertJSONData = function (data) {
            this.hierarchyData = [];
            this.taskIds = [];
            if (!this.parent.idMapping) {
                this.hierarchyData = data;
            }
            else {
                var keys = Object.keys(data);
                for (var i = 0; i < keys.length; i++) {
                    var tempData = data[parseInt(i.toString(), 10)];
                    this.hierarchyData.push(ej2_base_1.extend({}, tempData));
                    if (!ej2_base_1.isNullOrUndefined(tempData[this.parent.idMapping])) {
                        this.taskIds.push(tempData[this.parent.idMapping]);
                    }
                }
            }
            if (this.isSelfReference) {
                var selfData = [];
                var mappingData = new ej2_data_1.DataManager(this.hierarchyData).executeLocal(new ej2_data_1.Query()
                    .group(this.parent.parentIdMapping));
                for (var i = 0; i < mappingData.length; i++) {
                    var groupData = mappingData[parseInt(i.toString(), 10)];
                    var index = this.taskIds.indexOf(groupData.key);
                    if (!ej2_base_1.isNullOrUndefined(groupData.key)) {
                        if (index > -1) {
                            var childData = (groupData.items);
                            this.hierarchyData[parseInt(index.toString(), 10)][this.parent.childMapping] = childData;
                            continue;
                        }
                    }
                    selfData.push.apply(selfData, groupData.items);
                }
                this.hierarchyData = this.selfReferenceUpdate(selfData);
            }
            if (!Object.keys(this.hierarchyData).length) {
                var isGantt = 'isGantt';
                var referenceData = !(this.parent.dataSource instanceof ej2_data_1.DataManager) && this.parent["" + isGantt];
                this.parent.flatData = referenceData ? (this.parent.dataSource) : [];
            }
            else {
                this.createRecords(this.hierarchyData);
            }
            this.storedIndex = -1;
        };
        DataManipulation.prototype.selfReferenceUpdate = function (selfData) {
            var result = [];
            while (this.hierarchyData.length > 0 && selfData.length > 0) {
                var index = selfData.indexOf(this.hierarchyData[0]);
                if (index === -1) {
                    this.hierarchyData.shift();
                }
                else {
                    result.push(this.hierarchyData.shift());
                    selfData.splice(index, 1);
                }
            }
            return result;
        };
        DataManipulation.prototype.updateParentRemoteData = function (args) {
            var actionArgs = 'actionArgs';
            Iif (utils_1.isRemoteData(this.parent) && this.parent.enableVirtualization && args["" + actionArgs].requestType === 'virtualscroll') {
                this.parent.hideSpinner();
            }
            var records = args.result;
            Iif (utils_1.isRemoteData(this.parent) && this.parent.enableVirtualization && (args["" + actionArgs].requestType === 'virtualscroll' || args["" + actionArgs].action === 'clearFilter' || args["" + actionArgs].searchString === '')) {
                this.parent.query.expands = [];
            }
            Iif (!this.parent.hasChildMapping && !this.parentItems.length &&
                (this.parent.loadChildOnDemand)) {
                this.zerothLevelData = args;
                ej2_base_1.setValue('cancel', true, args);
            }
            else {
                if (this.parent.loadChildOnDemand) {
                    var _loop_1 = function (rec) {
                        if (utils_1.isCountRequired(this_1.parent) && records[parseInt(rec.toString(), 10)].hasChildRecords &&
                            this_1.parent.initialRender) {
                            records[parseInt(rec.toString(), 10)].expanded = false;
                        }
                        if (utils_1.isRemoteData(this_1.parent) && this_1.parent.enableVirtualization) {
                            var childRecords_1 = [];
                            var parent_1 = this_1.parent;
                            records.filter(function (e) {
                                Iif (e["" + parent_1.parentIdMapping] === records[parseInt(rec.toString(), 10)]["" + parent_1.idMapping]) {
                                    childRecords_1.push(e);
                                }
                            });
                            Iif (childRecords_1.length) {
                                records[parseInt(rec.toString(), 10)].expanded = true;
                            }
                            else Iif (records[parseInt(rec.toString(), 10)].hasChildRecords) {
                                records[parseInt(rec.toString(), 10)].expanded = false;
                            }
                        }
                        if (ej2_base_1.isNullOrUndefined(records[parseInt(rec.toString(), 10)].index)) {
                            records[parseInt(rec.toString(), 10)].taskData = ej2_base_1.extend({}, records[parseInt(rec.toString(), 10)]);
                            records[parseInt(rec.toString(), 10)].uniqueID = ej2_grids_1.getUid(this_1.parent.element.id + '_data_');
                            ej2_base_1.setValue('uniqueIDCollection.' + records[parseInt(rec.toString(), 10)].uniqueID, records[parseInt(rec.toString(), 10)], this_1.parent);
                            records[parseInt(rec.toString(), 10)].level = 0;
                            Iif (utils_1.isRemoteData(this_1.parent) && this_1.parent.enableVirtualization && records[parseInt(rec.toString(), 10)]["" + this_1.parent.parentIdMapping] && records[parseInt(rec.toString(), 10)].level === 0) {
                                records[parseInt(rec.toString(), 10)].level = records[parseInt(rec.toString(), 10)].level + 1;
                            }
                            records[parseInt(rec.toString(), 10)].index = Math.ceil(Math.random() * 1000);
                            if ((records[parseInt(rec.toString(), 10)][this_1.parent.hasChildMapping] ||
                                this_1.parentItems.indexOf(records[parseInt(rec.toString(), 10)][this_1.parent.idMapping]) !== -1)) {
                                records[parseInt(rec.toString(), 10)].hasChildRecords = true;
                            }
                            records[parseInt(rec.toString(), 10)].checkboxState = 'uncheck';
                        }
                    };
                    var this_1 = this;
                    for (var rec = 0; rec < records.length; rec++) {
                        _loop_1(rec);
                    }
                }
                else {
                    var dataResults = 'dataResults';
                    var expandRecord = 'expandRecord';
                    Eif (!ej2_base_1.isNullOrUndefined(records) && !((!this.parent.loadChildOnDemand) && utils_1.isCountRequired(this.parent) && !ej2_base_1.isNullOrUndefined(this.parent["" + dataResults]["" + expandRecord])) &&
                        !(utils_1.isRemoteData(this.parent) && !this.parent.loadChildOnDemand && args["" + actionArgs].isExpandCollapse && this.parent.enableVirtualization)) {
                        this.convertToFlatData(records);
                    }
                }
            }
            Iif (utils_1.isRemoteData(this.parent) && !this.parent.loadChildOnDemand && args["" + actionArgs].isExpandCollapse && this.parent.enableVirtualization) {
                args.result = records;
            }
            else if (utils_1.isRemoteData(this.parent) && this.parent.enableVirtualization && this.parent.loadChildOnDemand) {
                args.result = records;
            }
            else {
                args.result = !this.parent.loadChildOnDemand ? this.parent.flatData : records;
            }
            Iif (utils_1.isRemoteData(this.parent) && this.parent.enableVirtualization && !this.parent.loadChildOnDemand
                && this.parent.grid.aggregates.length && this.parent.grid.sortSettings.columns.length === 0
                && this.parent.grid.filterSettings.columns.length === 0 && !this.parent.grid.searchSettings.key.length) {
                var query = 'query';
                var summaryQuery = args["" + query].queries.filter(function (q) { return q.fn === 'onAggregates'; });
                args.result = this.parent.summaryModule.calculateSummaryValue(summaryQuery, this.parent.flatData, true);
            }
            this.parent.notify('updateResults', args);
        };
        DataManipulation.prototype.collectExpandingRecs = function (rowDetails, isChild) {
            var gridRows = this.parent.getRows();
            var name = 'name';
            Iif (this.parent.rowTemplate) {
                var rows = this.parent.getContentTable().rows;
                gridRows = [].slice.call(rows);
            }
            var childRecord;
            if (rowDetails.rows.length > 0) {
                Eif (!isChild) {
                    rowDetails.record.expanded = true;
                }
                for (var i = 0; i < rowDetails.rows.length; i++) {
                    this.parent['toggleRowVisibility'](rowDetails.rows[parseInt(i.toString(), 10)], 'e-childrow-visible');
                    Eif (!this.parent.loadChildOnDemand) {
                        var targetEle = rowDetails.rows[parseInt(i.toString(), 10)].getElementsByClassName('e-treegridcollapse')[0];
                        childRecord = this.parent.rowTemplate ?
                            this.parent.grid.getCurrentViewRecords()[rowDetails.rows[parseInt(i.toString(), 10)].rowIndex] :
                            this.parent.grid.getRowObjectFromUID(rowDetails.rows[parseInt(i.toString(), 10)].getAttribute('data-Uid')).data;
                        Iif (!ej2_base_1.isNullOrUndefined(targetEle) && childRecord.expanded) {
                            ej2_base_1.addClass([targetEle], 'e-treegridexpand');
                            ej2_base_1.removeClass([targetEle], 'e-treegridcollapse');
                        }
                        var childRows = [];
                        childRows = gridRows.filter(function (r) {
                            return r.querySelector('.e-gridrowindex' + childRecord.index + 'level' + (childRecord.level + 1));
                        });
                        Iif (childRows.length && childRecord.expanded) {
                            this.collectExpandingRecs({ record: childRecord, rows: childRows, parentRow: rowDetails.parentRow }, true);
                        }
                    }
                    var expandingTd = rowDetails.rows[parseInt(i.toString(), 10)].querySelector('.e-detailrowcollapse');
                    Iif (!ej2_base_1.isNullOrUndefined(expandingTd)) {
                        this.parent.grid.detailRowModule.expand(expandingTd);
                    }
                }
            }
            else {
                this.fetchRemoteChildData({ action: rowDetails["" + name], record: rowDetails.record, rows: rowDetails.rows, parentRow: rowDetails.parentRow });
            }
        };
        DataManipulation.prototype.fetchRemoteChildData = function (rowDetails) {
            var _this = this;
            var args = { row: rowDetails.parentRow, data: rowDetails.record };
            var dm = this.parent.dataSource;
            var qry = this.parent.grid.getDataModule().generateQuery();
            var clonequries = qry.queries.filter(function (e) { return e.fn !== 'onPage' && e.fn !== 'onWhere'; });
            qry.queries = clonequries;
            qry.isCountRequired = true;
            var idMappingValue = parseInt(rowDetails.record[this.parent.idMapping], 10);
            Iif (isNaN(idMappingValue)) {
                idMappingValue = rowDetails.record[this.parent.idMapping].toString();
            }
            Iif (this.parent.enableVirtualization && rowDetails.action === 'remoteExpand') {
                qry.take(this.parent.pageSettings.pageSize);
                var expandDetail = [];
                expandDetail.push('ExpandingAction', idMappingValue.toString());
                qry.expand(expandDetail);
            }
            else Iif (this.parent.enableVirtualization && rowDetails.action === 'collapse') {
                qry.take(this.parent.grid.pageSettings.pageSize);
                var expandDetail = [];
                expandDetail.push('CollapsingAction', idMappingValue.toString());
                qry.expand(expandDetail);
            }
            qry.where(this.parent.parentIdMapping, 'equal', rowDetails.record[this.parent.idMapping]);
            Iif (rowDetails.action === 'remoteExpand' && this.parent.grid.filterModule && this.parent.grid.filterModule['value']) {
                var filterqry = this.parent.grid.getDataModule().generateQuery().queries.filter(function (e) { return e.fn !== 'onPage' && typeof e.e.predicates !== 'undefined'; });
                qry.queries.push(filterqry[0]);
            }
            ej2_popups_1.showSpinner(this.parent.element);
            dm.executeQuery(qry).then(function (e) {
                var remoteExpandedData = 'remoteExpandedData';
                var remoteCollapsedData = 'remoteCollapsedData';
                var level = 'level';
                var datas = _this.parent.grid.currentViewData.slice();
                var inx;
                var idMapping = _this.parent.idMapping;
                Iif (_this.parent['isGantt'] && _this.parent.loadChildOnDemand && _this.parent.hasChildMapping) {
                    for (var i = 0; i < _this.parent.grid.currentViewData.length; i++) {
                        if (rowDetails.record[idMapping] === _this.parent.grid.currentViewData[i][idMapping]) {
                            inx = i;
                            break;
                        }
                    }
                }
                else {
                    inx = datas.indexOf(rowDetails.record);
                }
                Iif (_this.parent.enableVirtualization && (rowDetails.action === 'collapse' || rowDetails.action === 'remoteExpand')) {
                    datas = [];
                    for (var i = 0; i < inx; i++) {
                        datas.push(_this.parent.grid.currentViewData[parseInt(i.toString(), 10)]);
                    }
                }
                Iif (inx === -1) {
                    _this.parent.grid.getRowsObject().forEach(function (rows) {
                        if (rows.data.uniqueID === rowDetails.record.uniqueID) {
                            inx = rows.index;
                        }
                    });
                }
                var haveChild = ej2_grids_1.getObject('actual.nextLevel', e);
                var result = e.result;
                var resultChildData = [];
                Iif (rowDetails.action === 'remoteExpand' && _this.parent.grid.filterModule && _this.parent.grid.filterModule['value']) {
                    for (var i = 0; i < datas.length; i++) {
                        if (Object.prototype.hasOwnProperty.call(datas[parseInt(i.toString(), 10)], _this.parent.parentIdMapping) && datas[parseInt(i.toString(), 10)]['' + _this.parent.parentIdMapping] !== null && datas[parseInt(i.toString(), 10)].level === 0) {
                            datas.splice(i, 1);
                            i--;
                        }
                    }
                    for (var i = 0; i < result.length; i++) {
                        if (rowDetails.record['' + _this.parent.idMapping] !== result[parseInt(i.toString(), 10)]['' + _this.parent.idMapping] &&
                            rowDetails.record['' + _this.parent.idMapping] === result[parseInt(i.toString(), 10)]['' + _this.parent.parentIdMapping]) {
                            if (Object.prototype.hasOwnProperty.call(result, i)) {
                                resultChildData.push(result[parseInt(i.toString(), 10)]);
                            }
                        }
                    }
                    result = resultChildData;
                }
                Iif (_this.parent.enableVirtualization && rowDetails.action === 'remoteExpand') {
                    rowDetails.record.childRecords = [];
                    for (var i = 0; i < result.length; i++) {
                        if (rowDetails.record['' + _this.parent.idMapping] !== result[parseInt(i.toString(), 10)]['' + _this.parent.idMapping] &&
                            rowDetails.record['' + _this.parent.idMapping] === result[parseInt(i.toString(), 10)]['' + _this.parent.parentIdMapping] && Object.prototype.hasOwnProperty.call(result, i)) {
                            rowDetails.record.childRecords.push(result[parseInt(i.toString(), 10)]);
                        }
                    }
                }
                else {
                    rowDetails.record.childRecords = result;
                }
                for (var r = 0; r < result.length; r++) {
                    Iif (_this.parent.enableVirtualization && result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping] === rowDetails.record["" + _this.parent.idMapping] && rowDetails.action === 'remoteExpand') {
                        _this.parent["" + remoteExpandedData].push(rowDetails.record);
                    }
                    else Iif (_this.parent.enableVirtualization && result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping] === rowDetails.record["" + _this.parent.idMapping] && rowDetails.action === 'collapse') {
                        for (var i = 0; i < _this.parent["" + remoteExpandedData].length; i++) {
                            if (rowDetails.record["" + _this.parent.idMapping] === _this.parent["" + remoteExpandedData][parseInt(i.toString(), 10)]["" + _this.parent.idMapping]) {
                                _this.parent["" + remoteExpandedData].splice(i, 1);
                            }
                        }
                    }
                    result[parseInt(r.toString(), 10)].taskData = ej2_base_1.extend({}, result[parseInt(r.toString(), 10)]);
                    Iif (result[parseInt(r.toString(), 10)]["" + _this.parent.parentIdMapping] && _this.parent.enableVirtualization && _this.parent["" + remoteExpandedData].length) {
                        for (var i = 0; i < _this.parent["" + remoteExpandedData].length; i++) {
                            if (result[parseInt(r.toString(), 10)]["" + _this.parent.parentIdMapping] === _this.parent["" + remoteExpandedData][parseInt(i.toString(), 10)]["" + _this.parent.idMapping]) {
                                result[parseInt(r.toString(), 10)].level = _this.parent["" + remoteExpandedData][parseInt(i.toString(), 10)]["" + level] + 1;
                                var parentData = _this.parent["" + remoteExpandedData][parseInt(i.toString(), 10)];
                                delete parentData.childRecords;
                                result[parseInt(r.toString(), 10)].parentItem = parentData;
                                result[parseInt(r.toString(), 10)].parentUniqueID = rowDetails.record.uniqueID;
                            }
                        }
                    }
                    else Iif (_this.parent.enableVirtualization) {
                        if ((result[parseInt(r.toString(), 10)]["" + _this.parent.hasChildMapping] ||
                            _this.parentItems.indexOf(result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping]) !== -1)
                            && !(haveChild && !haveChild[parseInt(r.toString(), 10)])) {
                            if (ej2_base_1.isNullOrUndefined(result[parseInt(r.toString(), 10)]["" + _this.parent.parentIdMapping])) {
                                result[parseInt(r.toString(), 10)].level = 0;
                                if (rowDetails.action === 'remoteExpand') {
                                    result[parseInt(r.toString(), 10)].childRecords = [];
                                    result[parseInt(r.toString(), 10)].childRecords = rowDetails.record.childRecords;
                                }
                            }
                            else {
                                result[parseInt(r.toString(), 10)].level = rowDetails.record.level;
                            }
                        }
                        else {
                            var parentData = ej2_base_1.extend({}, rowDetails.record);
                            delete parentData.childRecords;
                            result[parseInt(r.toString(), 10)].parentItem = parentData;
                            result[parseInt(r.toString(), 10)].parentUniqueID = rowDetails.record.uniqueID;
                        }
                    }
                    else {
                        result[parseInt(r.toString(), 10)].level = rowDetails.record.level + 1;
                        var parentData = ej2_base_1.extend({}, rowDetails.record);
                        delete parentData.childRecords;
                        result[parseInt(r.toString(), 10)].parentItem = parentData;
                        result[parseInt(r.toString(), 10)].parentUniqueID = rowDetails.record.uniqueID;
                    }
                    result[parseInt(r.toString(), 10)].index = Math.ceil(Math.random() * 1000);
                    result[parseInt(r.toString(), 10)].uniqueID = ej2_grids_1.getUid(_this.parent.element.id + '_data_');
                    result[parseInt(r.toString(), 10)].checkboxState = 'uncheck';
                    Iif (_this.parent.enableVirtualization && ej2_base_1.isNullOrUndefined(result[parseInt(r.toString(), 10)].level)) {
                        for (var p = 0; p < _this.parent.grid.currentViewData.length; p++) {
                            if (_this.parent.grid.currentViewData[parseInt(p.toString(), 10)]["" + _this.parent.idMapping] === result[parseInt(r.toString(), 10)]["" + _this.parent.parentIdMapping]) {
                                result[parseInt(r.toString(), 10)].level = _this.parent.grid.currentViewData[parseInt(p.toString(), 10)]['level'] + 1;
                            }
                        }
                    }
                    ej2_base_1.setValue('uniqueIDCollection.' + result[parseInt(r.toString(), 10)].uniqueID, result[parseInt(r.toString(), 10)], _this.parent);
                    if ((result[parseInt(r.toString(), 10)]["" + _this.parent.hasChildMapping] ||
                        _this.parentItems.indexOf(result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping]) !== -1)
                        && !(haveChild && !haveChild[parseInt(r.toString(), 10)])) {
                        result[parseInt(r.toString(), 10)].hasChildRecords = true;
                        Iif (_this.parent.enableVirtualization && !_this.parent.loadChildOnDemand) {
                            for (var i = 0; i < _this.parent["" + remoteCollapsedData].length; i++) {
                                if (result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping] === _this.parent["" + remoteCollapsedData][parseInt(i.toString(), 10)]["" + _this.parent.idMapping]) {
                                    result[parseInt(r.toString(), 10)].expanded = _this.parent["" + remoteCollapsedData][parseInt(i.toString(), 10)]['expanded'];
                                }
                            }
                            if (rowDetails.action === 'collapse' && result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping] !== rowDetails.record["" + _this.parent.idMapping] && result[parseInt(r.toString(), 10)].expanded !== false) {
                                result[parseInt(r.toString(), 10)].expanded = true;
                            }
                            else if (rowDetails.action === 'collapse' && result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping] === rowDetails.record["" + _this.parent.idMapping]) {
                                result[parseInt(r.toString(), 10)].expanded = false;
                                _this.parent["" + remoteCollapsedData].push(rowDetails.record);
                            }
                            else if (rowDetails.action === 'remoteExpand') {
                                for (var i = 0; i < _this.parent.grid.currentViewData.length; i++) {
                                    if (_this.parent.grid.currentViewData[parseInt(i.toString(), 10)]["" + _this.parent.idMapping] === result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping]) {
                                        result.splice(r, 1, _this.parent.grid.currentViewData[parseInt(i.toString(), 10)]);
                                    }
                                }
                                if (result[parseInt(r.toString(), 10)][_this.parent.idMapping] === rowDetails.record["" + _this.parent.idMapping]) {
                                    for (var i = 0; i < _this.parent["" + remoteCollapsedData].length; i++) {
                                        if (rowDetails.record["" + _this.parent.idMapping] === _this.parent["" + remoteCollapsedData][parseInt(i.toString(), 10)]["" + _this.parent.idMapping]) {
                                            _this.parent["" + remoteCollapsedData].splice(i, 1);
                                        }
                                    }
                                }
                                if (result[parseInt(r.toString(), 10)].expanded !== false) {
                                    result[parseInt(r.toString(), 10)].expanded = true;
                                }
                            }
                        }
                        else Iif (_this.parent.enableVirtualization && result[parseInt(r.toString(), 10)]["" + _this.parent.idMapping] === rowDetails.record["" + _this.parent.idMapping] && rowDetails.action !== 'collapse') {
                            result[parseInt(r.toString(), 10)].expanded = true;
                        }
                        else Eif (!(_this.parent.enableVirtualization && !_this.parent.loadChildOnDemand)) {
                            result[parseInt(r.toString(), 10)].expanded = false;
                        }
                    }
                    datas.splice(inx + r + 1, 0, result[parseInt(r.toString(), 10)]);
                }
                ej2_base_1.setValue('result', datas, e);
                ej2_base_1.setValue('action', 'beforecontentrender', e);
                _this.parent.trigger(events.actionComplete, e);
                ej2_popups_1.hideSpinner(_this.parent.element);
                Iif (_this.parent.grid.aggregates.length > 0 && !_this.parent.enableVirtualization) {
                    var gridQuery = ej2_grids_1.getObject('query', e);
                    var result_1 = 'result';
                    if (ej2_base_1.isNullOrUndefined(gridQuery)) {
                        gridQuery = ej2_base_1.getValue('grid.renderModule.data', _this.parent).aggregateQuery(new ej2_data_1.Query());
                    }
                    if (!ej2_base_1.isNullOrUndefined(gridQuery)) {
                        var summaryQuery = gridQuery.queries.filter(function (q) { return q.fn === 'onAggregates'; });
                        e["" + result_1] = _this.parent.summaryModule.calculateSummaryValue(summaryQuery, e["" + result_1], true);
                    }
                }
                Eif (rowDetails.action === 'remoteExpand' && _this.parent.allowPaging && _this.parent.pageSettings.pageSizeMode === 'All') {
                    _this.parent.grid.pageSettings.totalRecordsCount = _this.parent.grid.pageSettings.totalRecordsCount + result.length;
                }
                Iif (_this.parent.enableVirtualization) {
                    _this.parent.grid.pageSettings.totalRecordsCount = e.count;
                }
                e.count = _this.parent.grid.pageSettings.totalRecordsCount;
                var virtualArgs = {};
                Iif (_this.parent.enableVirtualization) {
                    _this.remoteVirtualAction(virtualArgs);
                }
                var notifyArgs = { index: inx, childData: result };
                Iif (_this.parent.enableInfiniteScrolling) {
                    _this.parent.notify('infinite-remote-expand', notifyArgs);
                }
                else {
                    ej2_base_1.getValue('grid.renderModule', _this.parent).dataManagerSuccess(e, virtualArgs);
                }
                _this.parent.trigger(events.expanded, args);
            });
        };
        DataManipulation.prototype.remoteVirtualAction = function (virtualArgs) {
            virtualArgs.requestType = 'refresh';
            ej2_base_1.setValue('isExpandCollapse', true, virtualArgs);
            var contentModule = ej2_base_1.getValue('grid.contentModule', this.parent);
            var currentInfo = ej2_base_1.getValue('currentInfo', contentModule);
            var prevInfo = ej2_base_1.getValue('prevInfo', contentModule);
            if (currentInfo.loadNext && this.parent.grid.pageSettings.currentPage === currentInfo.nextInfo.page) {
                this.parent.grid.pageSettings.currentPage = prevInfo.page;
            }
        };
        DataManipulation.prototype.beginSorting = function () {
            this.isSortAction = true;
            if (utils_1.isRemoteData(this.parent) && this.parent.enableVirtualization) {
                var index = this.parent.query.queries.indexOf(this.parent.query.queries.filter(function (q) { return q.fn === 'onSortBy'; })[0]);
                Iif (index !== -1) {
                    this.parent.query.queries.splice(index, 1);
                }
                Iif (this.parent.grid.sortSettings.columns.length === 0) {
                    this.parent.query.sortBy(null, null);
                }
            }
        };
        DataManipulation.prototype.createRecords = function (data, parentRecords) {
            var treeGridData = [];
            var keys = Object.keys(data);
            for (var i = 0, len = keys.length; i < len; i++) {
                var currentData = ej2_base_1.extend({}, data[parseInt(i.toString(), 10)]);
                currentData.taskData = data[parseInt(i.toString(), 10)];
                var level = 0;
                this.storedIndex++;
                if (!Object.prototype.hasOwnProperty.call(currentData, 'index')) {
                    currentData.index = this.storedIndex;
                }
                var childMapping = currentData[this.parent.childMapping];
                var hasChildren = !ej2_base_1.isNullOrUndefined(childMapping) && childMapping.length > 0;
                var shouldCount = utils_1.isCountRequired(this.parent);
                var hasChildMapping = currentData[this.parent.hasChildMapping];
                if ((hasChildren && !shouldCount) || (hasChildMapping && shouldCount)) {
                    currentData.hasChildRecords = true;
                }
                else {
                    currentData.hasChildRecords = false;
                }
                if ((!ej2_base_1.isNullOrUndefined(childMapping) && !shouldCount) ||
                    (hasChildMapping) && shouldCount) {
                    if (this.parent.enableCollapseAll || !ej2_base_1.isNullOrUndefined(this.parent.dataStateChange)
                        && ej2_base_1.isNullOrUndefined(childMapping)) {
                        currentData.expanded = false;
                    }
                    else {
                        currentData.expanded = !ej2_base_1.isNullOrUndefined(currentData[this.parent.expandStateMapping])
                            ? currentData[this.parent.expandStateMapping] : true;
                    }
                }
                Iif (!Object.prototype.hasOwnProperty.call(currentData, 'index')) {
                    currentData.index = currentData.hasChildRecords ? this.storedIndex : this.storedIndex;
                }
                if (this.isSelfReference && ej2_base_1.isNullOrUndefined(currentData[this.parent.parentIdMapping])) {
                    this.parent.parentData.push(currentData);
                }
                currentData.uniqueID = ej2_grids_1.getUid(this.parent.element.id + '_data_');
                ej2_base_1.setValue('uniqueIDCollection.' + currentData.uniqueID, currentData, this.parent);
                if (!ej2_base_1.isNullOrUndefined(parentRecords)) {
                    var parentData = ej2_base_1.extend({}, parentRecords);
                    delete parentData.childRecords;
                    delete parentData[this.parent.childMapping];
                    if (this.isSelfReference) {
                        delete parentData.taskData[this.parent.childMapping];
                    }
                    currentData.parentItem = parentData;
                    currentData.parentUniqueID = parentData.uniqueID;
                    level = parentRecords.level + 1;
                }
                if (!Object.prototype.hasOwnProperty.call(currentData, 'level')) {
                    currentData.level = level;
                }
                currentData.checkboxState = 'uncheck';
                var remoteCollapsedData = 'remoteCollapsedData';
                Iif (this.parent.enableVirtualization && !this.parent.loadChildOnDemand && utils_1.isRemoteData(this.parent)
                    && !this.parent.initialRender) {
                    if (!currentData.hasChildRecords && ej2_base_1.isNullOrUndefined(currentData["" + this.parent.parentIdMapping])) {
                        currentData.hasChildRecords = true;
                        for (var c = 0; c < this.parent["" + remoteCollapsedData].length; c++) {
                            if (this.parent["" + remoteCollapsedData][parseInt(c.toString(), 10)]["" + this.parent.idMapping] === currentData["" + this.parent.idMapping]) {
                                currentData.expanded = false;
                            }
                        }
                    }
                    else if (currentData.level === 0 && ej2_base_1.isNullOrUndefined(parentRecords) && !currentData.hasChildRecords) {
                        currentData.level = currentData.level + 1;
                    }
                    if (currentData["" + this.parent.hasChildMapping] && !ej2_base_1.isNullOrUndefined(currentData["" + this.parent.expandStateMapping])) {
                        currentData.expanded = currentData["" + this.parent.expandStateMapping];
                        currentData.hasChildRecords = true;
                    }
                    this.parent.flatData.push(currentData);
                }
                else if (ej2_base_1.isNullOrUndefined(currentData["" + this.parent.parentIdMapping]) || currentData.parentItem) {
                    this.parent.flatData.push(currentData);
                    this.parent['infiniteScrollData'].push(currentData);
                }
                if (!this.isSelfReference && currentData.level === 0) {
                    this.parent.parentData.push(currentData);
                }
                if (!ej2_base_1.isNullOrUndefined(currentData[this.parent.childMapping] && currentData[this.parent.childMapping].length)) {
                    var record = this.createRecords(currentData[this.parent.childMapping], currentData);
                    currentData.childRecords = record;
                }
                treeGridData.push(currentData);
            }
            return treeGridData;
        };
        DataManipulation.prototype.dataProcessor = function (args) {
            var isExport = ej2_grids_1.getObject('isExport', args);
            var expresults = ej2_grids_1.getObject('expresults', args);
            var exportType = ej2_grids_1.getObject('exportType', args);
            var isPrinting = ej2_grids_1.getObject('isPrinting', args);
            var dataObj;
            var actionArgs = ej2_grids_1.getObject('actionArgs', args);
            var requestType = ej2_grids_1.getObject('requestType', args);
            var actionData = ej2_grids_1.getObject('data', args);
            var action = ej2_grids_1.getObject('action', args);
            var actionAddArgs = actionArgs;
            var primaryKeyColumnName = this.parent.getPrimaryKeyFieldNames()[0];
            var dataValue = ej2_grids_1.getObject('data', actionAddArgs);
            if ((!ej2_base_1.isNullOrUndefined(actionAddArgs)) && (!ej2_base_1.isNullOrUndefined(actionAddArgs.action)) && (actionAddArgs.action === 'add')
                && (!ej2_base_1.isNullOrUndefined(actionAddArgs.data)) && ej2_base_1.isNullOrUndefined(actionAddArgs.data["" + primaryKeyColumnName])) {
                actionAddArgs.data["" + primaryKeyColumnName] = args.result[actionAddArgs.index]["" + primaryKeyColumnName];
                dataValue.taskData["" + primaryKeyColumnName] = args.result[actionAddArgs.index]["" + primaryKeyColumnName];
            }
            if ((!ej2_base_1.isNullOrUndefined(actionArgs) && Object.keys(actionArgs).length) || requestType === 'save') {
                requestType = requestType ? requestType : actionArgs.requestType;
                actionData = actionData ? actionData : ej2_grids_1.getObject('data', actionArgs);
                action = action ? action : ej2_grids_1.getObject('action', actionArgs);
                if (this.parent.editSettings.mode === 'Batch') {
                    this.batchChanges = this.parent.grid.editModule.getBatchChanges();
                }
                Eif (this.parent.isLocalData) {
                    this.updateAction(actionData, action, requestType);
                }
            }
            if (isExport && !ej2_base_1.isNullOrUndefined(expresults)) {
                dataObj = expresults;
            }
            else {
                dataObj = utils_1.isCountRequired(this.parent) ? ej2_base_1.getValue('result', this.parent.grid.dataSource)
                    : this.parent.grid.dataSource;
            }
            var results = dataObj instanceof ej2_data_1.DataManager ? dataObj.dataSource.json : dataObj;
            var count = utils_1.isCountRequired(this.parent) ? ej2_base_1.getValue('count', this.parent.dataSource)
                : results.length;
            var qry = new ej2_data_1.Query();
            var gridQuery = ej2_grids_1.getObject('query', args);
            var filterQuery;
            var searchQuery;
            if (!ej2_base_1.isNullOrUndefined(gridQuery)) {
                filterQuery = gridQuery.queries.filter(function (q) { return q.fn === 'onWhere'; });
                searchQuery = gridQuery.queries.filter(function (q) { return q.fn === 'onSearch'; });
            }
            if ((this.parent.grid.allowFiltering && this.parent.grid.filterSettings.columns.length) ||
                (this.parent.grid.searchSettings.key.length > 0) || (!ej2_base_1.isNullOrUndefined(gridQuery) &&
                (filterQuery.length || searchQuery.length) && this.parent.isLocalData)) {
                if (ej2_base_1.isNullOrUndefined(gridQuery)) {
                    gridQuery = new ej2_data_1.Query();
                    gridQuery = ej2_base_1.getValue('grid.renderModule.data', this.parent).filterQuery(gridQuery);
                    gridQuery = ej2_base_1.getValue('grid.renderModule.data', this.parent).searchQuery(gridQuery);
                }
                var fltrQuery = gridQuery.queries.filter(function (q) { return q.fn === 'onWhere'; });
                var srchQuery = gridQuery.queries.filter(function (q) { return q.fn === 'onSearch'; });
                qry.queries = fltrQuery.concat(srchQuery);
                var filteredData = new ej2_data_1.DataManager(results).executeLocal(qry);
                this.parent.notify('updateFilterRecs', { data: filteredData });
                results = this.dataResults.result;
                this.dataResults.result = null;
                if (this.parent.grid.aggregates.length > 0) {
                    var query = ej2_grids_1.getObject('query', args);
                    Iif (ej2_base_1.isNullOrUndefined(gridQuery)) {
                        gridQuery = ej2_base_1.getValue('grid.renderModule.data', this.parent).aggregateQuery(new ej2_data_1.Query());
                    }
                    if (!ej2_base_1.isNullOrUndefined(query)) {
                        var summaryQuery = query.queries.filter(function (q) { return q.fn === 'onAggregates'; });
                        results = this.parent.summaryModule.calculateSummaryValue(summaryQuery, results, true);
                    }
                }
            }
            if (this.parent.grid.aggregates.length && this.parent.grid.sortSettings.columns.length === 0
                && this.parent.grid.filterSettings.columns.length === 0 && !this.parent.grid.searchSettings.key.length) {
                var gridQuery_1 = ej2_grids_1.getObject('query', args);
                if (ej2_base_1.isNullOrUndefined(gridQuery_1)) {
                    gridQuery_1 = ej2_base_1.getValue('grid.renderModule.data', this.parent).aggregateQuery(new ej2_data_1.Query());
                }
                var summaryQuery = gridQuery_1.queries.filter(function (q) { return q.fn === 'onAggregates'; });
                results = this.parent.summaryModule.calculateSummaryValue(summaryQuery, this.parent.flatData, true);
            }
            if (this.parent.grid.sortSettings.columns.length > 0 || this.isSortAction) {
                this.isSortAction = false;
                var parentData = this.parent.parentData;
                var query = ej2_grids_1.getObject('query', args);
                var srtQry = new ej2_data_1.Query();
                for (var srt = this.parent.grid.sortSettings.columns.length - 1; srt >= 0; srt--) {
                    var getColumnByField = 'getColumnByField';
                    var col = this.parent.grid.renderModule.data["" + getColumnByField](this.parent.grid.
                        sortSettings.columns[parseInt(srt.toString(), 10)].field);
                    var compFun = col.sortComparer && utils_1.isOffline(this.parent) ?
                        col.sortComparer.bind(col) :
                        this.parent.grid.sortSettings.columns[parseInt(srt.toString(), 10)].direction;
                    srtQry.sortBy(this.parent.grid.sortSettings.columns[parseInt(srt.toString(), 10)].field, compFun);
                }
                var modifiedData = new ej2_data_1.DataManager(parentData).executeLocal(srtQry);
                if (this.parent.allowRowDragAndDrop && !ej2_base_1.isNullOrUndefined(this.parent.rowDragAndDropModule['draggedRecord']) &&
                    this.parent.rowDragAndDropModule['droppedRecord'].hasChildRecords && this.parent.rowDragAndDropModule['dropPosition'] !== 'middleSegment') {
                    var dragdIndex = modifiedData.indexOf(this.parent.rowDragAndDropModule['draggedRecord']);
                    modifiedData.splice(dragdIndex, 1);
                    var dropdIndex = modifiedData.indexOf(this.parent.rowDragAndDropModule['droppedRecord']);
                    Iif (this.parent.rowDragAndDropModule['droppedRecord'].hasChildRecords && this.parent.rowDragAndDropModule['dropPosition'] === 'topSegment') {
                        modifiedData.splice(dropdIndex, 0, this.parent.rowDragAndDropModule['draggedRecord']);
                    }
                    else Eif (this.parent.rowDragAndDropModule['dropPosition'] === 'bottomSegment') {
                        modifiedData.splice(dropdIndex + 1, 0, this.parent.rowDragAndDropModule['draggedRecord']);
                    }
                }
                var sortArgs = { modifiedData: modifiedData, filteredData: results, srtQry: srtQry };
                this.parent.notify('createSort', sortArgs);
                results = sortArgs.modifiedData;
                this.dataResults.result = null;
                this.sortedData = results;
                this.parent.notify('updateModel', {});
                if (this.parent.grid.aggregates.length > 0 && !ej2_base_1.isNullOrUndefined(query)) {
                    var isSort = false;
                    var query_1 = ej2_grids_1.getObject('query', args);
                    var summaryQuery = query_1.queries.filter(function (q) { return q.fn === 'onAggregates'; });
                    results = this.parent.summaryModule.calculateSummaryValue(summaryQuery, this.sortedData, isSort);
                }
            }
            count = utils_1.isCountRequired(this.parent) ? ej2_base_1.getValue('count', this.parent.dataSource)
                : results.length;
            var temp = this.paging(results, count, isExport, isPrinting, exportType, args);
            results = temp.result;
            count = temp.count;
            args.result = results;
            args.count = count;
            this.parent.notify('updateResults', args);
        };
        DataManipulation.prototype.paging = function (results, count, isExport, isPrinting, exportType, args) {
            if (this.parent.allowPaging && (!isExport || exportType === 'CurrentPage')
                && (!isPrinting || this.parent.printMode === 'CurrentPage')) {
                this.parent.notify(events.pagingActions, { result: results, count: count, actionArgs: args });
                results = this.dataResults.result;
                count = utils_1.isCountRequired(this.parent) ? ej2_base_1.getValue('count', this.parent.dataSource)
                    : this.dataResults.count;
            }
            else if ((this.parent.enableVirtualization || this.parent.enableInfiniteScrolling) && (!isExport || exportType === 'CurrentPage')
                && ej2_base_1.getValue('requestType', args) !== 'save') {
                var actArgs = this.parent.enableInfiniteScrolling ? args : ej2_base_1.getValue('actionArgs', args);
                this.parent.notify(events.pagingActions, { result: results, count: count, actionArgs: actArgs });
                results = this.dataResults.result;
                count = this.dataResults.count;
            }
            var isPdfExport = 'isPdfExport';
            var isCollapsedStatePersist = 'isCollapsedStatePersist';
            if ((isPrinting === true || (args["" + isPdfExport] && (ej2_base_1.isNullOrUndefined(args["" + isCollapsedStatePersist])
                || args["" + isCollapsedStatePersist]))) && this.parent.printMode === 'AllPages') {
                var actualResults = [];
                for (var i = 0; i < results.length; i++) {
                    var expandStatus = utils_1.getExpandStatus(this.parent, results[parseInt(i.toString(), 10)], this.parent.parentData);
                    Eif (expandStatus) {
                        actualResults.push(results[parseInt(i.toString(), 10)]);
                    }
                }
                results = actualResults;
                count = results.length;
            }
            var value = { result: results, count: count };
            return value;
        };
        DataManipulation.prototype.updateData = function (dataResult) {
            this.dataResults = dataResult;
        };
        DataManipulation.prototype.updateAction = function (actionData, action, requestType) {
            if ((requestType === 'delete' || requestType === 'save')) {
                this.parent.notify(events.crudAction, { value: actionData, action: action || requestType });
            }
            if (requestType === 'batchsave' && this.parent.editSettings.mode === 'Batch') {
                this.parent.notify(events.batchSave, {});
            }
        };
        return DataManipulation;
    }());
    exports.DataManipulation = DataManipulation;
});