all files / base/olap/ engine.js

80.13% Statements 2073/2587
68.2% Branches 1636/2399
79.84% Functions 99/124
80.18% Lines 2067/2578
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 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251   19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19× 19×   34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34× 34×   34× 34× 34× 34× 34× 34× 34× 34× 34× 11× 11×     23×   34× 34× 34× 34× 34× 34× 34×     48×   48× 47×                       27× 27× 27× 27× 27× 27× 27×   27×   27×   21× 21× 21×   21×   21× 21× 21×   21×   21× 21× 21× 21× 21×   21×   21× 21× 21×   21×   21× 21× 21× 21× 21× 21×   27× 27× 27×             42× 42× 105× 105× 67×     38×     42×   42× 42× 42×                                           42× 12× 27× 27×     42×         21× 21× 21× 21× 21× 21× 21×   21×   21× 1164× 1164× 1164× 1164× 1140×   1164×   21×   58× 58×   58× 58× 58× 58× 58× 58× 58× 58× 58×   58×   58×   58× 24× 76× 76×       24× 24× 24× 24× 24× 24× 24× 24× 24× 24× 24× 24×     34×     48× 48× 48× 42×   24× 30×   48× 48× 30× 30× 30× 15× 15×   15×       48×   48× 48× 48× 48× 48× 19793× 19793× 19793× 19793× 19793× 19793× 19793× 20453× 20453× 20453×     20453× 87×   20366× 11×   20453× 44×   20453× 11×     19793× 19782× 19782× 19159× 687740×     623×       48× 48× 19793×             48× 24×   48×         61× 61× 61× 61× 61× 61× 61× 61× 61× 61×   61× 61× 61× 27× 27× 27× 27× 27× 27× 27×   61×     61× 61× 65433× 65171×     61× 61× 61× 14×   61× 61× 61× 27×     61× 61× 61× 27×     61× 61× 61× 27× 57×     61× 61×   14× 14× 13× 13× 13×   13× 13× 13× 13× 13× 13× 13× 13×     13× 13×   13× 13× 13× 13× 13×       14×             24× 24× 24× 24× 24× 24× 68×   67× 67× 67× 67×     67× 35× 35× 35× 35×     32× 18× 18× 18× 18×   18×       18×               18×                       31×     24×   21× 11×   21×     58× 58× 58× 58× 58× 58× 58× 58× 116× 58× 54× 97×             58× 45× 54×           116×     61× 61× 61× 61× 61× 61× 61× 61× 61× 61×         61× 61× 61× 61× 61× 61× 61× 61× 61× 61× 61× 61×                                 61× 61× 61×   61× 4877× 4877× 4877×   61× 61× 61× 61×               61× 61× 61× 61× 61× 61× 4877×   4877× 4877× 4877× 4877× 4877× 4877× 4877× 4877× 4877× 60× 60× 70×   21×     49×   70× 45× 45× 45×     25× 25×   70×   60×   4877× 4877× 49×   4877×   4877× 4877× 4877×             4877×   4877×       4877×     4877×                       4873× 4862×     4862× 4862× 4862× 4862× 4862× 4862× 4908× 4908×       4870×   4870× 4870× 4870× 4870× 4870×     4870×                   4870×                                                               4870× 4561×   4870× 4870×     4870× 4870× 4870× 4870× 4870× 4870×   4870× 20×   4870× 4870× 4870× 4870×     38× 12×     26×         4908×           4908×   4862× 4862× 4862× 301×       4877× 4877×   4877×   61×                 61×     58×                                                                                                               61×     61× 61×   61× 54× 16× 16× 16× 16× 16×               61×                                         6408× 6408×   6408× 6524×   6408×   6408× 6408× 6529× 6529× 6529×   6408×   7486× 7486× 10239× 10239× 17×     7486×   5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 5411× 6014× 6014× 6014× 6014× 48×   6014×   6014× 6014×   6014× 6014×   6014× 76× 76×   76×   5938× 526× 526× 526× 526× 502× 502×     24×       5412×   6014× 5938× 5758× 32×   5726× 16× 16× 16×     5758× 5758×     180× 180×         5938× 270× 270×                 5938× 5938× 5938× 6311× 6311× 5938×     373×     5938×   5938× 5938× 5938× 6311× 6311× 5938×     373×     5938× 5412×       6014× 6014× 6014× 254×   6014× 6014×   32× 77×   32× 32× 32×   6014×   5411×     5411×                               5411×   9740× 9740× 9740× 4862× 4755× 4755× 4755×       9740× 51× 51×   51× 51× 51× 51×     9689× 9689×   9740×   34× 34× 34× 68× 68× 68× 99×       68× 68×                                                                                                                                                               61× 61× 61× 61× 61× 61× 61× 61× 61× 61×   61× 534× 534× 534×   61× 30×   61× 60× 60× 60× 111×     111×   24× 24× 24×     87×   111×     61× 61× 61× 61× 61× 61× 61× 534× 534× 534× 534× 534× 534× 534× 534× 534× 534× 534× 534× 534× 534× 1085×     534× 534× 34× 34×   534× 534×   39× 39× 78×     39×     534× 498× 494× 494× 430×   64×     494× 440×   440× 440× 440×     440×   440× 440× 440×           54×     54×       54× 54× 54× 54×     54× 54× 54× 54× 54×     494×     534× 534× 38× 35×   35×   35× 35×   35× 35× 35× 31×           35× 35× 35× 35× 35×         534×   61× 61× 534×   61× 29× 20×     12× 12×   12× 12× 12× 12× 12×             20× 20× 20× 62× 62×   62× 62× 62× 22× 22× 22×     40×       20× 20× 20× 31× 62× 62× 62× 62× 62× 54×       31×     529× 529× 1069× 1069×   1069× 1069× 1069×   1069× 1069× 1069× 923× 923× 923×   923×   1069× 42×     1027× 127×   1027× 232× 232×   795×   519×     1069×     32× 32× 58× 140×   58×     58× 58× 58× 58×   58× 58×   58× 58×     430× 430× 844× 40× 40×     430×   21× 21× 21× 21× 21× 21× 21× 30× 30×     11×   11×           11×   11×     21× 21× 21× 21× 11× 11× 11× 11×   11× 11× 11× 11×     11×     21×   21×   32× 32×     32×   525× 525× 525× 525× 525× 525× 1061× 1061×   58× 58×   58×   1061×     525× 525× 517× 517× 517× 517× 517× 1045× 1045×   1045× 1045× 1045× 1538× 1538× 147×   1538× 369×     369× 369×   369×     1169× 1169×   1538× 1538× 1493×   45× 31× 31×   1538× 1538× 1538× 3021× 3021× 1538×     1483×     1538× 1538× 1538×                 1538×                                                         1538× 147×   1538×   1538×             1045×                                                         15117× 15117× 15117× 12431× 3661× 139× 90× 90× 90× 90× 90× 90×       90× 22× 22×           15117×   15117× 15117× 15117× 18198×     2686× 2686×     15117×                             27× 27× 26× 26× 26× 26× 26× 26× 26× 26× 116× 116×     116× 116×   116× 115× 107×   115× 115×           110× 81×     29×     116×     116×     26× 26× 29× 26× 26× 29× 29× 29× 29× 110×   110× 81×     29×     29× 29× 29×   29×                                                                                                               26×           29×   26× 26× 26× 26× 26× 26× 116×         116× 116× 116× 115× 115× 115×   116× 116× 116×         27× 27× 49× 49× 49× 49× 113× 113× 113× 113× 113× 113× 113× 113× 113× 113× 113× 1127× 1127×   645×   479× 309×   479× 263×   479×   166× 166× 166× 166× 166× 166× 48×   48×   48× 96× 96× 102× 102×     48× 48× 48× 48× 48×     118×       482× 26×   26×   26×   26× 112× 112× 324× 324×         456×   108×     1127×     14× 14× 14×         12×       1127× 148× 148× 148×         146×     148× 148× 148×       113× 35× 35× 35× 35× 35× 135× 135× 203× 203×       113× 779×   113× 115× 115× 115× 62× 736×   72×       62×     113× 113×   49× 113× 113× 1127×           115× 115×   115× 115× 115×   319× 319× 319× 504× 218× 218×     319×   60× 16× 16× 35× 35× 35× 35× 35×   16×   44× 14× 14× 68×   14× 14× 14×   14×             14×       14× 90×             14×   14×       14×   14×       60×   109× 109×       107× 107× 107×   107×             107×       107× 278×         107×   107× 11× 11×       107×   107×       109×                                                                                               34× 34× 26×       25× 25×                                                     25×   25×   25×   61× 61× 61× 61× 61× 67× 52× 52×     61× 147× 147× 147× 1538× 1538× 1538×   1538× 1538× 1538× 1538× 1538× 1538× 1538×       1538×       612× 13× 13×               599× 599×   612×   1538× 45×       41× 41× 41×           45×   1493× 117× 117× 117× 117×   1538× 1021× 127×   127×   95×     95×         32×       32×     127×   894×                 894× 894×             517×     1538× 926×   1538× 1411×   1538×   147×                       61× 61× 61× 61×           61× 4886× 4886× 4886× 65038× 65038× 65038× 65038×       65038× 34×                   65004× 65004× 65004× 65004× 65004×   65004× 65004×               65004× 65004×     65004×     65004×   65004×         65004×               65004×                             65038×         44301× 44301× 20828×   20828× 20828× 20828×     20828×     20828×       20828× 20828×     44301×   116× 116× 116× 116× 116× 116× 174× 174×   116× 114× 114× 114× 114× 124× 13× 13× 13× 13× 13× 13×     114× 101× 194× 101× 101× 101× 101× 101×       114× 114× 114×           114×         54× 54× 54× 54× 54× 54× 54× 54× 54× 27× 27× 27× 269× 269× 269× 269× 269× 269× 529× 529×   520× 260×   529×   269× 110×     159× 159×   269× 269×   27× 27× 27×             18× 150× 150× 272× 272× 492× 492× 492× 260× 260×               27× 27× 27× 27× 27× 27× 27× 27× 12305× 821× 821× 821× 821×   821× 821×     11484× 27×   11484× 11484×   12305× 12305× 12305×           12305× 12305× 12305× 12305×     27× 27× 22× 22× 260× 260× 12262× 12262× 12262×   12262× 12262× 12262× 12262×     12262×           43× 43×   43× 43× 43× 43×   43×           27×     27×     47×   40×   47×   11×               40× 40× 27× 27×                                                 27× 27× 49×   27× 27× 27× 27× 27× 27×     27×                                     25× 25× 8704× 8704× 8704× 3774×   3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3774× 3721× 3721×     8704×   102× 102×   102×   102×   102×   102×   102×   102×   102× 102×   102×   102×   102×   102×   102×   102×       8602×   163×     8439×     8704×   44× 44× 91× 91× 29× 29× 29× 29× 29×   29× 29× 29× 29×     44×                 8704×   25× 25×                   36× 36× 36× 19×     11× 11×           11× 11×       11× 11× 11× 29× 29× 29× 11× 11×     11×       11×               11×   55× 55×       55× 55×       36× 36× 36× 36× 36× 36× 36× 36× 173× 173× 35×     138×     36× 36× 36× 26× 26×     36×                         335× 335×   135× 135×                           40× 40×   105× 105×   55× 55×   335× 280×     55×     71521× 71521× 29315× 29315× 29315× 29315× 29315× 36× 36×     71521×   34× 34× 34× 19× 19× 19× 19× 19× 19× 19×                 19× 19× 89× 89× 89×       89× 89×     84×     19× 19×                                                   96× 96× 96× 96× 116× 116× 284× 284× 54× 54×       96×                                                                                                                                                                                                                                                                                                                                                       20× 20× 20× 20× 20× 20× 20× 20×                                                   20× 16× 16×                 16× 16× 16× 16×                                                                                                     11× 11× 11× 11× 992× 992× 992× 992× 992× 992×                     11×         11× 11×               11×   36× 17× 17×                   17×   17× 34× 34×                                                                                                     19×     11× 11× 11× 11× 152× 152× 152× 152× 152× 152× 11×                     141× 141×                         11× 11× 11×               11×   11× 11× 11× 11× 11× 31× 31×   11× 11× 11× 61× 61× 31×                   31×   61× 61×                                                                       61× 61× 61×   11× 11× 11×   11× 11× 11× 11× 11× 11× 31× 31×   11× 11× 992× 992× 992× 992× 992× 992× 926× 926×     66×   992× 992× 992× 116972× 116972× 992×     992× 992× 992× 981× 981× 517× 517× 517× 54451× 54451× 420×     517× 97×                     97×   517×   981×                                                                                             981× 981× 981×       11×               11×   1047× 367× 367×       11× 11× 11× 11× 11× 2372× 2372× 1435× 1435× 1435× 1435×                       1435× 1435×   656× 656×     779×       11× 11×               11×   11× 11× 11× 11× 11× 11× 15× 15×   11×                     11× 11× 273× 273× 273× 273×   273×   273× 62×                     62×   62× 62×                         62×     273×                                                                         273× 273× 273× 14×     11×             121× 121×                 121× 121× 121× 121× 66×                 121×           121×   121×                             125× 125× 125× 125× 125× 125×             125×              
define(["require", "exports", "@syncfusion/ej2-base", "../util", "./mdx-query", "../../common/base/css-constant"], function (require, exports, ej2_base_1, util_1, mdx_query_1, cls) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var OlapEngine = (function () {
        function OlapEngine() {
            this.fieldList = {};
            this.columnCount = 0;
            this.rowCount = 0;
            this.colFirstLvl = 0;
            this.rowFirstLvl = 0;
            this.pageColStartPos = 0;
            this.enableSort = false;
            this.enableValueSorting = false;
            this.dataFields = {};
            this.formatFields = {};
            this.filterMembers = {};
            this.drilledSets = {};
            this.isExporting = false;
            this.aggregatedValueMatrix = [];
            this.mappingFields = {};
            this.formatRegex = /^(?:[ncpae])(?:([0-9]|1[0-9]|20))?$/i;
            this.clonedValTuple = [];
            this.clonedColumnTuple = [];
            this.clonedRowTuple = [];
            this.pivotValues = [];
            this.valueContent = [];
            this.headerContent = [];
            this.rowStartPos = 0;
            this.pageRowStartPos = 0;
            this.tupColumnInfo = [];
            this.tupRowInfo = [];
            this.gridJSON = '';
            this.namedSetsPosition = {};
            this.colDepth = 0;
            this.totalCollection = [];
            this.parentObjCollection = {};
            this.curDrillEndPos = -1;
            this.headerGrouping = {};
            this.lastLevel = [];
            this.showRowSubTotals = true;
            this.showColumnSubTotals = true;
            this.hideRowTotalsObject = {};
            this.hideColumnTotalsObject = {};
            this.sortObject = {};
            this.isColDrill = false;
        }
        OlapEngine.prototype.renderEngine = function (dataSourceSettings, customProperties, onHeadersSort) {
            this.isEmptyData = false;
            this.getHeaderSortInfo = onHeadersSort;
            this.mdxQuery = '';
            this.isMeasureAvail = false;
            this.allowMemberFilter = false;
            this.allowLabelFilter = false;
            this.allowValueFilter = false;
            this.isMondrian = false;
            this.aggregatedValueMatrix = [];
            this.measureReportItems = [];
            this.calcChildMembers = [];
            this.selectedItems = [];
            this.savedFieldList = undefined;
            this.savedFieldListData = undefined;
            this.formatFields = {};
            this.filterMembers = {};
            this.dataFields = {};
            this.valueAxis = '';
            this.columnCount = 0;
            this.rowCount = 0;
            this.colFirstLvl = 0;
            this.rowFirstLvl = 0;
            this.pageColStartPos = 0;
            this.sortObject = {};
            this.globalize = new ej2_base_1.Internationalization();
            this.locale = this.globalize.culture ? this.globalize.culture : 'en-US';
            this.localeObj = customProperties ? customProperties.localeObj : undefined;
            this.enableValueSorting = customProperties ? customProperties.enableValueSorting : false;
            Eif (dataSourceSettings.url) {
                this.dataSourceSettings = dataSourceSettings;
                this.measureIndex = !ej2_base_1.isNullOrUndefined(dataSourceSettings.valueIndex) ? dataSourceSettings.valueIndex : -1;
                this.valueAxis = dataSourceSettings.valueAxis === 'row' ? 'row' : 'column';
                this.getAxisFields();
                this.formats = dataSourceSettings.formatSettings ? dataSourceSettings.formatSettings : [];
                this.enableSort = dataSourceSettings.enableSorting === undefined ? true : dataSourceSettings.enableSorting;
                this.valueSortSettings = dataSourceSettings.valueSortSettings ? dataSourceSettings.valueSortSettings : undefined;
                this.filterSettings = dataSourceSettings.filterSettings ? dataSourceSettings.filterSettings : [];
                this.sortSettings = dataSourceSettings.sortSettings ? dataSourceSettings.sortSettings : [];
                this.allowMemberFilter = dataSourceSettings.allowMemberFilter ? true : false;
                this.allowLabelFilter = dataSourceSettings.allowLabelFilter ? true : false;
                this.allowValueFilter = dataSourceSettings.allowValueFilter ? true : false;
                this.drilledMembers = dataSourceSettings.drilledMembers ? this.updateDrilledItems(dataSourceSettings.drilledMembers) : [];
                this.calculatedFieldSettings = dataSourceSettings.calculatedFieldSettings ? dataSourceSettings.calculatedFieldSettings : [];
                this.emptyCellTextContent = dataSourceSettings.emptyCellsTextContent ? dataSourceSettings.emptyCellsTextContent : '';
                this.pageSettings = customProperties ? (customProperties.pageSettings ?
                    customProperties.pageSettings : this.pageSettings) : undefined;
                this.isPaging = this.pageSettings && (customProperties.enablePaging || customProperties.enableVirtualization) ? true : false;
                this.frameSortObject();
                this.getFormattedFields(this.formats);
                this.savedFieldList = customProperties ? customProperties.savedFieldList : undefined;
                this.savedFieldListData = customProperties ? customProperties.savedFieldListData : undefined;
                this.fieldListData = [];
                this.fieldListObj = {};
                this.setNamedSetsPosition();
                if (!(this.savedFieldList && Object.keys(this.savedFieldList).length > 0 && this.savedFieldListData)) {
                    this.getCubes(dataSourceSettings);
                    this.getFieldList(dataSourceSettings);
                }
                else {
                    this.updateFieldlist(true);
                }
                this.loadCalculatedMemberElements(this.calculatedFieldSettings);
                var measuresInfo = this.getMeasureInfo();
                this.olapVirtualization = this.isPaging && dataSourceSettings.showSubTotals && (measuresInfo.measureIndex === (measuresInfo.measureAxis === 'column' ? dataSourceSettings.columns.length - 1 : dataSourceSettings.rows.length - 1)) && !ej2_base_1.isNullOrUndefined(this.pageSettings) && dataSourceSettings.showGrandTotals;
                this.isPaging = this.isPaging ? !this.olapVirtualization : this.isPaging;
                this.measureReportItems = [];
                this.updateFilterItems(this.filterSettings);
                this.generateGridData(dataSourceSettings);
            }
        };
        OlapEngine.prototype.generateGridData = function (dataSourceSettings, action) {
            var refPaging = (action && action === 'navPaging' &&
                this.isPaging && this.pageSettings !== undefined ? true : false);
            if (this.rows.length > 0 || this.columns.length > 0 || this.values.length > 0 || this.filters.length > 0) {
                mdx_query_1.MDXQuery.getCellSets(dataSourceSettings, this, refPaging);
            }
            else {
                mdx_query_1.MDXQuery.getCellSets(dataSourceSettings, this, true, undefined, true);
                this.generateEngine(undefined, undefined, { dataSourceSettings: dataSourceSettings, action: 'loadTableElements' });
            }
        };
        OlapEngine.prototype.generatePagingData = function (xmlDoc, request, customArgs) {
            var xmlaCellSet = [].slice.call(xmlDoc.querySelectorAll('Axes, CellData'));
            var countCells = xmlaCellSet[1] ? xmlaCellSet[1].querySelectorAll('FmtValue') : null;
            Eif (countCells && countCells.length > 0) {
                this.columnCount = Number(countCells[0].textContent);
                this.rowCount = Number(countCells[1].textContent);
            }
            var dataSourceSettings = customArgs.dataSourceSettings;
            mdx_query_1.MDXQuery.getCellSets(dataSourceSettings, this, true);
        };
        OlapEngine.prototype.scrollPage = function () {
            if (this.olapVirtualization) {
                var virtualScrollingData = this.getVirtualScrollingData(this.clonedColumnTuple, this.clonedRowTuple);
                Eif (virtualScrollingData.isCalculated) {
                    this.pivotValues = [];
                    this.clearEngineProperties();
                    this.performEngine(virtualScrollingData.columnTuple, virtualScrollingData.rowTuple, virtualScrollingData.valueTuple);
                }
                this.pivotValues = this.pivotValues.slice();
            }
            else {
                mdx_query_1.MDXQuery.getCellSets(this.dataSourceSettings, this, true);
            }
        };
        OlapEngine.prototype.getVirtualScrollingData = function (colTuples, rowTuples) {
            var valTuples = this.clonedValTuple.slice();
            var isCalculated = false;
            var calColPage = (this.pageSettings.currentColumnPage - 1) * this.pageSettings.columnPageSize;
            var calRowPage = (this.pageSettings.currentRowPage - 1) * this.pageSettings.rowPageSize;
            var calColSize = this.pageSettings.columnPageSize * 3;
            var calRowSize = this.pageSettings.rowPageSize * 3;
            calColPage = (this.columnCount < (calColPage + calColSize)) ?
                (this.columnCount > calColSize ? (this.columnCount - calColSize) : 0) : calColPage;
            calRowPage = (this.rowCount < (calRowPage + calRowSize)) ?
                (this.rowCount > calRowSize ? (this.rowCount - calRowSize) : 0) : calRowPage;
            if ((calColPage !== this.pageColStartPos || calRowPage !== this.pageRowStartPos) ||
                !(colTuples.length <= calColSize && rowTuples.length <= calRowSize)) {
                isCalculated = true;
                var measureInfo = this.getMeasureInfo();
                var isColGrandTolExists = !ej2_base_1.isNullOrUndefined(colTuples[0]) &&
                    (Number(colTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) === 0);
                var isRowGrandTolExists = !ej2_base_1.isNullOrUndefined(rowTuples[0]) &&
                    (Number(rowTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) === 0);
                var isAddColGrandTotals = isColGrandTolExists ? (calColPage + calColSize >= colTuples.length - 1) : false;
                var isAddRowGrandTotals = isRowGrandTolExists ? (calRowPage + calRowSize >= rowTuples.length - 1) : false;
                var colDepth = isColGrandTolExists ?
                    this.getAxisdepth(colTuples) : measureInfo.measureAxis === 'column' ? measureInfo.valueInfo.length : 1;
                var rowDepth = isRowGrandTolExists ?
                    this.getAxisdepth(rowTuples) : measureInfo.measureAxis === 'row' ? measureInfo.valueInfo.length : 1;
                var colTuplesOffset = (isColGrandTolExists ? colDepth : 0) + calColPage;
                var rowTuplesOffset = (isRowGrandTolExists ? rowDepth : 0) + calRowPage;
                var virtualColTuples = colTuples.slice(colTuplesOffset, colTuplesOffset + calColSize);
                var virtualRowTuples = rowTuples.slice(rowTuplesOffset, rowTuplesOffset + calRowSize);
                var colLastLevel = virtualColTuples[0] ?
                    Number(virtualColTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) : 0;
                var rowLastLevel = virtualRowTuples[0] ?
                    Number(virtualRowTuples[0].querySelectorAll('Member')[0].querySelector('LNum').textContent) : 0;
                var colData = this.getVirtualTotals(colTuples.slice(0, colTuplesOffset), colLastLevel, isAddColGrandTotals, 'column', colDepth);
                var rowData = this.getVirtualTotals(rowTuples.slice(0, rowTuplesOffset), rowLastLevel, isAddRowGrandTotals, 'row', rowDepth);
                colTuplesOffset = virtualColTuples.length + colData.totalsCollection.length > calColSize ?
                    Math.max(virtualColTuples.length + colData.totalsCollection.length - calColSize) : 0;
                rowTuplesOffset = virtualRowTuples.length + rowData.totalsCollection.length > calRowSize ?
                    Math.max(virtualRowTuples.length + rowData.totalsCollection.length - calRowSize) : 0;
                virtualColTuples = colData.totalsCollection.concat(virtualColTuples.slice(colTuplesOffset, virtualColTuples.length));
                virtualRowTuples = rowData.totalsCollection.concat(virtualRowTuples.slice(rowTuplesOffset, virtualRowTuples.length));
                var virtualValuesTupples = this.getVirtualValues(valTuples, calColPage + colTuplesOffset, calRowPage + rowTuplesOffset, calColSize, calRowSize, colData.indexCollection, rowData.indexCollection, colTuples.length, rowTuples.length, colDepth, rowDepth, isRowGrandTolExists);
                colTuples = virtualColTuples.slice();
                rowTuples = virtualRowTuples.slice();
                valTuples = virtualValuesTupples.slice();
            }
            this.pageColStartPos = calColPage;
            this.pageRowStartPos = calRowPage;
            return {
                columnTuple: colTuples,
                rowTuple: rowTuples,
                valueTuple: valTuples,
                isCalculated: isCalculated
            };
        };
        OlapEngine.prototype.getAxisdepth = function (tuplesCollection) {
            var depth = 0;
            for (var i = 0; i < tuplesCollection.length; i++) {
                var level = Number(tuplesCollection[i].querySelectorAll('Member')[0].querySelector('LNum').textContent);
                if (level === 0) {
                    depth++;
                }
                else {
                    break;
                }
            }
            return depth;
        };
        OlapEngine.prototype.getVirtualTotals = function (tuplesCollection, lastLevel, isAddGrandTotals, axis, axisDepth) {
            var totalsCollection = [];
            var indexCollection = [];
            if (lastLevel !== 1) {
                for (var i = tuplesCollection.length - 1; i > 0; i--) {
                    var currLevel = Number(tuplesCollection[i].querySelectorAll('Member')[0].querySelector('LNum').textContent);
                    Eif (currLevel === 0) {
                        break;
                    }
                    else if (lastLevel > currLevel) {
                        lastLevel = currLevel;
                        var nextLevel = Number(tuplesCollection[i - 1].querySelectorAll('Member')[0].querySelector('LNum').textContent);
                        if (nextLevel === currLevel) {
                            for (var offset = 0; offset < axisDepth; offset++) {
                                totalsCollection[totalsCollection.length] = tuplesCollection[i - offset];
                                indexCollection[indexCollection.length] = i - offset;
                            }
                            i = axisDepth > 1 ? i - (axisDepth - 1) : i;
                        }
                        else {
                            totalsCollection[totalsCollection.length] = tuplesCollection[i];
                            indexCollection[indexCollection.length] = i;
                        }
                    }
                    else if (currLevel === 1) {
                        break;
                    }
                }
            }
            if (isAddGrandTotals) {
                for (var i = axisDepth; i > 0; i--) {
                    totalsCollection = totalsCollection.concat([tuplesCollection[i - 1]]);
                    indexCollection = indexCollection.concat([i - 1]);
                }
            }
            return {
                totalsCollection: totalsCollection.reverse(),
                indexCollection: indexCollection.reverse()
            };
        };
        OlapEngine.prototype.getVirtualValues = function (valueTuples, calColumnPage, calRowPage, calColunmnSize, calRowSize, colTotalsIndex, rowTotalsIndex, colTuplesLen, rowTuplesLen, columnDepth, rowDepth, isRowGrandTolExists) {
            var framedVirtValTuples = [];
            var virtValTuples = valueTuples;
            Eif (rowTuplesLen > calRowSize) {
                var rowValuesOffset = ((isRowGrandTolExists ? rowDepth : 0) + calRowPage) * colTuplesLen;
                virtValTuples = valueTuples.slice(rowValuesOffset, rowValuesOffset + (calRowSize * colTuplesLen));
                var virtRowTotalValues = [];
                for (var i = 0; i < rowTotalsIndex.length; i++) {
                    virtRowTotalValues = virtRowTotalValues.concat(valueTuples.slice(rowTotalsIndex[i] * colTuplesLen, (rowTotalsIndex[i] * colTuplesLen) + colTuplesLen));
                }
                virtValTuples = virtRowTotalValues.concat(virtValTuples);
            }
            for (var i = 0, j = virtValTuples.length / colTuplesLen; i < j; i++) {
                var rows = virtValTuples.slice(i * colTuplesLen, (i * colTuplesLen) + colTuplesLen);
                var virtRows = rows.slice(calColumnPage + columnDepth, calColumnPage + columnDepth + calColunmnSize);
                var virtTotals = [];
                for (var x = 0; x < colTotalsIndex.length; x++) {
                    virtTotals[virtTotals.length] = rows[colTotalsIndex[x]];
                }
                framedVirtValTuples = framedVirtValTuples.concat(virtTotals.concat(virtRows));
            }
            return framedVirtValTuples;
        };
        OlapEngine.prototype.generateEngine = function (xmlDoc, request, customArgs) {
            Eif (customArgs.action !== 'down') {
                this.clearEngineProperties();
            }
            this.xmlDoc = xmlDoc ? xmlDoc.cloneNode(true) : undefined;
            this.request = request;
            this.customArgs = customArgs;
            this.parentObjCollection = {};
            this.curDrillEndPos = -1;
            this.onDemandDrillEngine = [];
            this.getSubTotalsVisibility();
            this.xmlaCellSet = xmlDoc ? xmlDoc.querySelectorAll('Axes, CellData') : undefined;
            var columnTuples = this.xmlaCellSet && this.xmlaCellSet.length > 0 ?
                [].slice.call(this.xmlaCellSet[0].querySelectorAll('Axis[name|="Axis0"] Tuple')) : [];
            var rowTuples = this.xmlaCellSet && this.xmlaCellSet.length > 0 ?
                [].slice.call(this.xmlaCellSet[0].querySelectorAll('Axis[name|="Axis1"] Tuple')) : [];
            var valCollection = this.xmlaCellSet && this.xmlaCellSet.length > 1 ?
                [].slice.call(this.xmlaCellSet[1].querySelectorAll('Cell')) : [];
            if (this.olapVirtualization && !ej2_base_1.isNullOrUndefined(this.pageSettings)) {
                if (columnTuples.length * rowTuples.length !== valCollection.length) {
                    var valueCollection = [];
                    for (var colPos = 0; colPos < valCollection.length; colPos++) {
                        Eif (!ej2_base_1.isNullOrUndefined(valCollection[colPos])) {
                            valueCollection[Number(valCollection[colPos].getAttribute('CellOrdinal'))] = valCollection[colPos];
                        }
                    }
                    valCollection = valueCollection;
                }
                this.clonedValTuple = valCollection;
                var drillInfo = this.getDrillInfo('columns');
                var columnData = this.getActualTuples(columnTuples, drillInfo);
                drillInfo = this.getDrillInfo('rows');
                var rowData = this.getActualTuples(rowTuples, drillInfo, columnData.indexColls, columnTuples.length);
                this.clonedColumnTuple = columnData.tupColls;
                this.clonedRowTuple = rowData.tupColls;
                this.columnCount = this.clonedColumnTuple.length;
                this.rowCount = this.clonedRowTuple.length;
                columnData = rowData = undefined;
                var virtualScrollingData = this.getVirtualScrollingData(this.clonedColumnTuple, this.clonedRowTuple);
                this.performEngine(virtualScrollingData.columnTuple, virtualScrollingData.rowTuple, virtualScrollingData.valueTuple);
            }
            else {
                this.performEngine(columnTuples, rowTuples, valCollection);
            }
        };
        OlapEngine.prototype.getDrillInfo = function (axis) {
            var drilledMembers = {};
            var fieldColls = [];
            if (axis === 'columns') {
                fieldColls = this.dataSourceSettings.columns.map(function (field) { return field.name; });
            }
            else Eif (axis === 'rows') {
                fieldColls = this.dataSourceSettings.rows.map(function (field) { return field.name; });
            }
            Eif (fieldColls.length > 0) {
                for (var i = 0, j = this.drilledMembers.length; i < j; i++) {
                    var drilledMember = this.drilledMembers[i];
                    var index = fieldColls.indexOf(drilledMember.name);
                    if (index > -1) {
                        Eif (!drilledMembers[index]) {
                            drilledMembers[index] = [];
                        }
                        drilledMembers[index] = drilledMembers[index].concat(drilledMember.items);
                    }
                }
            }
            return drilledMembers;
        };
        OlapEngine.prototype.getActualTuples = function (tuplesColl, drillInfo, indexCollection, deapth) {
            var tupColls = [];
            var indexColls = [];
            var valueCollection = [];
            Eif (tuplesColl.length > 0) {
                var _loop_1 = function (i, j) {
                    var tuples = tuplesColl[i];
                    var isAddElement = true;
                    var isGrandSum = false;
                    var isSum = false;
                    var memTypeColl = tuples.getElementsByTagName('MEMBER_TYPE');
                    var uNameColl = tuples.getElementsByTagName('UName');
                    for (var k = 0, l = memTypeColl.length; k < l; k++) {
                        var memType = Number(memTypeColl[k].textContent);
                        var uName = uNameColl[k].textContent;
                        Iif (isSum && memType < 2) {
                            isAddElement = false;
                        }
                        else if (memType === 2) {
                            isGrandSum = true;
                        }
                        else if (isGrandSum && memType < 2) {
                            isAddElement = false;
                        }
                        if (drillInfo[k] && drillInfo[k].indexOf(uName) > -1) {
                            isSum = true;
                        }
                        if (!isAddElement) {
                            break;
                        }
                    }
                    if (isAddElement) {
                        tupColls[tupColls.length] = tuples;
                        if (indexCollection) {
                            var rowColls_1 = this_1.clonedValTuple.slice(i * deapth, (i * deapth) + deapth);
                            valueCollection = valueCollection.concat(indexCollection.map(function (index) { return rowColls_1[index]; }));
                        }
                        else {
                            indexColls[indexColls.length] = i;
                        }
                    }
                };
                var this_1 = this;
                for (var i = 0, j = tuplesColl.length; i < j; i++) {
                    _loop_1(i, j);
                }
            }
            else if (indexCollection) {
                var rowColls_2 = this.clonedValTuple.slice(0, deapth);
                valueCollection = valueCollection.concat(indexCollection.map(function (index) { return rowColls_2[index]; }));
            }
            if (valueCollection.length > 0) {
                this.clonedValTuple = valueCollection;
            }
            return {
                tupColls: tupColls,
                indexColls: indexColls
            };
        };
        OlapEngine.prototype.clearEngineProperties = function () {
            this.pivotValues = [];
            this.valueContent = [];
            this.headerContent = [];
            this.colDepth = 0;
            this.tupColumnInfo = [];
            this.tupRowInfo = [];
            this.colMeasures = {};
            this.colMeasurePos = undefined;
            this.rowMeasurePos = undefined;
            this.rowStartPos = -1;
        };
        OlapEngine.prototype.performEngine = function (columnTuples, rowTuples, valCollection) {
            this.totalCollection = [];
            var measureInfo = this.getMeasureInfo();
            if (this.drilledMembers.length > 0) {
                var orderedInfo = void 0;
                orderedInfo = this.frameMeasureOrder(measureInfo, 'column', columnTuples, valCollection, columnTuples.length, columnTuples.length * rowTuples.length);
                columnTuples = orderedInfo.orderedHeaderTuples;
                valCollection = orderedInfo.orderedValueTuples;
                orderedInfo = this.frameMeasureOrder(measureInfo, 'row', rowTuples, valCollection, columnTuples.length, columnTuples.length * rowTuples.length);
                rowTuples = orderedInfo.orderedHeaderTuples;
                valCollection = orderedInfo.orderedValueTuples;
            }
            Iif (this.customArgs.action === 'down') {
                this.updateTupCollection(this.customArgs.drillInfo.axis === 'row' ? rowTuples.length : columnTuples.length);
            }
            var framedValCollection = {};
            for (var colPos = 0; colPos < valCollection.length; colPos++) {
                if (!ej2_base_1.isNullOrUndefined(valCollection[colPos])) {
                    framedValCollection[this.olapVirtualization ? colPos : Number(valCollection[colPos].getAttribute('CellOrdinal'))] = valCollection[colPos];
                }
            }
            var valueSortData;
            this.valueSortSettings.columnIndex = undefined;
            if (this.enableValueSorting && this.valueSortSettings && !this.isPaging && !this.olapVirtualization) {
                valueSortData = this.getValueSortInfo(columnTuples, rowTuples, measureInfo);
            }
            Eif (this.customArgs.action === 'down' ? this.customArgs.drillInfo.axis === 'column' : true) {
                this.frameColumnHeader(columnTuples);
                if (!this.isPaging && !this.olapVirtualization) {
                    this.performColumnSorting(framedValCollection, valueSortData);
                }
            }
            Eif (this.customArgs.action === 'down' ? this.customArgs.drillInfo.axis === 'row' : true) {
                this.frameRowHeader(rowTuples);
                if (!this.isPaging && !this.olapVirtualization) {
                    this.performRowSorting(framedValCollection, valueSortData);
                }
            }
            this.frameValues(framedValCollection, columnTuples.length);
            this.performColumnSpanning();
            if (!this.isPaging && !this.olapVirtualization && this.enableSort) {
                for (var i = 0; i < this.headerContent.length; i++) {
                    this.headerContent[i] = this.pivotValues[i];
                }
            }
            this.isEngineUpdated = true;
            this.isEmptyData = columnTuples.length === 0;
        };
        OlapEngine.prototype.getValueSortInfo = function (columnTuples, rowTuples, measureInfo) {
            var memberIndex;
            if (this.valueSortSettings.headerText) {
                var headersCollection = this.valueSortSettings.headerText.split(this.valueSortSettings.headerDelimiter);
                var granSumPos = headersCollection.indexOf('Grand Total');
                if (granSumPos > -1) {
                    var measure = headersCollection.join('').split(headersCollection[granSumPos]).join('');
                    headersCollection = [];
                    headersCollection[measureInfo.measureIndex] = measure;
                }
                var measureAxis = '';
                var measureIndex = measureInfo.measureIndex;
                for (var i = 0; i < this.dataSourceSettings.values.length; i++) {
                    measureIndex = headersCollection.indexOf(this.dataSourceSettings.values[i].caption);
                    Eif (this.dataSourceSettings.values[i].caption === headersCollection[measureIndex]) {
                        headersCollection[measureIndex] = this.fieldList[this.dataSourceSettings.values[i].name].name;
                        measureAxis = headersCollection[measureIndex];
                        break;
                    }
                }
                Eif (measureIndex !== -1) {
                    if (measureIndex < measureInfo.measureIndex) {
                        headersCollection = this.reArrangeHeaders(headersCollection, measureInfo.measureIndex, measureAxis);
                    }
                    var membersColls = this.olapValueAxis === 'column' ? columnTuples : rowTuples;
                    Eif (membersColls.length > 0) {
                        var level = membersColls[0].getElementsByTagName('Member').length - (granSumPos > -1 ? measureIndex : 0);
                        var member = this.getParentElement(membersColls, headersCollection, level, measureInfo.measureIndex, measureAxis, granSumPos > -1)[0];
                        memberIndex = membersColls.indexOf(member);
                    }
                }
            }
            return {
                memberIndex: memberIndex,
                columnLength: columnTuples.length,
                rowLength: rowTuples.length,
                isValueSorting: memberIndex > -1
            };
        };
        OlapEngine.prototype.getParentElement = function (membersColls, headersCollection, level, measureIndex, measureAxis, isGrandTotal) {
            var selectedMember = [];
            var parentLevel = 0;
            var isParentAvail = false;
            var isChildAvail = false;
            var index = membersColls[0].getElementsByTagName('Member').length - level;
            for (var i = 0; i < membersColls.length; i++) {
                if (ej2_base_1.isNullOrUndefined(membersColls[i].getElementsByTagName('Member')[index])) {
                    selectedMember = [];
                    break;
                }
                var memberUName = membersColls[i].getElementsByTagName('UName')[index].textContent;
                var memberCaption = membersColls[i].getElementsByTagName('Caption')[index].textContent;
                var memberLevel = Number(membersColls[i].getElementsByTagName('LNum')[index].textContent);
                var isParent = memberUName === headersCollection[index] ||
                    memberCaption === headersCollection[index] ||
                    (ej2_base_1.isNullOrUndefined(headersCollection[index]) && memberLevel === 0);
                if (isParent) {
                    selectedMember[selectedMember.length] = membersColls[i];
                    isParentAvail = true;
                    parentLevel = memberLevel;
                    if (isGrandTotal) {
                        break;
                    }
                }
                else if (isParentAvail && parentLevel < memberLevel) {
                    var childMember = [];
                    for (var j = i; j < membersColls.length; j++) {
                        var childUName = membersColls[j].getElementsByTagName('UName')[index].textContent;
                        var childCaption = membersColls[j].getElementsByTagName('Caption')[index].textContent;
                        var childLevel = Number(membersColls[j].getElementsByTagName('LNum')[index].textContent);
                        var isChild = childUName === headersCollection[index + 1] || childCaption === headersCollection[index + 1] ||
                            (ej2_base_1.isNullOrUndefined(headersCollection[index + 1]) && childLevel === 0);
                        Iif ((parentLevel + 1 === childLevel) && isChild) {
                            childMember[childMember.length] = membersColls[j];
                            isChildAvail = true;
                        }
                        else Iif (parentLevel + 1 < childLevel) {
                            if (isChildAvail) {
                                childMember[childMember.length] = membersColls[j];
                            }
                            else {
                                break;
                            }
                        }
                        else Iif (parentLevel + 1 > childLevel) {
                            break;
                        }
                    }
                    Iif (isChildAvail) {
                        var childHeaderCollection = headersCollection.slice(0, index).concat(headersCollection.slice(index + 1, headersCollection.length));
                        var childMeasureIndex = childHeaderCollection.indexOf(measureAxis);
                        if (childMeasureIndex < measureIndex) {
                            childHeaderCollection = this.reArrangeHeaders(childHeaderCollection, measureIndex, measureAxis);
                        }
                        selectedMember = this.getParentElement(childMember, childHeaderCollection, childMember[0].getElementsByTagName('Member').length, measureIndex, measureAxis);
                    }
                    break;
                }
                else if (isParentAvail && !isParent) {
                    break;
                }
            }
            if (isGrandTotal) {
                return selectedMember;
            }
            else if (index < (headersCollection.length - 1) && selectedMember.length > 0 && !isChildAvail) {
                selectedMember = this.getParentElement(selectedMember, headersCollection, level - 1, measureIndex, measureAxis);
            }
            return selectedMember;
        };
        OlapEngine.prototype.reArrangeHeaders = function (headersCollection, measureIndex, measureAxis) {
            var actualIndex = headersCollection.indexOf(measureAxis);
            var headerColl1 = headersCollection.slice(0, actualIndex);
            var headerColl2 = headersCollection.slice(actualIndex + 1, headersCollection.length);
            headerColl1[measureIndex] = headersCollection[actualIndex];
            return headerColl1.concat(headerColl2);
        };
        OlapEngine.prototype.getSubTotalsVisibility = function () {
            this.showRowSubTotals = this.dataSourceSettings.showRowSubTotals && this.dataSourceSettings.showSubTotals;
            this.showColumnSubTotals = this.dataSourceSettings.showColumnSubTotals && this.dataSourceSettings.showSubTotals;
            this.showSubTotalsAtTop = this.showColumnSubTotals && this.dataSourceSettings.subTotalsPosition === 'Top';
            this.showSubTotalsAtBottom = this.showRowSubTotals && this.dataSourceSettings.subTotalsPosition === 'Bottom';
            this.hideRowTotalsObject = {};
            this.hideColumnTotalsObject = {};
            var axisCount = 1;
            do {
                if (axisCount === 1) {
                    if (this.showColumnSubTotals) {
                        for (var cCnt = 0; cCnt < this.dataSourceSettings.columns.length; cCnt++) {
                            Iif (this.dataSourceSettings.columns[cCnt].showSubTotals === false) {
                                this.hideColumnTotalsObject[this.dataSourceSettings.columns[cCnt].name] = cCnt;
                            }
                        }
                    }
                }
                else {
                    if (this.showRowSubTotals) {
                        for (var rCnt = 0; rCnt < this.dataSourceSettings.rows.length; rCnt++) {
                            Iif (this.dataSourceSettings.rows[rCnt].showSubTotals === false) {
                                this.hideRowTotalsObject[this.dataSourceSettings.rows[rCnt].name] = rCnt;
                            }
                        }
                    }
                }
                axisCount++;
            } while (axisCount < 3);
        };
        OlapEngine.prototype.frameRowHeader = function (tuples) {
            var _this = this;
            this.headerGrouping = {};
            this.lastLevel = [];
            var isGrandTotalAdd = true;
            var position = this.pivotValues.length;
            var pivotValues = [];
            var valueContent = [];
            Eif (this.customArgs.action !== 'down') {
                pivotValues = this.pivotValues;
                valueContent = this.valueContent;
            }
            else {
                position = this.customArgs.drillInfo.currentCell.rowIndex + 1;
            }
            this.rowStartPos = this.rowStartPos > 0 ? this.rowStartPos : position;
            var tupPos = 0;
            var lastAllStartPos;
            var lastAllCount;
            var prevUNArray = [];
            var allType = {};
            var rowMembers = [];
            var availAllMember = false;
            var withoutAllStartPos = -1;
            var withoutAllEndPos = -1;
            var minLevel = [];
            var gTotals = [{
                    actualText: 'Grand Total',
                    axis: 'row',
                    colIndex: 0,
                    formattedText: 'Grand Total',
                    hasChild: false,
                    level: -1,
                    rowIndex: 0,
                    index: [],
                    type: 'grand sum',
                    ordinal: 0,
                    colSpan: 1,
                    rowSpan: 1,
                    memberType: 2,
                    isDrilled: false,
                    valueSort: { 'Grand Total': 1, levelName: 'Grand Total' }
                }];
            var maxLevel = [];
            var measurePos;
            var newTupPosition = (this.customArgs.drillInfo && this.customArgs.drillInfo.axis === 'row') ?
                (this.customArgs.drillInfo.currentCell.ordinal + 1) : 0;
            while (tupPos < tuples.length) {
                var members = tuples[tupPos].querySelectorAll('Member');
                maxLevel = this.frameTupCollection(members, maxLevel, (tupPos + newTupPosition), this.tupRowInfo, this.showRowSubTotals, this.hideRowTotalsObject, 'row');
                tupPos++;
            }
            tupPos = 0;
            var prevTupInfo;
            var tuplesLength = tuples.length;
            Iif (this.customArgs.action === 'down') {
                var ordinal = this.customArgs.drillInfo.currentCell.ordinal + 1;
                tupPos = ordinal;
                tuplesLength += ordinal;
                lastAllCount = this.tupRowInfo[ordinal - 1].allCount;
                lastAllStartPos = this.tupRowInfo[ordinal - 1].allStartPos;
                prevTupInfo = this.tupRowInfo[ordinal - 1];
            }
            var startTupPos = tupPos;
            var pagingAllowFlag = true;
            var lastMesPos = 0;
            var isGrandTotalTop = false;
            var subTotals = [];
            while (tupPos < tuplesLength && pagingAllowFlag) {
                var members = tuples[this.customArgs.action === 'down' ?
                    (tupPos - (this.customArgs.drillInfo.currentCell.ordinal + 1)) : tupPos].querySelectorAll('Member');
                var memPos = 0;
                var prevParent = void 0;
                var allCount = this.tupRowInfo[tupPos].allCount;
                var allStartPos = this.tupRowInfo[tupPos].allStartPos;
                var measure = this.tupRowInfo[tupPos].measure;
                var typeColl = this.tupRowInfo[tupPos].typeCollection;
                var drillStartPos = this.tupRowInfo[tupPos].drillStartPos;
                var startDrillUniquename = this.tupRowInfo[tupPos].startDrillUniquename;
                if (tupPos === 0 || tupPos === startTupPos) {
                    var firstTupMembers = this.customArgs.action === 'down' ? this.tupRowInfo[0].members : members;
                    while (memPos < firstTupMembers.length) {
                        if (firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '1' &&
                            Number(firstTupMembers[memPos].querySelector('LNum').textContent) === 0) {
                            minLevel[memPos] = 0;
                        }
                        else {
                            minLevel[memPos] = Number(firstTupMembers[memPos].querySelector('LNum').textContent);
                        }
                        if (firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '1') {
                            allType[memPos] = 0;
                            withoutAllStartPos = withoutAllStartPos === -1 ? memPos : withoutAllStartPos;
                            withoutAllEndPos = memPos;
                        }
                        else {
                            allType[memPos] = 1;
                            availAllMember = firstTupMembers[memPos].querySelector('MEMBER_TYPE').textContent === '3' ? availAllMember : true;
                        }
                        memPos++;
                    }
                    measurePos = typeColl.indexOf('3');
                }
                memPos = 0;
                if (tupPos === 0 && (members.length > (allCount + (measure ? 1 : 0)) || (members.length === 1 && measure))) {
                    gTotals.pop();
                }
                Eif ((tupPos === 0 && this.isPaging) ? gTotals.length === 0 :
                    (!availAllMember || allCount === lastAllCount || allStartPos !== lastAllStartPos || (members.length === 1 && measure))) {
                    var attrDrill = this.checkAttributeDrill(this.tupRowInfo[tupPos].drillInfo, 'rows');
                    var drillAllow = drillStartPos > -1 ? (allCount > 0 ? (attrDrill || allStartPos > drillStartPos) : true) : true;
                    drillAllow = (prevTupInfo && drillAllow && drillStartPos > -1) ?
                        (prevTupInfo.startDrillUniquename !== startDrillUniquename ? true :
                            ((withoutAllEndPos > prevTupInfo.measurePosition ? false :
                                prevTupInfo.measureName !== this.tupRowInfo[tupPos].measureName) &&
                                (allStartPos === (drillStartPos + 1) ||
                                    this.tupRowInfo[tupPos].measurePosition === (drillStartPos + 1))))
                        : drillAllow;
                    var withoutAllAllow = (withoutAllStartPos > -1 && allCount > 0) ?
                        (attrDrill || allStartPos > withoutAllEndPos) : true;
                    isGrandTotalTop = this.dataSourceSettings.grandTotalsPosition === 'Top' && this.olapRowValueIndex === 0 &&
                        this.olapValueAxis === 'row'
                        && this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showRowGrandTotals &&
                        (this.olapValueAxis === 'row' ? this.dataSourceSettings.rows.length > 1 : true);
                    Iif (isGrandTotalTop && gTotals.length === 1) {
                        gTotals = this.frameGrandTotalValues(tuples, gTotals, typeColl, measurePos);
                    }
                    if (members.length === allCount + (measure ? 1 : 0) && measure && !isGrandTotalTop) {
                        var levelName = 'Grand Total' + this.valueSortSettings.headerDelimiter +
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption ?
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption :
                            members[measurePos].querySelector('Caption').textContent;
                        var formattedText = (typeColl[measurePos] === '3' &&
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)] &&
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption) ?
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption :
                            members[measurePos].querySelector('Caption').textContent;
                        gTotals = this.frameGrandTotalAxisSet(gTotals, this.getUniqueName(members[measurePos].querySelector('UName').textContent), formattedText, position, tupPos, Number(typeColl[measurePos]), members[measurePos].querySelector('PARENT_UNIQUE_NAME') ?
                            members[measurePos].querySelector('PARENT_UNIQUE_NAME').textContent : undefined, members[measurePos].querySelector('LName').textContent, members[measurePos].getAttribute('Hierarchy'), {
                            levelName: levelName, axis: members[measurePos].getAttribute('Hierarchy')
                        });
                        gTotals[gTotals.length - 1].valueSort[levelName] = 1;
                    }
                    else if (!(allStartPos === 0 || (measurePos === 0 && allStartPos === 1)) && drillAllow && withoutAllAllow) {
                        if (this.dataSourceSettings.grandTotalsPosition === 'Top' && isGrandTotalAdd && this.dataSourceSettings.showGrandTotals &&
                            (this.olapValueAxis === 'row' ? this.dataSourceSettings.rows.length > 1 : true)) {
                            this.insertRowGrandTotal(gTotals, valueContent, pivotValues, tuples, position);
                            position = this.pivotValues.length;
                            isGrandTotalAdd = false;
                        }
                        prevTupInfo = this.tupRowInfo[tupPos];
                        var lastPos = position;
                        var lastMemPos = memPos;
                        prevParent = {};
                        var withoutAllDrilled = false;
                        while (memPos < members.length && pagingAllowFlag) {
                            var member = members[memPos];
                            if (member.querySelector('UName').textContent !== prevUNArray[memPos] && typeColl[memPos] !== '2'
                                && ((Object.keys(prevParent).length > 0 ? (prevParent.isDrilled &&
                                    !this.fieldList[prevParent.hierarchy].isHierarchy) : withoutAllDrilled) ?
                                    (typeColl[memPos] === '3' && (allType[memPos - 1] && allType[memPos + 1] !== 0)) : true)) {
                                var lvl = Number(member.querySelector('LNum').textContent) -
                                    ((allType[memPos] && typeColl[memPos] !== '3') ? 1 : minLevel[memPos]);
                                var isNamedSet = this.namedSetsPosition['row'][memPos] ? true : false;
                                var uniqueName = this.getUniqueName(member.querySelector('UName').textContent);
                                var depth = this.getDepth(this.tupRowInfo[tupPos], uniqueName, Number(typeColl[memPos]));
                                var levelName = this.getCaptionCollectionWithMeasure(this.tupRowInfo[tupPos], memPos, true);
                                Iif (this.showSubTotalsAtBottom && position > this.rowStartPos) {
                                    lastPos = position = this.insertRowSubTotal(pivotValues, valueContent, subTotals, position, lvl, levelName);
                                }
                                Eif (!(this.isPaging && pivotValues[lastMesPos][0] &&
                                    this.fieldList[pivotValues[lastMesPos][0].hierarchy] &&
                                    this.fieldList[pivotValues[lastMesPos][0].hierarchy].isHierarchy &&
                                    pivotValues[lastMesPos][0].hasChild &&
                                    !pivotValues[lastMesPos][0].isDrilled &&
                                    !this.rows[memPos].isNamedSet && (this.rows[memPos].name.indexOf('[Measures]') === 0 ||
                                    (this.fieldList[member.getAttribute('Hierarchy')] &&
                                        (this.fieldList[member.getAttribute('Hierarchy')].isHierarchy ||
                                            this.fieldList[member.getAttribute('Hierarchy')].hasAllMember))) &&
                                    pivotValues[lastMesPos][0].depth < depth)) {
                                    pivotValues[position] = [{
                                            axis: 'row',
                                            actualText: uniqueName,
                                            colIndex: 0,
                                            formattedText: (typeColl[memPos] === '3' && this.dataFields[uniqueName] &&
                                                this.dataFields[uniqueName].caption) ? this.dataFields[uniqueName].caption :
                                                member.querySelector('Caption').textContent,
                                            hasChild: (this.fieldList[member.getAttribute('Hierarchy')] &&
                                                this.fieldList[member.getAttribute('Hierarchy')].isHierarchy && memPos < this.rows.length - 1 &&
                                                !this.rows[memPos + 1].isNamedSet && this.rows[memPos + 1].name.indexOf('[Measures]') < 0 &&
                                                this.fieldList[this.rows[memPos + 1].name] &&
                                                this.fieldList[this.rows[memPos + 1].name].hasAllMember) ? true :
                                                Number(member.querySelector('CHILDREN_CARDINALITY').textContent) > 0 ? true : false,
                                            level: lvl,
                                            depth: depth,
                                            rowIndex: position,
                                            index: [],
                                            ordinal: tupPos,
                                            type: 'header',
                                            colSpan: 1,
                                            rowSpan: 1,
                                            memberType: Number(typeColl[memPos]),
                                            isDrilled: (this.fieldList[member.getAttribute('Hierarchy')] &&
                                                this.fieldList[member.getAttribute('Hierarchy')].isHierarchy &&
                                                !this.isAttributeDrill(member.getAttribute('Hierarchy'), this.tupRowInfo[tupPos].drillInfo, 'rows')) ? true : this.tupRowInfo[tupPos].drillInfo[memPos].isDrilled,
                                            parentUniqueName: member.querySelector('PARENT_UNIQUE_NAME') ?
                                                member.querySelector('PARENT_UNIQUE_NAME').textContent : undefined,
                                            levelUniqueName: member.querySelector('LName').textContent,
                                            hierarchy: member.getAttribute('Hierarchy'),
                                            isNamedSet: isNamedSet,
                                            valueSort: { levelName: '', axis: member.getAttribute('Hierarchy') }
                                        }];
                                    if (this.olapVirtualization && pivotValues[position][0].type === 'header') {
                                        delete pivotValues[position][0].type;
                                    }
                                    prevParent = typeColl[memPos] !== '3' ? pivotValues[position][0] : prevParent;
                                    Iif (!prevParent) {
                                        rowMembers.push(member.querySelector('Caption').textContent);
                                    }
                                    levelName = this.getCaptionCollectionWithMeasure(this.tupRowInfo[tupPos], memPos, false);
                                    pivotValues[position][0].valueSort.levelName = levelName;
                                    pivotValues[position][0].valueSort[levelName] = 1;
                                    valueContent[position - this.rowStartPos] = {};
                                    valueContent[position - this.rowStartPos][0] = pivotValues[position][0];
                                    if (measure && measurePos > memPos) {
                                        prevUNArray[measurePos] = '';
                                    }
                                    for (var pos = memPos + 1; pos < members.length; pos++) {
                                        prevUNArray[pos] = '';
                                    }
                                    prevUNArray[memPos] = member.querySelector('UName').textContent;
                                    lastMesPos = Number(typeColl[memPos]) !== 3 ? position : lastMesPos;
                                    position++;
                                    lastMemPos = memPos;
                                }
                            }
                            else if (typeColl[memPos] === '2') {
                                lastMemPos = memPos;
                            }
                            else {
                                Iif (this.tupRowInfo[tupPos].drillInfo[memPos].isDrilled &&
                                    allType[memPos] === 0) {
                                    withoutAllDrilled = true;
                                }
                            }
                            Iif (this.tupRowInfo[tupPos].drillInfo[memPos].isDrilled &&
                                this.tupRowInfo[tupPos].showTotals) {
                                this.tupRowInfo[tupPos].showTotals = !this.showRowSubTotals ? false :
                                    this.hideRowTotalsObject[this.tupRowInfo[tupPos].drillInfo[memPos].hierarchy] ===
                                        undefined;
                            }
                            memPos++;
                        }
                        Eif (lastPos < position && lastMemPos >= (members.length - 1)) {
                            pivotValues[position - 1][0].ordinal = tupPos;
                            if (pivotValues[position - 1][0].type === 'header') {
                                delete pivotValues[position - 1][0].type;
                            }
                        }
                    }
                    lastAllCount = allCount;
                    lastAllStartPos = allStartPos;
                }
                tupPos++;
            }
            Iif (this.showSubTotalsAtBottom && subTotals.length > 0) {
                subTotals.reverse();
                subTotals.forEach(function (axis) {
                    pivotValues[position] = [axis];
                    valueContent[position - _this.rowStartPos] = {};
                    valueContent[position - _this.rowStartPos][0] = pivotValues[position][0];
                    position++;
                });
            }
            if (!(this.dataSourceSettings.grandTotalsPosition === 'Top') || (this.olapValueAxis === 'row' &&
                this.dataSourceSettings.rows.length === 1 && this.dataSourceSettings.grandTotalsPosition === 'Top') ||
                this.dataSourceSettings.rows.length === 0) {
                this.insertRowGrandTotal(gTotals, valueContent, pivotValues, tuples, position);
            }
        };
        OlapEngine.prototype.insertRowSubTotal = function (pivotValues, valueContent, subTotals, position, lvl, levelName) {
            var prevRowParent = util_1.PivotUtil.frameHeaderWithKeys(pivotValues[position - 1][0]);
            if (prevRowParent.level < lvl && prevRowParent.type !== 'grand sum' && (prevRowParent.isDrilled ||
                prevRowParent.memberType === 3)) {
                if (prevRowParent.memberType === 3) {
                    var valueCells = [];
                    var index = 1;
                    while (pivotValues[position - index][0].memberType === 3) {
                        valueCells[valueCells.length] = pivotValues[position - index][0];
                        index++;
                    }
                    if (pivotValues[position - index][0].isDrilled && valueCells.length !== 0) {
                        for (var i = 0, axislength = valueCells.length; i < axislength; i++) {
                            valueCells[i].formattedText =
                                pivotValues[position - index][0].formattedText + ' ' + valueCells[i].formattedText;
                            valueCells[i].isSum = true;
                            valueCells[i].type = 'sum';
                            valueCells[i].parentUniqueName = pivotValues[position - index][0].levelUniqueName;
                            subTotals[subTotals.length] = valueCells[i];
                        }
                        index--;
                        position -= index;
                    }
                }
                else {
                    prevRowParent.hasChild = false;
                    prevRowParent.isDrilled = false;
                    prevRowParent.isSum = true;
                    prevRowParent.type = 'sum';
                    prevRowParent.formattedText = prevRowParent.formattedText + ' Total';
                    subTotals[Object.keys(subTotals).length] = prevRowParent;
                }
            }
            if (subTotals.length > 0) {
                var j = subTotals.length - 1;
                var subTotalLevel = subTotals[j].valueSort.levelName.split('.').length;
                var nextLevels = levelName.split('.').length;
                while (subTotalLevel >= nextLevels) {
                    pivotValues[position] = [subTotals[j]];
                    valueContent[position - this.rowStartPos] = {};
                    valueContent[position - this.rowStartPos][0] = pivotValues[position][0];
                    position++;
                    subTotals.splice(subTotals.length - 1, 1);
                    if (Object.keys(subTotals).length > 0) {
                        j--;
                        subTotalLevel = subTotals[j].valueSort.levelName.split('.').length;
                    }
                    else {
                        break;
                    }
                }
            }
            return position;
        };
        OlapEngine.prototype.insertRowGrandTotal = function (gTotals, valueContent, pivotValues, tuples, position) {
            Iif (gTotals.length > 1 && gTotals[0].memberType !== 3) {
                gTotals[0].ordinal = -1;
            }
            Eif (this.customArgs.action !== 'down') {
                var grandTotalFlag = this.dataSourceSettings.rows.length === 0 ||
                    (this.dataSourceSettings.rows.length === 1 && this.dataSourceSettings.rows[0].name === '[Measures]');
                if ((this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showRowGrandTotals) || grandTotalFlag) {
                    for (var totPos = 0; totPos < gTotals.length; totPos++) {
                        gTotals[totPos].rowIndex = position;
                        pivotValues[position] = [gTotals[totPos]];
                        valueContent[position - this.rowStartPos] = {};
                        valueContent[position - this.rowStartPos][0] = pivotValues[position][0];
                        position++;
                    }
                }
            }
            else {
                this.updateRowEngine(pivotValues, valueContent, tuples.length);
                this.onDemandDrillEngine = pivotValues;
            }
            return gTotals;
        };
        OlapEngine.prototype.frameGrandTotalAxisSet = function (gTotals, actualText, formattedText, rowIndex, ordinal, memberType, parentUniqueName, levelUniqueName, hierarchy, valueSort) {
            gTotals.push({
                axis: 'row',
                actualText: actualText,
                colIndex: 0,
                formattedText: formattedText,
                hasChild: false,
                level: -1,
                rowIndex: rowIndex,
                index: [],
                ordinal: ordinal,
                colSpan: 1,
                rowSpan: 1,
                memberType: memberType,
                isDrilled: false,
                parentUniqueName: parentUniqueName,
                levelUniqueName: levelUniqueName,
                hierarchy: hierarchy,
                valueSort: valueSort
            });
            return gTotals;
        };
        OlapEngine.prototype.getDepth = function (tupInfo, uniqueName, memberType) {
            var memberPosition = tupInfo.uNameCollection.indexOf(uniqueName);
            var cropUName = tupInfo.uNameCollection.substring(0, memberPosition) +
                (memberType === 3 ? '' : uniqueName);
            var fieldSep = cropUName.split('::[').map(function (item) {
                return item[0] === '[' ? item : ('[' + item);
            });
            if (memberType === 3 && this.rowMeasurePos === fieldSep.length) {
                fieldSep.push(uniqueName);
            }
            var nxtIndextCount = -1;
            for (var fPos = 0; fPos < fieldSep.length; fPos++) {
                var fieldMembers = fieldSep[fPos];
                var membersCount = fieldMembers.split('~~').length;
                nxtIndextCount += membersCount;
            }
            return nxtIndextCount;
        };
        OlapEngine.prototype.checkAttributeDrill = function (drillInfo, axis) {
            var isDrill = false;
            for (var i = 0; i < drillInfo.length; i++) {
                isDrill = this.isAttributeDrill(drillInfo[i].hierarchy, drillInfo, axis);
                if (isDrill) {
                    break;
                }
            }
            return isDrill;
        };
        OlapEngine.prototype.frameTupCollection = function (members, maxLevel, tupPos, tupInfo, showSubTotals, hideTotalsObject, axis) {
            var _a, _b;
            var memPos = 0;
            var allCount = 0;
            var allStartPos;
            var measure;
            var measureName;
            var measurePosition;
            var typeColl = [];
            var levelColl = [];
            var drillState = [];
            var uNameCollection = '';
            var captionCollection = '';
            var showTotals = true;
            var hideFieldPos = -1;
            while (memPos < members.length) {
                var member = members[memPos];
                var memberlevel = Number(member.querySelector('LNum').textContent);
                var memberUName = member.querySelector('UName').textContent;
                if (Number(member.querySelector('MEMBER_TYPE').textContent) > 3) {
                    member.querySelector('MEMBER_TYPE').textContent = memberUName.indexOf('[Measures]') === 0 ? '3' : '1';
                }
                var memberType = memberUName.indexOf('[Measures]') === 0 ? '3' :
                    (Number(member.querySelector('MEMBER_TYPE').textContent) > 3 ? '1' : member.querySelector('MEMBER_TYPE').textContent);
                var memberCaption = member.querySelector('Caption').textContent;
                if (this.fieldList[memberCaption] && this.fieldList[memberCaption].type === 'CalculatedField') {
                    memberCaption = this.fieldList[memberCaption].caption;
                    member.querySelector('Caption').textContent = memberCaption;
                }
                var hierarchy = member.getAttribute('Hierarchy');
                var parentUName = member.querySelector('PARENT_UNIQUE_NAME') ?
                    member.querySelector('PARENT_UNIQUE_NAME').textContent : '';
                if (memberType === '2') {
                    Eif (!this.isPaging) {
                        allCount++;
                    }
                    allStartPos = ej2_base_1.isNullOrUndefined(allStartPos) ? memPos : allStartPos;
                }
                else if (memberType === '3') {
                    measure = member;
                    measureName = memberUName;
                    measurePosition = memPos;
                    if (axis === 'column') {
                        this.colMeasures[memberUName] = member;
                        this.colMeasurePos = memPos;
                    }
                    else {
                        this.rowMeasurePos = memPos;
                    }
                }
                else {
                    hideFieldPos = hideTotalsObject[hierarchy];
                }
                if (memberType !== '2') {
                    if (this.headerGrouping[memPos]) {
                        if (memberlevel > this.lastLevel[memPos]) {
                            this.lastLevel[memPos] = memberlevel;
                        }
                        else if (memberlevel < this.lastLevel[memPos]) {
                            var levelPos = this.lastLevel[memPos];
                            while (levelPos >= memberlevel) {
                                delete this.headerGrouping[memPos].UName[levelPos];
                                delete this.headerGrouping[memPos].Caption[levelPos];
                                levelPos--;
                            }
                            this.lastLevel[memPos] = memberlevel;
                        }
                        this.headerGrouping[memPos].UName[memberlevel] = memberUName;
                        this.headerGrouping[memPos].Caption[memberlevel] = memberCaption;
                    }
                    else {
                        this.lastLevel[memPos] = memberlevel;
                        this.headerGrouping[memPos] = {
                            UName: (_a = {}, _a[memberlevel] = memberUName, _a),
                            Caption: (_b = {}, _b[memberlevel] = memberCaption, _b)
                        };
                    }
                    if (this.isPaging) {
                        var currUName = parentUName;
                        while (this.drilledSets[currUName]) {
                            var currCaption = this.drilledSets[currUName].querySelector('Caption').textContent;
                            var currLevel = Number(this.drilledSets[currUName].querySelector('LNum').textContent);
                            this.headerGrouping[memPos].UName[currLevel] = currUName;
                            this.headerGrouping[memPos].Caption[currLevel] = currCaption;
                            currUName = this.drilledSets[currUName].querySelector('PARENT_UNIQUE_NAME') === null ? '' :
                                this.drilledSets[currUName].querySelector('PARENT_UNIQUE_NAME').textContent;
                        }
                    }
                    var uNames = '';
                    var uNamesKeys = Object.keys(this.headerGrouping[memPos].UName);
                    for (var i = 0; i < uNamesKeys.length; i++) {
                        var j = uNamesKeys[i];
                        if (i === 0) {
                            uNames = this.headerGrouping[memPos].UName[Number(j)];
                        }
                        else {
                            uNames = uNames + '~~' + this.headerGrouping[memPos].UName[Number(j)];
                        }
                    }
                    uNameCollection = uNameCollection === '' ? uNames :
                        (uNameCollection + '::' + uNames);
                    var captions = '';
                    var captionsKeys = Object.keys(this.headerGrouping[memPos].Caption);
                    for (var i = 0; i < captionsKeys.length; i++) {
                        var j = captionsKeys[i];
                        if (i === 0) {
                            captions = this.headerGrouping[memPos].Caption[Number(j)];
                        }
                        else {
                            captions = captions + '~~' + this.headerGrouping[memPos].Caption[Number(j)];
                        }
                    }
                    if (memPos !== measurePosition) {
                        captionCollection = captionCollection === '' ? captions :
                            (captionCollection + '::' + captions);
                    }
                }
                typeColl.push(memberType);
                levelColl.push(memberlevel);
                if (ej2_base_1.isNullOrUndefined(maxLevel[memPos]) || maxLevel[memPos] < memberlevel) {
                    maxLevel[memPos] = memberlevel;
                }
                drillState.push({ level: memberlevel, uName: memberUName, hierarchy: hierarchy, isDrilled: false });
                if (tupInfo[tupPos - 1] && tupInfo[tupPos - 1].typeCollection[memPos] === '1' &&
                    drillState[memPos].level > tupInfo[tupPos - 1].drillInfo[memPos].level) {
                    var uCollection = uNameCollection.split(/~~|::\[/).map(function (item) {
                        return item[0] === '[' ? item : ('[' + item);
                    });
                    uCollection.pop();
                    var parentLevel = uCollection.join('~~');
                    this.setDrillInfo(parentUName, parentLevel, memPos, tupPos, tupInfo);
                }
                memPos++;
            }
            Iif (hideFieldPos > -1) {
                showTotals = typeColl[hideFieldPos + 1] !== '2';
            }
            tupInfo[tupPos] = {
                allCount: allCount,
                allStartPos: allStartPos,
                measure: measure,
                measureName: measureName,
                measurePosition: measurePosition,
                members: members,
                typeCollection: typeColl,
                uNameCollection: uNameCollection,
                captionCollection: captionCollection,
                levelCollection: levelColl,
                drillInfo: drillState,
                drillStartPos: -1,
                drillEndPos: -1,
                showTotals: (!showSubTotals && allCount > 0 && allStartPos > (measurePosition === 0 ? 1 : 0)) ? false : showTotals
            };
            return maxLevel;
        };
        OlapEngine.prototype.getCaptionCollectionWithMeasure = function (tuple, memPos, isAddTotals) {
            var captionColection = tuple.captionCollection;
            var isMeasureAdd = true;
            if (!isAddTotals && tuple.typeCollection[memPos] !== '3') {
                for (var i = 0; i < this.measurePosition; i++) {
                    Eif (tuple.drillInfo[memPos].hierarchy === this.dataSourceSettings.rows[i].name) {
                        isMeasureAdd = false;
                        break;
                    }
                }
            }
            if (tuple.measure && isMeasureAdd) {
                var uName = this.getUniqueName(tuple.measure.querySelector('UName').textContent);
                var measureName = this.dataFields[uName] && this.dataFields[uName].caption ?
                    this.dataFields[uName].caption : tuple.measure.querySelector('Caption').textContent;
                var measurePosition = tuple.uNameCollection.split(/[~~::]+/g).indexOf(tuple.measureName);
                var captionCollectionArray = tuple.captionCollection.split(/[~~::]+/g);
                captionCollectionArray.splice(measurePosition, 0, measureName);
                captionColection = captionCollectionArray.join(this.valueSortSettings.headerDelimiter);
            }
            else {
                var captionCollectionArray = tuple.captionCollection.split(/[~~::]+/g);
                captionColection = captionCollectionArray.join(this.valueSortSettings.headerDelimiter);
            }
            return captionColection;
        };
        OlapEngine.prototype.setNamedSetsPosition = function () {
            this.namedSetsPosition = {};
            var axis = 0;
            do {
                var setsPositions = {};
                var axisFields = axis ? this.dataSourceSettings.rows : this.dataSourceSettings.columns;
                for (var fPos = 0; fPos < axisFields.length; fPos++) {
                    Iif (axisFields[fPos].isNamedSet) {
                        setsPositions[fPos] = axisFields[fPos].name;
                    }
                }
                this.namedSetsPosition[axis ? 'row' : 'column'] = setsPositions;
                axis++;
            } while (axis < 2);
        };
        OlapEngine.prototype.updateRowEngine = function (pivotValues, valueContent, tuplesLength) {
            var currEngineCount = this.pivotValues.length - 1;
            var newEngineCount = Object.keys(pivotValues).length;
            while (currEngineCount > this.customArgs.drillInfo.currentCell.rowIndex) {
                this.pivotValues[currEngineCount + newEngineCount] = this.pivotValues[currEngineCount];
                this.pivotValues[currEngineCount + newEngineCount][0].ordinal += tuplesLength;
                this.pivotValues[currEngineCount + newEngineCount][0].rowIndex += newEngineCount;
                this.valueContent[(currEngineCount + newEngineCount) - this.rowStartPos] =
                    this.valueContent[currEngineCount - this.rowStartPos];
                currEngineCount--;
            }
            for (var key = 0; key < pivotValues.length; key++) {
                this.pivotValues[key] = pivotValues[key];
                this.valueContent[Number(key) - this.rowStartPos] = valueContent[Number(key) - this.rowStartPos];
            }
            this.pivotValues[this.customArgs.drillInfo.currentCell.rowIndex][0].isDrilled = true;
        };
        OlapEngine.prototype.updateTupCollection = function (newTuplesCount) {
            var tupCollection = this.customArgs.drillInfo.axis === 'row' ? this.tupRowInfo : this.tupColumnInfo;
            var currTupCount = tupCollection.length - 1;
            while (currTupCount > this.customArgs.drillInfo.currentCell.ordinal) {
                tupCollection[currTupCount + newTuplesCount] = tupCollection[currTupCount];
                currTupCount--;
            }
        };
        OlapEngine.prototype.frameGrandTotalValues = function (tuples, gTotals, typeColl, measurePos) {
            var tupPos = 0;
            var lastAllStartPos;
            var lastAllCount;
            var availAllMember = false;
            var withoutAllEndPos = -1;
            var isGrandtoalDataAdd = false;
            var prevTupInfo;
            var isGrandTotalTop = false;
            while (tupPos < tuples.length && !isGrandtoalDataAdd) {
                var members = tuples[this.customArgs.action === 'down' ?
                    (tupPos - (this.customArgs.drillInfo.currentCell.ordinal + 1)) : tupPos].querySelectorAll('Member');
                var allCount = this.tupRowInfo[tupPos].allCount;
                var allStartPos = this.tupRowInfo[tupPos].allStartPos;
                var measure = this.tupRowInfo[tupPos].measure;
                var typeColl_1 = this.tupRowInfo[tupPos].typeCollection;
                var drillStartPos = this.tupRowInfo[tupPos].drillStartPos;
                var startDrillUniquename = this.tupRowInfo[tupPos].startDrillUniquename;
                if (tupPos === 0 && (members.length > (allCount + (measure ? 1 : 0)) || (members.length === 1 && measure))) {
                    gTotals.pop();
                }
                if ((tupPos === 0 && this.isPaging) ? gTotals.length === 0 :
                    (!availAllMember || allCount === lastAllCount || allStartPos !== lastAllStartPos || (members.length === 1 && measure))) {
                    var attrDrill = this.checkAttributeDrill(this.tupRowInfo[tupPos].drillInfo, 'rows');
                    var drillAllow = drillStartPos > -1 ? (allCount > 0 ? (attrDrill || allStartPos > drillStartPos) : true) : true;
                    drillAllow = (prevTupInfo && drillAllow && drillStartPos > -1) ?
                        (prevTupInfo.startDrillUniquename !== startDrillUniquename ? true :
                            ((withoutAllEndPos > prevTupInfo.measurePosition ? false :
                                prevTupInfo.measureName !== this.tupRowInfo[tupPos].measureName) &&
                                (allStartPos === (drillStartPos + 1) ||
                                    this.tupRowInfo[tupPos].measurePosition === (drillStartPos + 1))))
                        : drillAllow;
                    if (members.length === allCount + (measure ? 1 : 0) && measure && !isGrandTotalTop) {
                        var levelName = 'Grand Total' + this.valueSortSettings.headerDelimiter +
                            members[measurePos].querySelector('Caption').textContent;
                        var formattedText = (typeColl_1[measurePos] === '3' &&
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)] &&
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption) ?
                            this.dataFields[this.getUniqueName(members[measurePos].querySelector('UName').textContent)].caption :
                            members[measurePos].querySelector('Caption').textContent;
                        gTotals = this.frameGrandTotalAxisSet(gTotals, this.getUniqueName(members[measurePos].querySelector('UName').textContent), formattedText, this.pivotValues.length, tupPos, Number(typeColl_1[measurePos]), members[measurePos].querySelector('PARENT_UNIQUE_NAME') ?
                            members[measurePos].querySelector('PARENT_UNIQUE_NAME').textContent : undefined, members[measurePos].querySelector('LName').textContent, members[measurePos].getAttribute('Hierarchy'), {
                            levelName: levelName, axis: members[measurePos].getAttribute('Hierarchy')
                        });
                        gTotals[gTotals.length - 1].valueSort['Grand Total' + this.valueSortSettings.headerDelimiter +
                            members[measurePos].querySelector('Caption').textContent] = 1;
                    }
                    lastAllCount = allCount;
                    lastAllStartPos = allStartPos;
                }
                isGrandtoalDataAdd = this.dataSourceSettings.values.length + 1 === gTotals.length ? true : false;
                tupPos++;
            }
            return gTotals;
        };
        OlapEngine.prototype.frameColumnHeader = function (tuples) {
            var _this = this;
            this.headerGrouping = {};
            this.lastLevel = [];
            var tupPos = 0;
            var maxLevel = [];
            var allType = [];
            var minLevel = [];
            var withoutAllStartPos = -1;
            var withoutAllEndPos = -1;
            var newTupPosition = (this.customArgs.drillInfo && this.customArgs.drillInfo.axis === 'column') ?
                (this.customArgs.drillInfo.currentCell.ordinal + 1) : 0;
            while (tupPos < tuples.length) {
                var members = tuples[tupPos].querySelectorAll('Member');
                maxLevel = this.frameTupCollection(members, maxLevel, (tupPos + newTupPosition), this.tupColumnInfo, this.showColumnSubTotals, this.hideColumnTotalsObject, 'column');
                tupPos++;
            }
            if (this.olapVirtualization) {
                maxLevel = maxLevel.slice(0, maxLevel.length - 1).map(function (level) { return level === 0 ? 1 : level; }).concat(maxLevel.slice(maxLevel.length - 1));
            }
            if (tuples.length > 0) {
                var members = tuples[0].querySelectorAll('Member');
                var memPos = 0;
                while (memPos < members.length) {
                    minLevel[memPos] = (members[memPos].querySelector('MEMBER_TYPE').textContent === '1' &&
                        Number(members[memPos].querySelector('LNum').textContent) === 0) ? 0 :
                        Number(members[memPos].querySelector('LNum').textContent);
                    if (members[memPos].querySelector('MEMBER_TYPE').textContent === '1' &&
                        (this.isPaging || Number(members[memPos].querySelector('LNum').textContent) === 0)) {
                        allType[memPos] = 0;
                        withoutAllStartPos = withoutAllStartPos === -1 ? memPos : withoutAllStartPos;
                        withoutAllEndPos = memPos;
                    }
                    else {
                        allType[memPos] = 1;
                    }
                    memPos++;
                }
            }
            tupPos = 0;
            var position = 1;
            var lastSavedInfo = {};
            var isSubTotIncluded = true;
            var withoutAllAvail = false;
            var lastRealTup;
            var _loop_2 = function () {
                var members = tuples[tupPos].querySelectorAll('Member');
                var allCount = this_2.tupColumnInfo[tupPos].allCount;
                var allStartPos = this_2.tupColumnInfo[tupPos].allStartPos;
                var measure = this_2.tupColumnInfo[tupPos].measure;
                var typeColl = this_2.tupColumnInfo[tupPos].typeCollection;
                var drillInfo = this_2.tupColumnInfo[tupPos].drillInfo;
                var drillStartPos = this_2.tupColumnInfo[tupPos].drillStartPos;
                var startDrillUniquename = this_2.tupColumnInfo[tupPos].startDrillUniquename;
                var endDrillUniquename = this_2.tupColumnInfo[tupPos].endDrillUniquename;
                var drillEndPos = this_2.tupColumnInfo[tupPos].drillEndPos;
                var levelColl = this_2.tupColumnInfo[tupPos].levelCollection;
                var isStartCol = typeColl[0] === '2' ? false : (typeColl[0] === '3' ? typeColl[1] !== '2' : true);
                var depth = 0;
                maxLevel.map(function (item, pos) {
                    depth = depth + (allType[pos] === 0 ? (item + (1 - (minLevel[pos] > 1 ? 1 : minLevel[pos]))) :
                        (item === 0 ? ((_this.isPaging && typeColl[pos] === '2') ? 0 : 1) : item));
                });
                this_2.colDepth = this_2.colDepth > depth ? this_2.colDepth : depth;
                if (tupPos === 0 && members.length > (allCount + (measure ? 1 : 0))) {
                    withoutAllAvail = true;
                    isStartCol = (allCount > 0 && isStartCol) ? (allStartPos > withoutAllStartPos) : isStartCol;
                }
                var isGrandTotalTop = false;
                if (this_2.dataSourceSettings.grandTotalsPosition === 'Top' && this_2.dataSourceSettings.showGrandTotals &&
                    this_2.dataSourceSettings.showColumnGrandTotals) {
                    var count = 0;
                    for (var i = 0; i < members.length; i++) {
                        if ((members[i].querySelector('Caption').textContent).indexOf('All') === 0) {
                            count++;
                        }
                    }
                    isGrandTotalTop = count === (this_2.olapValueAxis === 'column' ? this_2.dataSourceSettings.columns.length - 1 :
                        this_2.dataSourceSettings.columns.length);
                }
                if (isStartCol || isGrandTotalTop) {
                    if (allCount === 0 || isGrandTotalTop) {
                        var levelComp = [-1, -1, -1];
                        if (this_2.tupColumnInfo[tupPos - 1] && this_2.tupColumnInfo[tupPos - 1].allCount === 0) {
                            levelComp = this_2.levelCompare(levelColl, this_2.tupColumnInfo[tupPos - 1].levelCollection);
                        }
                        else Iif (withoutAllAvail && lastRealTup) {
                            levelComp = this_2.levelCompare(levelColl, lastRealTup.levelCollection);
                        }
                        if (this_2.tupColumnInfo[tupPos].drillStartPos < 0 || this_2.showSubTotalsAtTop) {
                            if (!isSubTotIncluded && levelComp[0] > -1 && levelComp[2] > -1) {
                                position = this_2.mergeTotCollection(position, allCount, maxLevel, minLevel, allType, allStartPos, drillInfo, levelComp);
                            }
                            this_2.setParentCollection(members);
                            this_2.frameCommonColumnLoop(members, tupPos, position, maxLevel, allType, minLevel);
                            Iif (!this_2.tupColumnInfo[tupPos].showTotals) {
                                position--;
                            }
                            if (!isSubTotIncluded && levelComp[0] > -1 && levelComp[2] > -1) {
                                position = this_2.mergeTotCollection(position, allCount, maxLevel, minLevel, allType, allStartPos, drillInfo, levelComp);
                            }
                            isSubTotIncluded = false;
                            Eif (!this_2.isColDrill) {
                                position++;
                            }
                            else {
                                this_2.isColDrill = false;
                            }
                        }
                        else Eif (lastSavedInfo.drillStartPos === drillStartPos ?
                            (lastSavedInfo.startDrillUniquename !== startDrillUniquename ||
                                lastSavedInfo.allCount === allCount) : true) {
                            Iif (!isSubTotIncluded && levelComp[0] > -1 && levelComp[2] > -1) {
                                position = this_2.mergeTotCollection(position, allCount, maxLevel, minLevel, allType, allStartPos, drillInfo, levelComp);
                                isSubTotIncluded = true;
                            }
                            this_2.setParentCollection(members);
                            Eif (withoutAllAvail ? (withoutAllEndPos <= drillStartPos) : true) {
                                Eif (!isGrandTotalTop) {
                                    this_2.totalCollection[this_2.totalCollection.length] =
                                        ({ allCount: allCount, ordinal: tupPos, members: members, drillInfo: drillInfo });
                                }
                                lastSavedInfo.allCount = allCount;
                                lastSavedInfo.allStartPos = allStartPos;
                                lastSavedInfo.drillStartPos = drillStartPos;
                                lastSavedInfo.startDrillUniquename = startDrillUniquename;
                                lastSavedInfo.endDrillUniquename = endDrillUniquename;
                            }
                        }
                        lastRealTup = this_2.tupColumnInfo[tupPos];
                    }
                }
                var attrDrill = this_2.checkAttributeDrill(this_2.tupColumnInfo[tupPos].drillInfo, 'columns');
                if (allCount > 0 && (withoutAllAvail ? (isStartCol && (attrDrill || withoutAllEndPos < allStartPos)) : true)) {
                    if (allCount === lastSavedInfo.allCount || allStartPos !== lastSavedInfo.allStartPos) {
                        var endAllow = drillEndPos !== drillStartPos ?
                            (lastSavedInfo.endDrillUniquename === endDrillUniquename) : true;
                        var allow = allStartPos !== lastSavedInfo.allStartPos ?
                            (lastSavedInfo.startDrillUniquename !== startDrillUniquename) : endAllow;
                        Eif (drillStartPos > -1 ? (allow) : true) {
                            if (!isSubTotIncluded) {
                                position = this_2.mergeTotCollection(position, allCount, maxLevel, minLevel, allType, allStartPos, drillInfo);
                                isSubTotIncluded = true;
                            }
                            this_2.setParentCollection(members);
                            Eif ((withoutAllAvail && drillStartPos > -1) ? (withoutAllEndPos <= drillStartPos) : true) {
                                if (!isGrandTotalTop) {
                                    this_2.totalCollection[this_2.totalCollection.length] =
                                        ({
                                            allCount: allCount, ordinal: tupPos, members: members,
                                            allStartPos: allStartPos, drillInfo: drillInfo
                                        });
                                }
                                lastSavedInfo.allCount = allCount;
                                lastSavedInfo.allStartPos = allStartPos;
                                lastSavedInfo.drillStartPos = drillStartPos;
                                lastSavedInfo.startDrillUniquename = startDrillUniquename;
                                lastSavedInfo.endDrillUniquename = endDrillUniquename;
                            }
                        }
                    }
                }
                tupPos++;
            };
            var this_2 = this;
            while (tupPos < tuples.length) {
                _loop_2();
            }
            if (this.totalCollection.length > 0) {
                if (Object.keys(this.colMeasures).length > 1) {
                    this.orderTotals(position, maxLevel, allType, minLevel);
                }
                else {
                    this.totalCollection = this.totalCollection.reverse();
                    for (var _i = 0, _a = this.totalCollection; _i < _a.length; _i++) {
                        var coll = _a[_i];
                        var isGrandTotal = this.tupColumnInfo[coll.ordinal].measurePosition === 0 ?
                            this.tupColumnInfo[coll.ordinal].allStartPos === 1 : this.tupColumnInfo[coll.ordinal].allStartPos === 0;
                        Eif (isGrandTotal ? (this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showColumnGrandTotals) : true) {
                            this.frameCommonColumnLoop(coll.members, coll.ordinal, position, maxLevel, minLevel, allType);
                            var attrDrill = this.checkAttributeDrill(this.tupColumnInfo[coll.ordinal].drillInfo, 'columns');
                            Eif (this.tupColumnInfo[coll.ordinal].showTotals || attrDrill) {
                                position++;
                            }
                        }
                    }
                }
            }
        };
        OlapEngine.prototype.orderTotals = function (position, maxLevel, allType, minLevel) {
            var groupColl = {};
            var maxCnt = 1;
            for (var _i = 0, _a = this.totalCollection; _i < _a.length; _i++) {
                var coll = _a[_i];
                var isGrandTotal = this.tupColumnInfo[coll.ordinal].measurePosition === 0 ?
                    this.tupColumnInfo[coll.ordinal].allStartPos === 1 : this.tupColumnInfo[coll.ordinal].allStartPos === 0;
                Eif (isGrandTotal ? (this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showColumnGrandTotals) : true) {
                    var measureName = this.tupColumnInfo[coll.ordinal].measure.querySelector('UName').textContent;
                    if (groupColl[measureName]) {
                        groupColl[measureName].coll.push(coll);
                        groupColl[measureName].count++;
                        maxCnt = maxCnt < groupColl[measureName].count ? groupColl[measureName].count : maxCnt;
                    }
                    else {
                        groupColl[measureName] = { coll: [coll], count: 1 };
                    }
                }
            }
            var keys = Object.keys(groupColl);
            var collLength = maxCnt - 1;
            while (collLength > -1) {
                for (var _b = 0, keys_1 = keys; _b < keys_1.length; _b++) {
                    var key = keys_1[_b];
                    var coll = groupColl[key].coll[collLength];
                    Eif (coll) {
                        this.frameCommonColumnLoop(coll.members, coll.ordinal, position, maxLevel, allType, minLevel);
                        if (this.tupColumnInfo[coll.ordinal].showTotals) {
                            position++;
                        }
                    }
                }
                collLength--;
            }
        };
        OlapEngine.prototype.setParentCollection = function (members) {
            var memPos = 0;
            while (members.length > memPos) {
                var member = members[memPos];
                var memberType = Number(member.querySelector('MEMBER_TYPE').textContent) > 2 ? '3' :
                    member.querySelector('MEMBER_TYPE').textContent;
                var memberlevel = Number(member.querySelector('LNum').textContent);
                var memberUName = member.querySelector('UName').textContent;
                var parentUName = member.querySelector('PARENT_UNIQUE_NAME') ?
                    member.querySelector('PARENT_UNIQUE_NAME').textContent : '';
                var isSameParent = true;
                var isWithoutAllMember = false;
                if (this.parentObjCollection[memPos]) {
                    var levelCollection = Object.keys(this.parentObjCollection[memPos]);
                    var parentMember = this.parentObjCollection[memPos][memberlevel - 1];
                    isSameParent = parentMember ? parentUName === parentMember.querySelector('UName').textContent :
                        levelCollection.length === 0;
                    isWithoutAllMember = this.tupColumnInfo[0].typeCollection[memPos] === '1';
                }
                if (memberType === '2') {
                    delete this.parentObjCollection[memPos];
                }
                else {
                    if ((this.isPaging || isWithoutAllMember) ? !isSameParent : false) {
                        delete this.parentObjCollection[memPos];
                    }
                    if (!this.parentObjCollection[memPos]) {
                        this.parentObjCollection[memPos] = {};
                        this.parentObjCollection[memPos][memberlevel] = member;
                    }
                    else if (!this.parentObjCollection[memPos][memberlevel] ||
                        this.parentObjCollection[memPos][memberlevel].querySelector('UName').textContent !== memberUName) {
                        this.parentObjCollection[memPos][memberlevel] = member;
                    }
                }
                memPos++;
            }
        };
        OlapEngine.prototype.setDrillInfo = function (pUName, parentLvlCollection, memPos, tupPos, tupInfo) {
            tupPos--;
            while (tupInfo[tupPos] && tupInfo[tupPos].drillInfo[memPos].uName === pUName) {
                var prevUcollection = tupInfo[tupPos].uNameCollection.split(/~~|::\[/).map(function (item) {
                    return item[0] === '[' ? item : ('[' + item);
                });
                Iif (prevUcollection.join('~~').indexOf(parentLvlCollection) < 0) {
                    break;
                }
                tupInfo[tupPos].drillInfo[memPos].isDrilled = true;
                Eif (this.curDrillEndPos <= memPos) {
                    tupInfo[tupPos].drillEndPos = this.curDrillEndPos = memPos;
                    tupInfo[tupPos].endDrillUniquename = pUName;
                }
                Eif (tupInfo[tupPos].drillStartPos > memPos || tupInfo[tupPos].drillStartPos === -1) {
                    tupInfo[tupPos].drillStartPos = memPos;
                }
                tupInfo[tupPos].startDrillUniquename = pUName;
                tupPos--;
            }
        };
        OlapEngine.prototype.levelCompare = function (newLevels, oldLevels) {
            var changePos = [-1, 0];
            for (var lPos = 0; lPos < oldLevels.length; lPos++) {
                if (newLevels[lPos] !== oldLevels[lPos]) {
                    changePos = [lPos, newLevels[lPos], (oldLevels[lPos] - newLevels[lPos])];
                    break;
                }
            }
            return changePos;
        };
        OlapEngine.prototype.mergeTotCollection = function (position, allCount, maxLevel, allType, minLevel, allStartPos, drillInfo, levelComp) {
            var prevHdrPos = ej2_base_1.isNullOrUndefined(allStartPos) ? levelComp[0] : (allStartPos - ((this.colMeasurePos === (allStartPos - 1)) ? 2 : 1));
            var flagLevel = drillInfo[prevHdrPos] && drillInfo[prevHdrPos].level;
            var flagLevelString = this.getLevelsAsString(prevHdrPos - 1, drillInfo);
            var groupColl = {};
            var maxCnt = 1;
            var enterFlag = false;
            for (var _i = 0, _a = this.totalCollection; _i < _a.length; _i++) {
                var coll = _a[_i];
                if (enterFlag || (coll.allCount <= allCount &&
                    ((flagLevel > -1 && coll.drillInfo[prevHdrPos]) ? ((coll.drillInfo[prevHdrPos].level >= flagLevel) &&
                        (this.getLevelsAsString(prevHdrPos - 1, coll.drillInfo)) === flagLevelString) : true))) {
                    var measureName = this.tupColumnInfo[coll.ordinal].measure ?
                        this.tupColumnInfo[coll.ordinal].measure.querySelector('UName').textContent : 'measure';
                    Iif (groupColl[measureName]) {
                        groupColl[measureName].coll.push(coll);
                        groupColl[measureName].count++;
                        maxCnt = maxCnt < groupColl[measureName].count ? groupColl[measureName].count : maxCnt;
                    }
                    else {
                        groupColl[measureName] = { coll: [coll], count: 1 };
                    }
                    enterFlag = false;
                }
            }
            var keys = Object.keys(groupColl);
            var collLength = maxCnt - 1;
            while (collLength > -1) {
                for (var _b = 0, keys_2 = keys; _b < keys_2.length; _b++) {
                    var key = keys_2[_b];
                    var coll1 = groupColl[key].coll[collLength];
                    Eif (coll1) {
                        var isGrandTotal = this.tupColumnInfo[coll1.ordinal].measurePosition === 0 ?
                            this.tupColumnInfo[coll1.ordinal].allStartPos === 1 : this.tupColumnInfo[coll1.ordinal].allStartPos === 0;
                        Eif (isGrandTotal ? (this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showColumnGrandTotals) : true) {
                            this.frameCommonColumnLoop(coll1.members, coll1.ordinal, position, maxLevel, minLevel, allType);
                            Eif (this.tupColumnInfo[coll1.ordinal].showTotals) {
                                position++;
                            }
                        }
                        this.totalCollection.pop();
                    }
                }
                collLength--;
            }
            return position;
        };
        OlapEngine.prototype.getLevelsAsString = function (prevHdrPos, drillInfo) {
            var lvlCollection = [];
            for (var pos = 0; pos < prevHdrPos; pos++) {
                lvlCollection[pos] = drillInfo[pos].level;
            }
            return lvlCollection.length > 0 ? lvlCollection.toString() : '';
        };
        OlapEngine.prototype.frameCommonColumnLoop = function (members, tupPos, position, maxLevel, minLevel, allType) {
            var _a;
            var drillMemberPosition = -1;
            Eif (this.tupColumnInfo[tupPos].showTotals) {
                var memberPos = 0;
                var memberDepth = 0;
                while (memberPos < members.length) {
                    memberDepth += (allType[memberPos] > 0 && this.getMeasurePosition(this.tupColumnInfo[tupPos].uNameCollection, this.tupColumnInfo[tupPos].measurePosition) !== memberPos) ? maxLevel[memberPos] : (maxLevel[memberPos] + (1 - minLevel[memberPos]));
                    if (this.tupColumnInfo[tupPos].drillInfo[memberPos].isDrilled &&
                        this.tupColumnInfo[tupPos].showTotals) {
                        this.tupColumnInfo[tupPos].showTotals = !this.showColumnSubTotals ? false : this.hideColumnTotalsObject[this.tupColumnInfo[tupPos].drillInfo[memberPos].hierarchy] === undefined;
                        memberDepth -= maxLevel[memberPos] -
                            this.tupColumnInfo[tupPos].levelCollection[memberPos];
                        drillMemberPosition = this.tupColumnInfo[tupPos].showTotals ? -1 : (memberDepth - 1);
                    }
                    memberPos++;
                }
            }
            var attrDrill = this.checkAttributeDrill(this.tupColumnInfo[tupPos].drillInfo, 'columns');
            if (this.tupColumnInfo[tupPos].showTotals || attrDrill) {
                var memPos = 0;
                var spanMemPos = 0;
                var colMembers = {};
                var isGrandTotal = members[0].querySelector('LNum').textContent === '0';
                while (memPos < members.length) {
                    var member = members[memPos];
                    var memberType = Number(member.querySelector('MEMBER_TYPE').textContent) > 2 ? '3' :
                        member.querySelector('MEMBER_TYPE').textContent;
                    var memDup = 0;
                    var memberLevel = member.querySelector('LNum').textContent;
                    for (var rowDepthPos = memberType !== '2' ? (allType[memPos] ? 1 : minLevel[memPos]) : 1; rowDepthPos <= (memberType === '3' ? 1 : maxLevel[memPos]); rowDepthPos++) {
                        var isDrilled = false;
                        if (!this.pivotValues[spanMemPos]) {
                            this.pivotValues[spanMemPos] = [];
                        }
                        if (Number(members[memPos].querySelector('LNum').textContent) > rowDepthPos && memberType !== '2') {
                            Iif (!this.parentObjCollection[memPos][rowDepthPos]) {
                                this.getDrilledParent(members[memPos], rowDepthPos, this.parentObjCollection[memPos]);
                            }
                            Eif (this.parentObjCollection[memPos][rowDepthPos]) {
                                member = this.parentObjCollection[memPos][rowDepthPos];
                            }
                            isDrilled = true;
                        }
                        else {
                            member = members[memPos];
                            memDup++;
                        }
                        var uName = this.getUniqueName(member.querySelector('UName').textContent);
                        if (memberType !== '2') {
                            colMembers[uName] = (memberType === '3' && this.dataFields[uName] && this.dataFields[uName].caption) ? this.dataFields[uName].caption : member.querySelector('Caption').textContent;
                        }
                        else if (memberType === '2' && memberLevel === '0' && isGrandTotal) {
                            colMembers[uName] = 'Grand Total';
                            isGrandTotal = false;
                        }
                        var levelNameKeys = Object.keys(colMembers);
                        var levelName = memPos >= this.measurePosition && Number(member.getElementsByTagName('LNum')[0].textContent) === 0 && levelNameKeys.length === 1 ? 'Grand Total' + this.valueSortSettings.headerDelimiter : '';
                        for (var i = 0; i < levelNameKeys.length; i++) {
                            var j = levelNameKeys[i];
                            if (i === 0) {
                                levelName = levelName + colMembers[j];
                            }
                            else {
                                levelName = levelName + this.valueSortSettings.headerDelimiter + colMembers[j];
                            }
                        }
                        var isNamedSet = this.namedSetsPosition['column'][memPos] ? true : false;
                        var depth = this.getDepth(this.tupColumnInfo[tupPos], uName, Number(memberType));
                        Eif (!(this.isPaging && this.pivotValues[spanMemPos - 1] && this.pivotValues[spanMemPos - 1][position] &&
                            this.fieldList[this.pivotValues[spanMemPos - 1][position].hierarchy] &&
                            this.fieldList[this.pivotValues[spanMemPos - 1][position].hierarchy].isHierarchy &&
                            this.pivotValues[spanMemPos - 1][position].hasChild &&
                            !this.pivotValues[spanMemPos - 1][position].isDrilled &&
                            !this.columns[memPos].isNamedSet && this.fieldList[member.getAttribute('Hierarchy')] &&
                            (this.fieldList[member.getAttribute('Hierarchy')].isHierarchy ||
                                this.fieldList[member.getAttribute('Hierarchy')].hasAllMember) &&
                            this.pivotValues[spanMemPos - 1][position].depth < depth)) {
                            this.pivotValues[spanMemPos][position] = {
                                axis: 'column',
                                actualText: uName,
                                colIndex: position,
                                formattedText: (memberType === '3' && this.dataFields[uName] &&
                                    this.dataFields[uName].caption) ? this.dataFields[uName].caption :
                                    member.querySelector('Caption').textContent,
                                hasChild: (this.fieldList[member.getAttribute('Hierarchy')] &&
                                    this.fieldList[member.getAttribute('Hierarchy')].isHierarchy && memPos < this.columns.length - 1 &&
                                    !this.columns[memPos + 1].isNamedSet && this.columns[memPos + 1].name.indexOf('[Measures]') < 0 &&
                                    this.fieldList[this.columns[memPos + 1].name] &&
                                    this.fieldList[this.columns[memPos + 1].name].hasAllMember) ?
                                    true : Number(member.querySelector('CHILDREN_CARDINALITY').textContent) > 0 ? true : false,
                                level: memDup > 1 ? -1 : (Number(member.querySelector('LNum').textContent) -
                                    ((allType[memPos] && memberType !== '3') ? 1 : 0)),
                                rowIndex: spanMemPos,
                                ordinal: tupPos,
                                memberType: Number(memberType),
                                depth: depth,
                                isDrilled: (this.fieldList[member.getAttribute('Hierarchy')] &&
                                    this.fieldList[member.getAttribute('Hierarchy')].isHierarchy &&
                                    !this.isAttributeDrill(member.getAttribute('Hierarchy'), this.tupColumnInfo[tupPos].drillInfo, 'columns')) ? true : (isDrilled || this.tupColumnInfo[tupPos].drillInfo[memPos].isDrilled),
                                parentUniqueName: member.querySelector('PARENT_UNIQUE_NAME') ?
                                    member.querySelector('PARENT_UNIQUE_NAME').textContent : undefined,
                                levelUniqueName: member.querySelector('LName').textContent,
                                hierarchy: member.getAttribute('Hierarchy'),
                                isNamedSet: isNamedSet,
                                valueSort: (_a = { levelName: levelName }, _a[levelName] = 1, _a.axis = member.getAttribute('Hierarchy'), _a)
                            };
                            if (!this.headerContent[spanMemPos]) {
                                this.headerContent[spanMemPos] = {};
                            }
                            this.headerContent[spanMemPos][position] =
                                this.pivotValues[spanMemPos][position];
                            spanMemPos++;
                        }
                        else {
                            this.isColDrill = true;
                            break;
                        }
                    }
                    memPos++;
                }
            }
            else {
                Eif (drillMemberPosition > -1) {
                    this.pivotValues[drillMemberPosition][position - 1].ordinal = tupPos;
                }
                else if (this.tupColumnInfo[tupPos].allCount > 0) {
                    var memberPos = 0;
                    var memberDepth = 0;
                    while (memberPos < this.tupColumnInfo[tupPos].allStartPos) {
                        memberDepth += (allType[memberPos] > 0 &&
                            this.getMeasurePosition(this.tupColumnInfo[tupPos].uNameCollection, this.tupColumnInfo[tupPos].measurePosition) !== memberPos) ?
                            maxLevel[memberPos] :
                            (maxLevel[memberPos] + (1 - minLevel[memberPos]));
                        memberPos++;
                    }
                    if (this.tupColumnInfo[tupPos].allStartPos === (this.tupColumnInfo[tupPos].measurePosition + 1)) {
                        memberDepth -= maxLevel[this.tupColumnInfo[tupPos].allStartPos - 2] -
                            this.tupColumnInfo[tupPos].levelCollection[this.tupColumnInfo[tupPos].allStartPos - 2] + 1;
                    }
                    else {
                        memberDepth -= maxLevel[this.tupColumnInfo[tupPos].allStartPos - 1] -
                            this.tupColumnInfo[tupPos].levelCollection[this.tupColumnInfo[tupPos].allStartPos - 1];
                    }
                    if (this.pivotValues[memberDepth - 1]) {
                        this.pivotValues[memberDepth - 1][position - 1].ordinal = tupPos;
                    }
                }
            }
        };
        OlapEngine.prototype.isAttributeDrill = function (hierarchy, drillInfo, axis) {
            var isDrill = false;
            var isAdjacent = this.isAdjacentToMeasure(hierarchy, axis);
            if (!isAdjacent) {
                for (var i = 0; i < this.drilledMembers.length; i++) {
                    if (this.drilledMembers[i].name === hierarchy) {
                        for (var j = 0; j < this.drilledMembers[i].items.length; j++) {
                            var delimiter = this.drilledMembers[i].delimiter;
                            var drillItems = this.drilledMembers[i].items[j].split(delimiter);
                            var levelName = '';
                            for (var k = 0; k < drillItems.length; k++) {
                                Eif (drillInfo[k] && drillInfo[k].uName) {
                                    levelName = levelName + (levelName === '' ? '' : this.drilledMembers[i].delimiter) +
                                        drillInfo[k].uName;
                                }
                            }
                            if (levelName === this.drilledMembers[i].items[j]) {
                                isDrill = true;
                                break;
                            }
                        }
                    }
                }
            }
            return isDrill;
        };
        OlapEngine.prototype.isAdjacentToMeasure = function (hierarchy, axis) {
            var isAdjacent = false;
            var fields = axis === 'rows' ? this.rows : this.columns;
            for (var i = 0; i < fields.length; i++) {
                if (fields[i].name === hierarchy && fields[i + 1] && (fields[i + 1].name === '[Measures]' ||
                    fields[i + 1].isNamedSet || (this.fieldList[fields[i + 1].name] &&
                    !this.fieldList[fields[i + 1].name].hasAllMember))) {
                    isAdjacent = true;
                    break;
                }
            }
            return isAdjacent;
        };
        OlapEngine.prototype.getDrilledParent = function (childMember, parentLevel, savedCollection) {
            var childlevel = Number(childMember.querySelector('LNum').textContent);
            var currentChild = childMember;
            for (var lvl = childlevel - 1; lvl >= parentLevel; lvl--) {
                var currentParent = this.drilledSets[currentChild.querySelector('PARENT_UNIQUE_NAME').textContent];
                if (currentParent) {
                    savedCollection[lvl] = currentParent;
                    currentChild = currentParent;
                }
                else {
                    break;
                }
            }
        };
        OlapEngine.prototype.performRowSorting = function (valCollection, valueSortData) {
            var _a;
            if ((this.enableSort || this.enableValueSorting) && this.tupRowInfo.length > 0) {
                var rowCount = this.pivotValues.length;
                var lvlGrouping = {};
                var measureObjects = {};
                var gSumGrouping = [];
                var gSumFlag = false;
                var withoutAllLastPos = this.tupRowInfo[0].typeCollection.lastIndexOf('1');
                var isDrilled = void 0;
                for (var rPos = this.colDepth; rPos < rowCount; rPos++) {
                    var currentCell = this.pivotValues[rPos][0];
                    Iif (this.showSubTotalsAtBottom && currentCell.isSum && currentCell.memberType !== 3) {
                        continue;
                    }
                    var currentTuple = this.tupRowInfo[currentCell.ordinal];
                    var uniqueName = currentTuple ? (currentTuple.measurePosition === 0 && currentCell.memberType === 3 ?
                        currentTuple.measureName : currentTuple.uNameCollection) : '';
                    if (uniqueName !== '') {
                        if (withoutAllLastPos > -1) {
                            uniqueName = this.frameUniqueName(uniqueName, currentCell, currentTuple);
                        }
                        var level = uniqueName.split(/~~|::\[/).length;
                        if (currentCell.memberType === 3 && this.tupRowInfo[0].measurePosition > 0) {
                            var parentUName = this.getParentUname(uniqueName, currentCell, true, true);
                            Iif (measureObjects[parentUName]) {
                                measureObjects[parentUName].push(currentCell);
                            }
                            else {
                                measureObjects[parentUName] = [currentCell];
                            }
                        }
                        else if (lvlGrouping[level]) {
                            lvlGrouping[level][uniqueName] = [currentCell];
                        }
                        else {
                            lvlGrouping[level] = (_a = {}, _a[uniqueName] = [currentCell], _a);
                        }
                    }
                    Iif (gSumFlag) {
                        gSumGrouping.push(currentCell);
                    }
                    if (currentCell.type === 'grand sum') {
                        gSumFlag = true;
                    }
                }
                var isMeasureAvail = Object.keys(measureObjects).length > 0 && this.tupRowInfo[0].measurePosition > 0;
                var levels = Object.keys(lvlGrouping).map(function (item) {
                    return Number(item);
                }).sort(function (a, b) { return (a > b) ? 1 : ((b > a) ? -1 : 0); });
                var sortLvlGrouping = {};
                for (var lPos = levels.length - 1; lPos >= 0; lPos--) {
                    var parentGrouping = {};
                    var objCollection = lvlGrouping[levels[lPos]];
                    var objKeys = Object.keys(objCollection);
                    for (var oPos = 0; oPos < objKeys.length; oPos++) {
                        var parentUName = lPos === 0 ? 'parent' :
                            this.getParentUname(objKeys[oPos], objCollection[objKeys[oPos]][0], isMeasureAvail, false);
                        if (parentGrouping[parentUName]) {
                            parentGrouping[parentUName].push(objCollection[objKeys[oPos]][0]);
                        }
                        else {
                            parentGrouping[parentUName] = [objCollection[objKeys[oPos]]][0];
                        }
                    }
                    var pKeys = Object.keys(parentGrouping);
                    for (var kPos = 0; kPos < pKeys.length; kPos++) {
                        parentGrouping[pKeys[kPos]] = this.sortRowHeaders(parentGrouping[pKeys[kPos]], valCollection, valueSortData);
                    }
                    if (sortLvlGrouping[levels[lPos + 1]]) {
                        for (var kPos = 0; kPos < pKeys.length; kPos++) {
                            var groupSets = [];
                            var axisSets = parentGrouping[pKeys[kPos]];
                            for (var aPos = 0; aPos < axisSets.length; aPos++) {
                                var tupInfo = this.tupRowInfo[axisSets[aPos].ordinal];
                                var uName = (tupInfo.measurePosition === 0 && axisSets[aPos].memberType === 3) ?
                                    tupInfo.measureName : tupInfo.uNameCollection;
                                groupSets.push(axisSets[aPos]);
                                Eif (withoutAllLastPos > -1) {
                                    uName = this.frameUniqueName(uName, axisSets[aPos], tupInfo);
                                }
                                var isMembersIncluded = false;
                                Iif (isMeasureAvail) {
                                    var parentUName = this.getParentUname(uName, axisSets[aPos], isMeasureAvail, true);
                                    if (measureObjects[parentUName]) {
                                        measureObjects[parentUName] = this.sortRowHeaders(measureObjects[parentUName], valCollection, valueSortData);
                                        var isLastMeasure = uName.lastIndexOf('::[') === uName.indexOf('::[Measures]');
                                        var isFullLength = uName.split('::[').length - 1 === tupInfo.measurePosition;
                                        var isLastNotDrilledMember = !tupInfo.drillInfo[tupInfo.measurePosition - 1].isDrilled;
                                        var isActualLastMember = tupInfo.members.length > (tupInfo.measurePosition + 1);
                                        if (isLastMeasure && isFullLength && isLastNotDrilledMember && isActualLastMember) {
                                            isMembersIncluded = true;
                                            for (var mPos = 0; mPos < measureObjects[parentUName].length; mPos++) {
                                                groupSets.push(measureObjects[parentUName][mPos]);
                                                var matchParent = (uName.substring(0, uName.indexOf('::[Measures]')) + '::' + measureObjects[parentUName][mPos].actualText);
                                                if (sortLvlGrouping[levels[lPos + 1]][matchParent]) {
                                                    groupSets = groupSets.concat(sortLvlGrouping[levels[lPos + 1]][matchParent]);
                                                }
                                            }
                                        }
                                        else {
                                            isDrilled = this.showSubTotalsAtBottom && groupSets[groupSets.length - 1].isDrilled;
                                            groupSets = groupSets.concat(measureObjects[parentUName]);
                                        }
                                    }
                                }
                                Eif (!isMembersIncluded &&
                                    sortLvlGrouping[levels[lPos + 1]][uName]) {
                                    Iif (this.showSubTotalsAtBottom && groupSets[groupSets.length - 1].memberType === 3 &&
                                        groupSets[groupSets.length - 1].level > -1 && isDrilled) {
                                        var valueColl = [];
                                        var sliceIndex = 0;
                                        for (var i = groupSets.length - 1; i >= 0; i--) {
                                            if (groupSets[i].memberType === 3) {
                                                valueColl[valueColl.length] = groupSets[i];
                                            }
                                            else {
                                                valueColl = valueColl.reverse();
                                                sliceIndex = i + 1;
                                                break;
                                            }
                                        }
                                        groupSets = groupSets.slice(0, sliceIndex).concat(sortLvlGrouping[levels[lPos + 1]][uName]).concat(valueColl);
                                    }
                                    else {
                                        var currentCell = groupSets[groupSets.length - 1];
                                        var subTotal = void 0;
                                        Iif (this.showSubTotalsAtBottom && currentCell.isDrilled) {
                                            subTotal = util_1.PivotUtil.frameHeaderWithKeys(currentCell);
                                            subTotal.hasChild = false;
                                            subTotal.isDrilled = false;
                                            subTotal.isSum = true;
                                            subTotal.formattedText = subTotal.formattedText + ' Total';
                                        }
                                        groupSets = groupSets.concat(sortLvlGrouping[levels[lPos + 1]][uName]);
                                        Iif (subTotal) {
                                            groupSets[groupSets.length] = subTotal;
                                        }
                                    }
                                }
                            }
                            parentGrouping[pKeys[kPos]] = groupSets;
                        }
                    }
                    else if (isMeasureAvail) {
                        for (var kPos = 0; kPos < pKeys.length; kPos++) {
                            var axisSets = parentGrouping[pKeys[kPos]];
                            var groupSets = [];
                            for (var aPos = 0; aPos < axisSets.length; aPos++) {
                                groupSets.push(axisSets[aPos]);
                                var uName = this.tupRowInfo[axisSets[aPos].ordinal].uNameCollection;
                                Eif (withoutAllLastPos > -1) {
                                    uName = this.frameUniqueName(uName, axisSets[aPos], this.tupRowInfo[axisSets[aPos].ordinal]);
                                }
                                var parentUName = this.getParentUname(uName, axisSets[aPos], true, true);
                                Eif (measureObjects[parentUName]) {
                                    measureObjects[parentUName] = this.sortRowHeaders(measureObjects[parentUName], valCollection, valueSortData);
                                    groupSets = groupSets.concat(measureObjects[parentUName]);
                                }
                            }
                            parentGrouping[pKeys[kPos]] = groupSets;
                        }
                    }
                    sortLvlGrouping[levels[lPos]] = parentGrouping;
                }
                var newPos = 0;
                var totPos = 0;
                var valuePos = 0;
                gSumFlag = false;
                gSumGrouping = this.sortRowHeaders(gSumGrouping, valCollection, valueSortData);
                for (var rPos = this.colDepth; rPos < rowCount; rPos++) {
                    Iif (this.dataSourceSettings.grandTotalsPosition === 'Top' && (this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showRowGrandTotals) &&
                        ((this.olapValueAxis === 'column' && this.colDepth + 1 === rPos) || (this.olapValueAxis === 'row' && this.colDepth + this.dataSourceSettings.values.length + 1 === rPos))) {
                        newPos = 0;
                        gSumFlag = false;
                    }
                    var cell = gSumFlag ? gSumGrouping : sortLvlGrouping[levels[0]]['parent'];
                    var currPos = (this.dataSourceSettings.grandTotalsPosition === 'Top' && (this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showRowGrandTotals) && this.colDepth === rPos) ? cell.length : gSumFlag ? (newPos - totPos) : newPos;
                    if (cell[currPos]) {
                        this.pivotValues[rPos] = [cell[currPos]];
                        this.pivotValues[rPos][0].rowIndex = rPos;
                        this.valueContent[valuePos][0] = this.pivotValues[rPos][0];
                    }
                    newPos++;
                    valuePos++;
                    if (this.pivotValues[rPos][0].type === 'grand sum') {
                        gSumFlag = true;
                        totPos = newPos;
                    }
                }
            }
        };
        OlapEngine.prototype.performColumnSorting = function (valCollection, valueSortData) {
            Eif (this.enableSort || this.enableValueSorting) {
                for (var i = 0; i < this.dataSourceSettings.columns.length; i++) {
                    var temporary = [];
                    var index = 0;
                    var grandTotal = [];
                    for (var j = 0; j < this.pivotValues.length; j++) {
                        var header = this.pivotValues[j];
                        var keys = void 0;
                        var arrange = {};
                        var arrangeHeaders = [];
                        var value = 1;
                        grandTotal[index] = [];
                        temporary[index] = [];
                        var k = 1;
                        var fieldName = header[k].hierarchy;
                        var levelName = header[k].levelUniqueName;
                        for (k; k < header.length; k++) {
                            Eif (!header[k].isNamedSet) {
                                if (header[k].memberType !== 2 && header[k].hierarchy
                                    !== '[Measures]' && header[k].level !== -1) {
                                    if (ej2_base_1.isNullOrUndefined(arrange[header[k].formattedText]) ||
                                        ej2_base_1.isNullOrUndefined(this.pivotValues[j - 1])) {
                                        if (!arrange[header[k].formattedText]) {
                                            arrange[header[k].formattedText] = [];
                                        }
                                        if (!header[k + 1] || (header[k].formattedText !== header[k + 1].formattedText)) {
                                            arrangeHeaders[arrangeHeaders.length] = header[k];
                                        }
                                        arrange[header[k].formattedText][header[k].colIndex] = header[k];
                                    }
                                    else Eif (arrange[header[k].formattedText] && this.pivotValues[j - 1]) {
                                        var prevRowCell = this.pivotValues[j - 1][header[k].colIndex];
                                        var prevColValue = Number(Object.keys(arrange[header[k].formattedText])[0]);
                                        var prevColIndex = ((arrange[header[k].formattedText])[prevColValue]).colIndex;
                                        var prevColRowCell = this.pivotValues[j - 1][prevColIndex];
                                        if (prevRowCell.formattedText !== prevColRowCell.formattedText) {
                                            keys = this.sortColumnHeaders(arrange, arrangeHeaders, this.sortObject[header[k - 1].levelUniqueName] ||
                                                this.sortObject[header[k].hierarchy], valCollection, valueSortData, fieldName, levelName);
                                            temporary[index] = ej2_base_1.isNullOrUndefined(temporary[index]) ? [] :
                                                temporary[index];
                                            for (var keyPos = 0; keyPos < keys.length; keyPos++) {
                                                var length_1 = Object.keys(arrange[keys[keyPos]]).length;
                                                for (var cellPos = 0; cellPos < length_1; cellPos++) {
                                                    value = temporary[index].length === 0 ? 1 : 0;
                                                    temporary[index][temporary[index].length + value] = arrange[keys[keyPos]][Number(Object.keys(arrange[keys[keyPos]])[cellPos])];
                                                }
                                            }
                                            arrange = {};
                                            arrangeHeaders = [];
                                            arrange[header[k].formattedText] = [];
                                            arrangeHeaders[arrangeHeaders.length] = header[k];
                                            arrange[header[k].formattedText][header[k].colIndex] = header[k];
                                        }
                                        else {
                                            arrange[header[k].formattedText][header[k].colIndex] = header[k];
                                        }
                                    }
                                }
                                else if (Object.keys(arrange).length > 0) {
                                    grandTotal[index][grandTotal[index].length + value]
                                        = header[k];
                                    keys = this.sortColumnHeaders(arrange, arrangeHeaders, this.sortObject[header[k - 1].levelUniqueName] ||
                                        this.sortObject[header[k].hierarchy], valCollection, valueSortData, fieldName, levelName);
                                    temporary[index] = ej2_base_1.isNullOrUndefined(temporary[index]) ? [] :
                                        temporary[index];
                                    for (var l = 0; l < keys.length; l++) {
                                        var length_2 = Object.keys(arrange[keys[l]]).length;
                                        for (var q = 0; q < length_2; q++) {
                                            value = temporary[index].length === 0 ? 1 : 0;
                                            temporary[index][temporary[index].length + value] =
                                                arrange[keys[l]][Number(Object.keys(arrange[keys[l]])[q])];
                                        }
                                    }
                                }
                                else if ((header[k].level === -1 || header[k].level === 0) &&
                                    Object.keys(arrange).length >= 0 && header[k].hierarchy !== '[Measures]') {
                                    grandTotal[index][grandTotal[index].length + value]
                                        = header[k];
                                }
                                if (header[k].level !== -1 && Object.keys(arrange).length === 1 &&
                                    header[k].hierarchy !== '[Measures]' && !ej2_base_1.isNullOrUndefined(header[k + 1]) &&
                                    header[k + 1].level === -1) {
                                    var height = Object.keys(arrange[header[k].formattedText]).length;
                                    var weight = Object.keys(arrange[header[k].formattedText]);
                                    if (height > 1) {
                                        for (var hgt = 0; hgt < height; hgt++) {
                                            value = grandTotal[index].length === 0 ? 1 : 0;
                                            grandTotal[index][grandTotal[index].length + value]
                                                = arrange[header[k].formattedText][Number(weight[hgt])];
                                        }
                                    }
                                    else {
                                        grandTotal[index][grandTotal[index].length + value]
                                            = header[k];
                                    }
                                }
                                if (Object.keys(grandTotal[index]).length > 0) {
                                    value = temporary[index].length === 0 ? 1 : 0;
                                    var height1 = grandTotal[index].length;
                                    if (height1 > 2) {
                                        for (var hgt1 = 1; hgt1 < height1; hgt1++) {
                                            value = temporary[index].length === 0 ? 1 : 0;
                                            temporary[index][temporary[index].length + value] =
                                                grandTotal[index][hgt1];
                                        }
                                    }
                                    else {
                                        temporary[index][temporary[index].length + value] =
                                            grandTotal[index][1] || grandTotal[index][0];
                                    }
                                    arrange = {};
                                    arrangeHeaders = [];
                                    grandTotal[index] = [];
                                }
                            }
                        }
                        if (Object.keys(arrange).length > 0) {
                            grandTotal[index][grandTotal[index].length + value] = header[k];
                            var order = this.sortObject[header[k - 1].levelUniqueName] || this.sortObject[header[k - 1].hierarchy];
                            keys = this.sortColumnHeaders(arrange, arrangeHeaders, order, valCollection, valueSortData, fieldName, levelName);
                            temporary[index] = ej2_base_1.isNullOrUndefined(temporary[index]) ? [] : temporary[index];
                            for (var len = 0; len < keys.length; len++) {
                                var leng = Object.keys(arrange[keys[len]]).length;
                                for (var q = 0; q < leng; q++) {
                                    value = temporary[index].length === 0 ? 1 : 0;
                                    temporary[index][temporary[index].length + value] = arrange[keys[len]][Number(Object.keys(arrange[keys[len]])[q])];
                                }
                            }
                        }
                        for (var m = 1; m < temporary[index].length; m++) {
                            this.pivotValues[index][m] = temporary[index][m];
                        }
                        for (var n = j; n < this.pivotValues.length; n++) {
                            var pElement = ej2_base_1.extend({}, this.pivotValues[n + 1], null, true);
                            var cElement = ej2_base_1.extend({}, this.pivotValues[n], null, true);
                            if (Object.keys(pElement).length === Object.keys(cElement).length && Object.keys(pElement).length > 2) {
                                for (var o = 1; o < this.pivotValues[j].length; o++) {
                                    if (Object.keys(pElement).length > 0 && cElement[o].colIndex
                                        !== pElement[o].colIndex) {
                                        this.pivotValues[n + 1][o] =
                                            pElement[cElement[o].colIndex];
                                    }
                                }
                                break;
                            }
                        }
                        index++;
                        arrange = {};
                    }
                    for (var i_1 = 0; i_1 < this.pivotValues.length; i_1++) {
                        var header = this.pivotValues[i_1];
                        for (var j = 1; j < header.length; j++) {
                            header[j].colIndex = j;
                        }
                    }
                }
            }
        };
        OlapEngine.prototype.frameUniqueName = function (uniqueName, currentCell, currentTuple) {
            var hasLastMeasure = uniqueName.indexOf(currentCell.actualText.toString() + '::[Measures]') > -1;
            uniqueName = uniqueName.substring(0, uniqueName.indexOf(currentCell.actualText.toString())) +
                currentCell.actualText.toString();
            var measureAvail = uniqueName.split('::[').length <= this.getMeasurePosition(uniqueName, currentTuple.measurePosition);
            uniqueName = uniqueName + ((hasLastMeasure || measureAvail) ? ('::' + currentTuple.measureName) : '');
            return uniqueName;
        };
        OlapEngine.prototype.getMeasurePosition = function (uniqueName, measurePosition) {
            var position = measurePosition;
            var collection = uniqueName.split('::[');
            for (var i = 0; i < collection.length; i++) {
                if (collection[i] && collection[i].indexOf('Measures') > -1) {
                    position = i;
                    break;
                }
            }
            return position;
        };
        OlapEngine.prototype.sortRowHeaders = function (headers, valCollection, valueSortData) {
            if (this.enableValueSorting && this.olapValueAxis === 'column' && valueSortData.isValueSorting && !ej2_base_1.isNullOrUndefined(this.valueSortSettings)) {
                var aggreColl = [];
                for (var i = 0; i < headers.length; i++) {
                    var header = headers[i];
                    var valueElement = valCollection[(header.ordinal * valueSortData.columnLength) + valueSortData.memberIndex];
                    var valueArray = valueElement ? valueElement.getElementsByTagName('Value') : undefined;
                    var value = valueElement && valueArray.length > 0 ? Number(valueArray[0].textContent) : 0;
                    aggreColl.push({ 'header': header, 'value': value });
                }
                headers = util_1.PivotUtil.getSortedValue(aggreColl, this.valueSortSettings.sortOrder);
            }
            else if (this.enableSort && headers.length > 0 && headers[0].memberType !== 3 && !headers[0].isNamedSet) {
                var sortMembers = [];
                for (var i = 0; i < headers.length; i++) {
                    sortMembers[i] = headers[i].actualText;
                }
                var isHeaderSortByDefault = false;
                var fieldName = headers[0].actualText !== 'Grand Total' ? headers[0].hierarchy : headers[1].hierarchy;
                var membersInfo = this.fieldList[fieldName] && this.fieldList[fieldName].membersOrder ?
                    this.fieldList[fieldName].membersOrder.slice() : [];
                var sortDetails = {
                    fieldName: fieldName,
                    levelName: headers[0].levelUniqueName,
                    sortOrder: (this.sortObject[headers[0].hierarchy] || this.sortObject[headers[0].levelUniqueName]),
                    members: membersInfo && membersInfo.length > 0 ? membersInfo : sortMembers,
                    IsOrderChanged: false
                };
                Iif (membersInfo && membersInfo.length > 0) {
                    util_1.PivotUtil.applyCustomSort(sortDetails, headers, 'string', false, true);
                }
                else {
                    Eif (sortDetails.sortOrder === 'Ascending' || sortDetails.sortOrder === undefined) {
                        headers.sort(function (a, b) { return (a.formattedText > b.formattedText) ? 1 :
                            ((b.formattedText > a.formattedText) ? -1 : 0); });
                    }
                    else if (sortDetails.sortOrder === 'Descending') {
                        headers.sort(function (a, b) { return (a.formattedText < b.formattedText) ? 1 :
                            ((b.formattedText < a.formattedText) ? -1 : 0); });
                    }
                    isHeaderSortByDefault = true;
                }
                if (isHeaderSortByDefault && this.getHeaderSortInfo) {
                    var copyOrder = [];
                    for (var m = 0, n = 0; m < headers.length; m++) {
                        Eif (headers[m].actualText !== 'Grand Total') {
                            copyOrder[n++] = headers[m].formattedText;
                        }
                    }
                    sortDetails.members = copyOrder;
                }
                if (this.getHeaderSortInfo) {
                    this.getHeaderSortInfo(sortDetails);
                }
                Iif (sortDetails.IsOrderChanged) {
                    util_1.PivotUtil.applyCustomSort(sortDetails, headers, 'string', true, true);
                }
            }
            return headers;
        };
        OlapEngine.prototype.sortColumnHeaders = function (arrange, headers, order, valCollection, valueSortData, header, levelName) {
            var keys = Object.keys(arrange);
            if (this.enableValueSorting && this.olapValueAxis === 'row' && valueSortData.isValueSorting && !ej2_base_1.isNullOrUndefined(this.valueSortSettings)) {
                var aggreColl = [];
                for (var i = 0; i < keys.length; i++) {
                    var childCollection = arrange[keys[i]];
                    var header_1 = this.showSubTotalsAtTop ? childCollection[0] : childCollection[childCollection.length - 1];
                    var valueElement = valCollection[(valueSortData.memberIndex * valueSortData.columnLength) + header_1.ordinal];
                    var valueArray = valueElement ? valueElement.getElementsByTagName('Value') : undefined;
                    var value = valueElement && valueArray.length > 0 ? Number(valueArray[0].textContent) : 0;
                    aggreColl.push({ 'header': header_1, 'value': value });
                }
                headers = util_1.PivotUtil.getSortedValue(aggreColl, this.valueSortSettings.sortOrder);
                keys = headers.map(function (header) {
                    return header.formattedText;
                });
            }
            else Eif (this.enableSort) {
                var isHeaderSortByDefault = false;
                var membersInfo = this.fieldList[header] && this.fieldList[header].membersOrder ?
                    this.fieldList[header].membersOrder.slice() : [];
                var sortDetails = {
                    fieldName: header,
                    levelName: levelName,
                    sortOrder: order,
                    members: membersInfo && membersInfo.length > 0 ? membersInfo : keys,
                    IsOrderChanged: false
                };
                Iif (membersInfo && membersInfo.length > 0) {
                    this.applyCustomSort(keys, sortDetails);
                }
                else {
                    Eif (sortDetails.sortOrder === 'Ascending' || sortDetails.sortOrder === undefined) {
                        keys.sort(function (a, b) { return (a > b) ? 1 : ((b > a) ? -1 : 0); });
                    }
                    else if (sortDetails.sortOrder === 'Descending') {
                        keys.sort(function (a, b) { return (a < b) ? 1 : ((b < a) ? -1 : 0); });
                    }
                    isHeaderSortByDefault = true;
                }
                if (isHeaderSortByDefault && this.getHeaderSortInfo) {
                    var copyOrder = [];
                    for (var m = 0, n = 0; m < keys.length; m++) {
                        Eif (keys[m] !== 'Grand Total') {
                            copyOrder[n++] = keys[m];
                        }
                    }
                    sortDetails.members = copyOrder;
                }
                if (this.getHeaderSortInfo) {
                    this.getHeaderSortInfo(sortDetails);
                }
                Iif (sortDetails.IsOrderChanged) {
                    this.applyCustomSort(keys, sortDetails, true);
                }
            }
            return keys;
        };
        OlapEngine.prototype.applyCustomSort = function (headers, sortDetails, hasMembersOrder) {
            var order = [];
            var updatedMembers = [];
            var grandTotal;
            if (sortDetails.IsOrderChanged) {
                order = sortDetails.members;
            }
            else {
                order = (sortDetails.sortOrder === 'Ascending' || sortDetails.sortOrder === 'None' || sortDetails.sortOrder === undefined) ? [].concat(sortDetails.members) : [].concat(sortDetails.members).reverse();
            }
            if (headers[0] === 'Grand Total') {
                grandTotal = headers[0];
                headers.shift();
            }
            for (var i = 0, j = 0; i < headers.length; i++) {
                var sortText = headers[i];
                if (order[j] === sortText) {
                    headers.splice(j++, 0, sortText);
                    headers.splice(++i, 1);
                    if (j < order.length) {
                        i = -1;
                    }
                    else {
                        if (!hasMembersOrder) {
                            updatedMembers.splice(--j, 0, sortText);
                        }
                        break;
                    }
                }
                if (i >= 0 && !hasMembersOrder) {
                    updatedMembers[i] = headers[i];
                }
            }
            if (!hasMembersOrder) {
                for (var i = updatedMembers.length; i < headers.length; i++) {
                    updatedMembers[i] = headers[i];
                }
                if (updatedMembers[updatedMembers.length - 1] === 'Grand Total') {
                    updatedMembers.pop();
                }
                sortDetails.members = updatedMembers;
            }
            if (grandTotal) {
                headers.splice(0, 0, grandTotal);
            }
            return headers;
        };
        OlapEngine.prototype.frameSortObject = function () {
            Eif (this.enableSort) {
                for (var fPos = 0; fPos < this.sortSettings.length; fPos++) {
                    this.sortObject[this.sortSettings[fPos].name] = this.sortSettings[fPos].order;
                }
            }
        };
        OlapEngine.prototype.getParentUname = function (uniqueNameColl, cell, isMeasureAvail, isLastMeasure) {
            var parentString = '';
            Iif (isMeasureAvail && !isLastMeasure) {
                var tuple = this.tupRowInfo[cell.ordinal];
                var sepPos = [];
                var sepObjects = {};
                for (var i = 0; i < uniqueNameColl.length; i++) {
                    if (uniqueNameColl[i] === '~' || uniqueNameColl[i] === ':') {
                        sepPos.push(i);
                        sepObjects[i] = uniqueNameColl[i] + uniqueNameColl[i];
                        i++;
                    }
                }
                if (this.getMeasurePosition(uniqueNameColl, tuple.measurePosition) >= (uniqueNameColl.split('::[').length - 1)) {
                    if (sepPos[sepPos.length - 2] > -1) {
                        parentString = uniqueNameColl.substring(0, sepPos[sepPos.length - 2]) + sepObjects[sepPos[sepPos.length - 1]] +
                            tuple.measureName;
                    }
                    else {
                        parentString = 'parent';
                    }
                }
                else {
                    var lastPosition = uniqueNameColl.lastIndexOf('~~') > uniqueNameColl.lastIndexOf('::[') ?
                        uniqueNameColl.lastIndexOf('~~') : uniqueNameColl.lastIndexOf('::[');
                    parentString = lastPosition > -1 ? uniqueNameColl.substring(0, lastPosition) : 'parent';
                }
            }
            else {
                var lastPosition = uniqueNameColl.lastIndexOf('~~') > uniqueNameColl.lastIndexOf('::[') ?
                    uniqueNameColl.lastIndexOf('~~') : uniqueNameColl.lastIndexOf('::[');
                parentString = lastPosition > -1 ? uniqueNameColl.substring(0, lastPosition) : 'parent';
            }
            return parentString;
        };
        OlapEngine.prototype.performColumnSpanning = function () {
            var spanCollection = {};
            var rowPos = this.rowStartPos - 1;
            var colMeasureCount = Object.keys(this.colMeasures).length;
            var measurePosition = this.tupColumnInfo[0] ? this.tupColumnInfo[0].measurePosition : this.measureIndex;
            for (var i = rowPos; i > -1; i--) {
                if (this.pivotValues[i][1].memberType === 3) {
                    measurePosition = i;
                    break;
                }
            }
            while (rowPos > -1) {
                spanCollection[rowPos] = {};
                var colPos = this.pivotValues[rowPos].length - 1;
                while (colPos > 0) {
                    spanCollection[rowPos][colPos] = 1;
                    var nextColCell = this.pivotValues[rowPos][colPos + 1];
                    var nextRowCell = (this.pivotValues[rowPos + 1] && this.rowStartPos - rowPos > 1) ?
                        this.pivotValues[rowPos + 1][colPos] : undefined;
                    var currCell = this.pivotValues[rowPos][colPos];
                    var colflag = false;
                    var rowflag = false;
                    var tupColInfo = this.tupColumnInfo[currCell.ordinal];
                    var isSubTot = tupColInfo.allStartPos > (tupColInfo.typeCollection[0] === '3' ? 1 : 0);
                    var attrDrill = this.checkAttributeDrill(tupColInfo.drillInfo, 'columns');
                    Iif (this.showSubTotalsAtTop && currCell.isDrilled && nextColCell &&
                        (nextColCell.actualText !== currCell.actualText) && currCell.level > -1) {
                        currCell.ordinal = this.getOrdinal(currCell, this.pivotValues[rowPos + 1]);
                    }
                    if (nextRowCell && nextColCell && ((currCell.memberType === 2 || currCell.level === -1) ?
                        (nextColCell.actualText === currCell.actualText) :
                        ((currCell.memberType === 3 && currCell.actualText === nextColCell.actualText) ||
                            nextColCell.valueSort.levelName === currCell.valueSort.levelName))) {
                        if (currCell.memberType === 2) {
                            Eif (isSubTot ? nextColCell.type === 'sum' : true) {
                                currCell.colSpan = (nextColCell.colSpan + 1) >
                                    (measurePosition > rowPos ? colMeasureCount : 0) ? 1 : (nextColCell.colSpan + 1);
                            }
                            else {
                                currCell.colSpan = 1;
                            }
                        }
                        else {
                            currCell.colSpan = nextColCell.colSpan + 1;
                            currCell.ordinal = nextColCell.ordinal;
                        }
                        colflag = true;
                    }
                    if (currCell.memberType === 2) {
                        if (isSubTot) {
                            if (!attrDrill) {
                                currCell.type = 'sum';
                            }
                            currCell.formattedText = 'Total';
                            currCell.valueSort[currCell.valueSort.levelName.toString()] = 1;
                        }
                        else {
                            currCell.type = 'grand sum';
                            currCell.formattedText = 'Grand Total';
                            Iif (rowPos < this.measureIndex) {
                                var levelName = 'Grand Total';
                                currCell.valueSort.levelName = levelName;
                                currCell.valueSort[levelName.toString()] = 1;
                            }
                        }
                        currCell.hasChild = false;
                    }
                    else if (currCell.level === -1) {
                        currCell.type = 'sum';
                        currCell.formattedText = 'Total';
                        currCell.hasChild = false;
                        currCell.valueSort[currCell.valueSort.levelName.toString()] = 1;
                    }
                    if (nextRowCell) {
                        if ((currCell.memberType === 2 && nextRowCell.memberType === 2) || nextRowCell.actualText === currCell.actualText) {
                            spanCollection[rowPos][colPos] = spanCollection[rowPos + 1] ?
                                (spanCollection[rowPos + 1][colPos] + 1) : 1;
                            if (rowPos === 0 || (currCell.memberType === 1 && currCell.level > -1 &&
                                nextRowCell.memberType === 1 && nextRowCell.level === -1)) {
                                currCell.rowSpan = (currCell.isDrilled && ((this.fieldList[currCell.hierarchy] &&
                                    this.fieldList[currCell.hierarchy].isHierarchy) ? currCell.hasChild : true)) ? 1 :
                                    (spanCollection[rowPos + 1][colPos] + 1);
                                nextRowCell.rowSpan = (nextRowCell.isDrilled && ((this.fieldList[nextRowCell.hierarchy] &&
                                    this.fieldList[nextRowCell.hierarchy].isHierarchy) ? nextRowCell.hasChild : true) &&
                                    nextRowCell.level === -1) ? spanCollection[rowPos + 1][colPos] : nextRowCell.rowSpan;
                            }
                            else {
                                Iif (currCell.memberType === 3) {
                                    currCell.rowSpan = 1;
                                }
                                else {
                                    currCell.rowSpan = -1;
                                }
                            }
                            rowflag = true;
                        }
                        else Iif (currCell.isDrilled && ((this.fieldList[currCell.hierarchy] &&
                            this.fieldList[currCell.hierarchy].isHierarchy) ? currCell.hasChild : true) && currCell.level === -1 &&
                            nextRowCell.memberType === 2) {
                            spanCollection[rowPos][colPos] = spanCollection[rowPos + 1] ?
                                (spanCollection[rowPos + 1][colPos] + 1) : 1;
                            currCell.rowSpan = -1;
                            rowflag = true;
                        }
                        else {
                            currCell.rowSpan = rowPos === 0 ? spanCollection[rowPos][colPos] : -1;
                            nextRowCell.rowSpan = ((nextRowCell.level > -1 && !(nextRowCell.isDrilled &&
                                ((this.fieldList[nextRowCell.hierarchy] && this.fieldList[nextRowCell.hierarchy].isHierarchy) ?
                                    nextRowCell.hasChild : true))) || (currCell.memberType !== 2 && nextRowCell.memberType === 2)) ?
                                spanCollection[rowPos + 1][colPos] : 1;
                        }
                    }
                    else {
                        currCell.rowSpan = (currCell.level > -1 || this.rowStartPos === 1) ?
                            spanCollection[rowPos][colPos] : -1;
                    }
                    if (!colflag) {
                        currCell.colSpan = 1;
                    }
                    if (!rowflag) {
                        spanCollection[rowPos][colPos] = 1;
                    }
                    colPos--;
                }
                rowPos--;
            }
        };
        OlapEngine.prototype.getOrdinal = function (currCell, nextRow) {
            var newOrdinal = 0;
            for (var cellIndex = currCell.colIndex; cellIndex > 0; cellIndex--) {
                if (nextRow[cellIndex].level === -1) {
                    newOrdinal = nextRow[cellIndex].ordinal;
                    break;
                }
            }
            return newOrdinal;
        };
        OlapEngine.prototype.frameValues = function (valCollection, colLength) {
            var rowStartPos = this.colDepth;
            var rowEndPos = this.pivotValues.length;
            var startRowOrdinal = 0;
            Iif (this.customArgs.action === 'down') {
                var keys = Object.keys(this.onDemandDrillEngine);
                rowStartPos = Number(keys[0]);
                rowEndPos = Number(keys[keys.length - 1]) + 1;
                startRowOrdinal = this.onDemandDrillEngine[rowStartPos][0].ordinal;
            }
            for (var rowPos = rowStartPos; rowPos < rowEndPos; rowPos++) {
                var columns = this.pivotValues[rowPos];
                var rowOrdinal = columns[0].ordinal;
                for (var colPos = 1; colPos < this.pivotValues[0].length; colPos++) {
                    Eif (this.pivotValues[this.colDepth - 1][colPos]) {
                        var colOrdinal = this.pivotValues[this.colDepth - 1][colPos].ordinal;
                        var lastColCell = this.pivotValues[this.colDepth - 1][colPos];
                        var measure = columns[0].memberType === 3 ? columns[0].actualText.toString() :
                            ((this.tupColumnInfo[lastColCell.ordinal] && this.tupColumnInfo[lastColCell.ordinal].measure) ?
                                this.tupColumnInfo[lastColCell.ordinal].measure.querySelector('UName').textContent :
                                columns[0].actualText);
                        if (columns[0].type === 'header') {
                            columns[colPos] = {
                                axis: 'value',
                                actualText: this.getUniqueName(measure),
                                formattedText: '',
                                value: 0,
                                colIndex: colPos,
                                rowIndex: rowPos
                            };
                        }
                        else {
                            var formattedText = void 0;
                            var value = '0';
                            var measureName = this.getUniqueName(measure);
                            var showTotals = true;
                            var attrDrill = (this.fieldList[columns[0].hierarchy] &&
                                this.fieldList[columns[0].hierarchy].isHierarchy) ? columns[0].isDrilled : true;
                            Eif (this.tupRowInfo[rowOrdinal]) {
                                showTotals = this.tupRowInfo[rowOrdinal].showTotals;
                            }
                            else {
                                var grandTotalFlag = this.dataSourceSettings.rows.length === 0 ||
                                    (this.dataSourceSettings.rows.length === 1 && this.dataSourceSettings.rows[0].name === '[Measures]');
                                showTotals = (this.dataSourceSettings.showGrandTotals && this.dataSourceSettings.showRowGrandTotals) ||
                                    grandTotalFlag;
                            }
                            var valElement = valCollection[(rowOrdinal - startRowOrdinal) * colLength + colOrdinal];
                            formattedText = this.showSubTotalsAtBottom && columns[0].isDrilled ? '' : (!showTotals && attrDrill) ? '' :
                                ((!ej2_base_1.isNullOrUndefined(valElement) && !ej2_base_1.isNullOrUndefined(valElement.querySelector('FmtValue'))) ?
                                    valElement.querySelector('FmtValue').textContent : this.emptyCellTextContent);
                            value = (!showTotals && attrDrill) ? '0' :
                                ((!ej2_base_1.isNullOrUndefined(valElement) && !ej2_base_1.isNullOrUndefined(valElement.querySelector('Value'))) ?
                                    valElement.querySelector('Value').textContent : null);
                            formattedText = this.showSubTotalsAtBottom && columns[0].isDrilled ? '' : showTotals && !ej2_base_1.isNullOrUndefined(value) ?
                                this.getFormattedValue(Number(value), measureName, (formattedText !== '' ? formattedText : value)) : formattedText;
                            var isSum = (this.tupColumnInfo[colOrdinal] ?
                                (this.tupColumnInfo[colOrdinal].allCount > 0 ||
                                    this.tupColumnInfo[colOrdinal].drillStartPos > -1) : true) ||
                                (this.tupRowInfo[rowOrdinal] ? (this.tupRowInfo[rowOrdinal].allCount > 0 ||
                                    this.tupRowInfo[rowOrdinal].drillStartPos > -1) : true);
                            var isGrand = (this.tupRowInfo[rowOrdinal] ?
                                (this.tupRowInfo[rowOrdinal].measurePosition === 0 ?
                                    this.tupRowInfo[rowOrdinal].allStartPos === 1 :
                                    this.tupRowInfo[rowOrdinal].allStartPos === 0) : false) ||
                                (this.tupColumnInfo[colOrdinal] ?
                                    (this.tupColumnInfo[colOrdinal].measurePosition === 0 ?
                                        this.tupColumnInfo[colOrdinal].allStartPos === 1 :
                                        this.tupColumnInfo[colOrdinal].allStartPos === 0) : false);
                            columns[colPos] = {
                                axis: 'value',
                                actualText: measureName,
                                formattedText: formattedText,
                                colOrdinal: colOrdinal,
                                rowOrdinal: rowOrdinal,
                                columnHeaders: this.tupColumnInfo[colOrdinal] ? this.tupColumnInfo[colOrdinal].captionCollection : '',
                                rowHeaders: this.tupRowInfo[rowOrdinal] ? this.tupRowInfo[rowOrdinal].captionCollection : '',
                                value: !ej2_base_1.isNullOrUndefined(value) ? Number(value) : null,
                                colIndex: colPos,
                                rowIndex: rowPos,
                                isSum: isSum,
                                isGrandSum: isGrand
                            };
                        }
                        this.valueContent[rowPos - this.rowStartPos][colPos] = columns[colPos];
                    }
                }
            }
        };
        OlapEngine.prototype.getFormattedValue = function (value, fieldName, formattedText) {
            var formattedValue = formattedText;
            if (this.formatFields[fieldName] && !ej2_base_1.isNullOrUndefined(value)) {
                var formatField = (this.formatFields[fieldName].properties ?
                    this.formatFields[fieldName].properties : this.formatFields[fieldName]);
                var formatObj = ej2_base_1.extend({}, formatField, null, true);
                delete formatObj.name;
                Iif (!formatObj.minimumSignificantDigits && formatObj.minimumSignificantDigits < 1) {
                    delete formatObj.minimumSignificantDigits;
                }
                Iif (!formatObj.maximumSignificantDigits && formatObj.maximumSignificantDigits < 1) {
                    delete formatObj.maximumSignificantDigits;
                }
                Iif (formatObj.type) {
                    formattedValue = this.globalize.formatDate(new Date(value.toString()), formatObj);
                }
                else {
                    delete formatObj.type;
                    formattedValue = this.globalize.formatNumber(value, formatObj);
                }
            }
            return formattedValue;
        };
        OlapEngine.prototype.getMeasureInfo = function () {
            this.olapValueAxis = undefined;
            this.olapRowValueIndex = undefined;
            var mAxis = 'column';
            var mIndex;
            var values = [];
            for (var _i = 0, _a = this.values; _i < _a.length; _i++) {
                var field = _a[_i];
                values[values.length] = (field.isCalculatedField ? this.fieldList[field.name].tag : field.name);
            }
            if (values.length > 0) {
                Eif (this.isMeasureAvail) {
                    var isAvail = false;
                    var fieldCount = 0;
                    for (var i = 0, cnt = this.rows.length; i < cnt; i++) {
                        if (this.rows[i].name.toLowerCase() === '[measures]') {
                            mAxis = 'row';
                            mIndex = i;
                            isAvail = true;
                            fieldCount = this.dataSourceSettings.rows.length;
                            this.olapRowValueIndex = mIndex;
                            break;
                        }
                    }
                    if (!isAvail) {
                        for (var i = 0, cnt = this.columns.length; i < cnt; i++) {
                            if (this.columns[i].name.toLowerCase() === '[measures]') {
                                mAxis = 'column';
                                mIndex = i;
                                isAvail = true;
                                fieldCount = this.dataSourceSettings.columns.length;
                                break;
                            }
                        }
                    }
                    this.olapValueAxis = mAxis;
                    this.measurePosition = mIndex;
                    this.measureIndex = mIndex === fieldCount - 1 ? -1 : mIndex;
                }
                else {
                    mAxis = this.valueAxis;
                    mIndex = mAxis === 'row' ? this.rows.length - 1 : this.columns.length - 1;
                }
                return { measureAxis: mAxis, measureIndex: mIndex, valueInfo: values };
            }
            else {
                return { measureAxis: mAxis, measureIndex: -1, valueInfo: [] };
            }
        };
        OlapEngine.prototype.frameMeasureOrder = function (measureInfo, axis, tuples, vTuples, cLen, valuesCount) {
            var orderedTuples = [];
            var orderedVTuples = [];
            var orderedIndex = [];
            var levels = {};
            var cLevels = [];
            var measureAxis = measureInfo.measureAxis;
            var measureIndex = measureInfo.measureIndex;
            var values = measureInfo.valueInfo;
            if (measureAxis === axis && values.length > 0) {
                var levelCollection = {};
                var uniqueLevels = [];
                for (var j = 0, lnt = tuples.length; j < lnt; j++) {
                    var node = tuples[j];
                    var members = [].slice.call(node.querySelectorAll('Member'));
                    var level = '';
                    var cLevel = '';
                    var i = 0;
                    while (i < members.length) {
                        level = level + (level !== '' ? '~~' : '') + members[i].querySelector('UName').textContent;
                        if (i === measureIndex && measureIndex === 0) {
                            cLevel = level;
                        }
                        else if (i === (measureIndex - 1)) {
                            cLevel = level;
                        }
                        i++;
                    }
                    if (levelCollection[cLevel]) {
                        levelCollection[cLevel][levelCollection[cLevel].length] = level;
                    }
                    else {
                        levelCollection[cLevel] = [level];
                        uniqueLevels[uniqueLevels.length] = cLevel;
                    }
                    levels[level] = { index: j, node: node };
                    cLevels[cLevels.length] = level;
                }
                Eif (cLevels.length > 0) {
                    Eif (uniqueLevels.length > 0) {
                        if (measureIndex === 0) {
                            for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
                                var name_1 = values_1[_i];
                                for (var _a = 0, uniqueLevels_1 = uniqueLevels; _a < uniqueLevels_1.length; _a++) {
                                    var key = uniqueLevels_1[_a];
                                    Eif (key === name_1) {
                                        for (var _b = 0, _c = levelCollection[key]; _b < _c.length; _b++) {
                                            var level = _c[_b];
                                            orderedIndex[orderedIndex.length] = levels[level].index;
                                            orderedTuples[orderedTuples.length] = levels[level].node;
                                        }
                                    }
                                }
                            }
                        }
                        else {
                            for (var _d = 0, uniqueLevels_2 = uniqueLevels; _d < uniqueLevels_2.length; _d++) {
                                var key = uniqueLevels_2[_d];
                                for (var _e = 0, values_2 = values; _e < values_2.length; _e++) {
                                    var name_2 = values_2[_e];
                                    for (var _f = 0, _g = levelCollection[key]; _f < _g.length; _f++) {
                                        var level = _g[_f];
                                        var levelInfo = level.split('~~');
                                        if (levelInfo[measureIndex] === name_2) {
                                            orderedIndex[orderedIndex.length] = levels[level].index;
                                            orderedTuples[orderedTuples.length] = levels[level].node;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                var clonedValTuple = [];
                Eif (vTuples.length > 0) {
                    var valueIndex = [];
                    var vOrdinalIndex = [];
                    var vOrdinalIndexPos = 0;
                    var len = 0;
                    var cRow = 0;
                    for (var j = 0, cnt = valuesCount; j < cnt; j++) {
                        if (len > (cLen - 1)) {
                            cRow++;
                            len = 0;
                            Eif (!valueIndex[cRow]) {
                                valueIndex[cRow] = [];
                            }
                            valueIndex[cRow][len] = j;
                            len++;
                        }
                        else {
                            if (!valueIndex[cRow]) {
                                valueIndex[cRow] = [];
                            }
                            valueIndex[cRow][len] = j;
                            len++;
                        }
                        var vTupleOrdinal = void 0;
                        Eif (vTuples[vOrdinalIndexPos]) {
                            vTupleOrdinal = this.olapVirtualization ?
                                j : Number(vTuples[vOrdinalIndexPos].getAttribute('CellOrdinal'));
                        }
                        else {
                            vOrdinalIndexPos++;
                        }
                        Eif (vTupleOrdinal === j) {
                            vOrdinalIndex[j] = vTupleOrdinal;
                            clonedValTuple[vTupleOrdinal] = vTuples[vOrdinalIndexPos];
                            vOrdinalIndexPos++;
                        }
                    }
                    vTuples = clonedValTuple;
                    if (measureAxis === 'column') {
                        Eif (valueIndex.length > 0 && valueIndex[0].length === orderedIndex.length) {
                            for (var i = 0, cnt = orderedIndex.length; i < cnt; i++) {
                                var j = 0;
                                while (j < valueIndex.length) {
                                    var index = (j * cLen) + i;
                                    Eif (!ej2_base_1.isNullOrUndefined(valueIndex[j]) && !ej2_base_1.isNullOrUndefined(orderedIndex[i])) {
                                        var ordinalValue = vOrdinalIndex[index] ?
                                            vOrdinalIndex[index].toString() : index.toString();
                                        var tuple = vTuples[Number(valueIndex[j][orderedIndex[i]])];
                                        Eif (tuple) {
                                            tuple.setAttribute('CellOrdinal', ordinalValue.toString());
                                            orderedVTuples[index] = tuple;
                                        }
                                    }
                                    j++;
                                }
                            }
                        }
                    }
                    else {
                        Eif (valueIndex.length === orderedIndex.length) {
                            for (var i = 0, cnt = orderedIndex.length; i < cnt; i++) {
                                var j = 0;
                                while (j < valueIndex[orderedIndex[i]].length) {
                                    var index = (i * cLen) + j;
                                    var ordinalValue = vOrdinalIndex[index] ?
                                        vOrdinalIndex[index].toString() : index.toString();
                                    var tuple = vTuples[Number(valueIndex[orderedIndex[i]][j])];
                                    Eif (tuple) {
                                        tuple.setAttribute('CellOrdinal', ordinalValue.toString());
                                        orderedVTuples[orderedVTuples.length] = tuple;
                                    }
                                    j++;
                                }
                            }
                        }
                    }
                }
                return { orderedHeaderTuples: orderedTuples, orderedValueTuples: orderedVTuples };
            }
            else {
                return { orderedHeaderTuples: tuples, orderedValueTuples: vTuples };
            }
        };
        OlapEngine.prototype.getDrilledSets = function (uNameCollection, currentCell, fieldPos, axis) {
            var levels = [];
            var memberName = currentCell.actualText.toString();
            var tupCollection = axis === 'row' ? this.tupRowInfo : this.tupColumnInfo;
            var currTuple = tupCollection[currentCell.ordinal];
            var measurePos = tupCollection[0].typeCollection.indexOf('3');
            var allStartPos = measurePos === 0 ? 1 : 0;
            var tupPos = 0;
            var isWithoutAllMember = tupCollection[0].typeCollection[fieldPos] === '1';
            while (tupPos < tupCollection.length) {
                if (ej2_base_1.isNullOrUndefined(tupCollection[tupPos].allStartPos) ||
                    tupCollection[tupPos].allStartPos > allStartPos) {
                    levels[levels.length] = tupCollection[tupPos].uNameCollection;
                }
                tupPos++;
            }
            var memberArray = uNameCollection.split('::[').map(function (item) {
                return item[0] === '[' ? item : ('[' + item);
            });
            var joinArray = [];
            for (var memPos = 0; memPos <= fieldPos; memPos++) {
                Eif (memberArray[memPos]) {
                    if ((isWithoutAllMember || this.isPaging) && memPos === fieldPos) {
                        var splitLevels = memberArray[memPos].split('~~');
                        var drillLevel = splitLevels.indexOf(memberName);
                        var cropLevels = [];
                        for (var lPos = 0; lPos <= drillLevel; lPos++) {
                            cropLevels.push(splitLevels[lPos]);
                        }
                        joinArray[joinArray.length] = cropLevels.length > 0 ? cropLevels.join('~~') : memberArray[memPos];
                    }
                    else {
                        joinArray[joinArray.length] = memberArray[memPos];
                    }
                }
            }
            uNameCollection = joinArray.join('::');
            var childSets = [];
            var memberObj = {};
            for (var _i = 0, levels_1 = levels; _i < levels_1.length; _i++) {
                var item = levels_1[_i];
                if (item.indexOf(uNameCollection) === 0) {
                    childSets.push(item);
                    Iif (this.isPaging) {
                        var drillField = item.split('::[')[fieldPos];
                        drillField = drillField[0] === '[' ? drillField : ('[' + drillField);
                        var drillFieldSep = drillField.split('~~');
                        for (var fPos = drillFieldSep.indexOf(memberName); fPos < drillFieldSep.length; fPos++) {
                            memberObj[drillFieldSep[fPos]] = drillFieldSep[fPos];
                        }
                    }
                }
            }
            Iif (this.isPaging) {
                var fieldSep = currTuple.uNameCollection.split('::[').map(function (item) {
                    return item[0] === '[' ? item : ('[' + item);
                });
                var cropArray = [];
                for (var fPos = 0; fPos < fieldSep.length; fPos++) {
                    if (fPos !== fieldPos) {
                        cropArray[fPos] = fieldSep[fPos];
                    }
                }
                var drillFieldSep = Object.keys(memberObj);
                for (var fPos = 0; fPos < drillFieldSep.length; fPos++) {
                    cropArray[fieldPos] = drillFieldSep[fPos];
                    childSets.push(cropArray.join('::'));
                }
            }
            var drillSets = {};
            for (var _a = 0, childSets_1 = childSets; _a < childSets_1.length; _a++) {
                var level = childSets_1[_a];
                var fields = level.split('::[').map(function (item) {
                    return item[0] === '[' ? item : ('[' + item);
                });
                var set = '';
                for (var pos = 0; pos <= fieldPos; pos++) {
                    var field = fields[pos];
                    Eif (field) {
                        var members = field.split('~~');
                        set = set + (set !== '' ? '~~' : '') + members[members.length - 1];
                    }
                }
                drillSets[set] = set;
            }
            return drillSets;
        };
        OlapEngine.prototype.updateDrilledInfo = function (dataSourceSettings) {
            this.dataSourceSettings = dataSourceSettings;
            this.drilledMembers = dataSourceSettings.drilledMembers ? this.updateDrilledItems(dataSourceSettings.drilledMembers) : [];
            this.generateGridData(dataSourceSettings);
        };
        OlapEngine.prototype.updateCalcFields = function (dataSourceSettings, lastcalcInfo) {
            this.dataSourceSettings = dataSourceSettings;
            this.calculatedFieldSettings = dataSourceSettings.calculatedFieldSettings ? dataSourceSettings.calculatedFieldSettings : [];
            this.getAxisFields();
            this.updateFieldlist();
            this.loadCalculatedMemberElements(this.calculatedFieldSettings);
            Iif (this.dataFields[lastcalcInfo.name]) {
                this.generateGridData(dataSourceSettings);
            }
            else {
                mdx_query_1.MDXQuery.getCellSets(dataSourceSettings, this, true, undefined, true);
            }
        };
        OlapEngine.prototype.onSort = function (dataSourceSettings, isValueSort) {
            this.dataSourceSettings = dataSourceSettings;
            Iif (!isValueSort) {
                this.sortSettings = dataSourceSettings.sortSettings ? dataSourceSettings.sortSettings : [];
                this.getAxisFields();
                this.frameSortObject();
                this.updateFieldlist();
            }
            Eif (this.xmlaCellSet.length > 0 && this.xmlDoc) {
                this.generateEngine(this.xmlDoc, this.request, this.customArgs);
            }
            else {
                this.generateGridData(dataSourceSettings);
            }
        };
        OlapEngine.prototype.updateFieldlist = function (isInit) {
            var i = 0;
            while (i < this.savedFieldListData.length) {
                var fieldName = this.savedFieldListData[i].id;
                var parentID = this.savedFieldListData[i].pid;
                if (this.savedFieldList[fieldName]) {
                    var sortOrder = (this.enableSort ? this.sortObject[fieldName] ?
                        this.sortObject[fieldName] : 'Ascending' : 'None');
                    this.savedFieldList[fieldName].isSelected = false;
                    this.savedFieldList[fieldName].isExcelFilter = false;
                    this.savedFieldList[fieldName].sort = sortOrder;
                    this.savedFieldList[fieldName].allowDragAndDrop = true;
                    this.savedFieldList[fieldName].showFilterIcon = true;
                    this.savedFieldList[fieldName].showSortIcon = true;
                    this.savedFieldList[fieldName].showEditIcon = true;
                    this.savedFieldList[fieldName].showRemoveIcon = true;
                    this.savedFieldList[fieldName].showValueTypeIcon = true;
                    this.savedFieldList[fieldName].showSubTotals = true;
                    this.savedFieldListData[i].sort = sortOrder;
                    this.savedFieldListData[i].allowDragAndDrop = true;
                    this.savedFieldListData[i].showFilterIcon = true;
                    this.savedFieldListData[i].showSortIcon = true;
                    this.savedFieldListData[i].showEditIcon = true;
                    this.savedFieldListData[i].showRemoveIcon = true;
                    this.savedFieldListData[i].showValueTypeIcon = true;
                    this.savedFieldListData[i].showSubTotals = true;
                    if (isInit) {
                        this.savedFieldList[fieldName].filter = [];
                        this.savedFieldList[fieldName].actualFilter = [];
                    }
                }
                if (this.dataFields[fieldName] && this.savedFieldList[fieldName] &&
                    this.selectedItems.indexOf(fieldName) > -1) {
                    this.savedFieldList[fieldName].isSelected = true;
                    this.savedFieldList[fieldName].allowDragAndDrop = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].allowDragAndDrop : true);
                    this.savedFieldList[fieldName].showFilterIcon = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showFilterIcon : true);
                    this.savedFieldList[fieldName].showSortIcon = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showSortIcon : true);
                    this.savedFieldList[fieldName].showEditIcon = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showEditIcon : true);
                    this.savedFieldList[fieldName].showRemoveIcon = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showRemoveIcon : true);
                    this.savedFieldList[fieldName].showValueTypeIcon = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showValueTypeIcon : true);
                    this.savedFieldList[fieldName].showSubTotals = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showSubTotals : true);
                    this.savedFieldListData[i].isSelected = true;
                    this.savedFieldListData[i].allowDragAndDrop = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].allowDragAndDrop : true);
                    this.savedFieldListData[i].showFilterIcon = (this.dataFields[fieldName] ?
                        this.dataFields[fieldName].showFilterIcon : true);
                    this.savedFieldListData[i].showSortIcon =
                        (this.dataFields[fieldName] ? this.dataFields[fieldName].showSortIcon : true);
                    this.savedFieldListData[i].showEditIcon =
                        (this.dataFields[fieldName] ? this.dataFields[fieldName].showEditIcon : true);
                    this.savedFieldListData[i].showRemoveIcon =
                        (this.dataFields[fieldName] ? this.dataFields[fieldName].showRemoveIcon : true);
                    this.savedFieldListData[i].showValueTypeIcon =
                        (this.dataFields[fieldName] ? this.dataFields[fieldName].showValueTypeIcon : true);
                    this.savedFieldListData[i].showSubTotals =
                        (this.dataFields[fieldName] ? this.dataFields[fieldName].showSubTotals : true);
                }
                else {
                    if (this.dataFields[parentID] && this.savedFieldList[parentID] &&
                        this.selectedItems.indexOf(parentID) > -1) {
                        this.savedFieldListData[i].isSelected = true;
                    }
                    else {
                        this.savedFieldListData[i].isSelected = false;
                    }
                }
                if ((this.savedFieldList[fieldName] && this.savedFieldList[fieldName].isCalculatedField) ||
                    fieldName.toLowerCase() === '[calculated members].[_0]') {
                    var isAvail = false;
                    for (var _i = 0, _a = this.calculatedFieldSettings; _i < _a.length; _i++) {
                        var field = _a[_i];
                        if (fieldName === field.name) {
                            var expression = field.formula;
                            var formatString = field.formatString;
                            this.savedFieldListData[i].formula = expression;
                            this.savedFieldListData[i].formatString = formatString;
                            this.savedFieldListData[i].parentHierarchy = (expression.toLowerCase().indexOf('measure') > -1 ?
                                undefined : field.hierarchyUniqueName);
                            this.savedFieldList[fieldName].formula = expression;
                            this.savedFieldList[fieldName].formatString = formatString;
                            this.savedFieldList[fieldName].parentHierarchy = this.savedFieldListData[i].parentHierarchy;
                            isAvail = true;
                        }
                    }
                    Iif ((!isAvail && fieldName.toLowerCase() !== '[calculated members].[_0]') ||
                        (fieldName.toLowerCase() === '[calculated members].[_0]' && this.calculatedFieldSettings.length === 0)) {
                        this.savedFieldListData.splice(i, 1);
                        i--;
                        if (this.savedFieldList[fieldName]) {
                            delete this.savedFieldList[fieldName];
                        }
                    }
                }
                i++;
            }
            this.fieldList = this.savedFieldList;
            this.fieldListData = this.savedFieldListData;
        };
        OlapEngine.prototype.updateFieldlistData = function (name, isSelect) {
            for (var _i = 0, _a = this.fieldListData; _i < _a.length; _i++) {
                var item = _a[_i];
                if (item.id === name) {
                    item.isSelected = isSelect ? true : false;
                    break;
                }
            }
        };
        OlapEngine.prototype.getFormattedFields = function (formats) {
            this.formatFields = {};
            var cnt = formats.length;
            while (cnt--) {
                this.formatFields[formats[cnt].name] = formats[cnt];
            }
        };
        OlapEngine.prototype.getCubes = function (dataSourceSettings) {
            var connectionString = this.getConnectionInfo(dataSourceSettings.url, dataSourceSettings.localeIdentifier.toString());
            var soapMessage = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body>' +
                '<Discover xmlns="urn:schemas-microsoft-com:xml-analysis"><RequestType>MDSCHEMA_CUBES</RequestType>' +
                '<Restrictions><RestrictionList><CATALOG_NAME>' + dataSourceSettings.catalog +
                '</CATALOG_NAME></RestrictionList></Restrictions><Properties><PropertyList><Catalog>' + dataSourceSettings.catalog +
                '</Catalog> <LocaleIdentifier>' + connectionString.LCID + '</LocaleIdentifier>' + (dataSourceSettings.roles ? '<Roles>' + dataSourceSettings.roles + '</Roles>' : '') + '</PropertyList></Properties>' +
                '</Discover></Body></Envelope>';
            this.doAjaxPost('POST', connectionString.url, soapMessage, this.validateCube.bind(this), { dataSourceSettings: dataSourceSettings, action: 'getCubes' });
            Iif (this.errorInfo) {
                throw this.errorInfo;
            }
        };
        OlapEngine.prototype.validateCube = function (xmlDoc, request, customArgs) {
            var fields = [].slice.call(xmlDoc.querySelectorAll('row'));
            var isCubeExist = false;
            for (var _i = 0, fields_1 = fields; _i < fields_1.length; _i++) {
                var field = fields_1[_i];
                var cubeName = field.querySelector('CUBE_NAME').textContent;
                if (cubeName === customArgs.dataSourceSettings.cube) {
                    isCubeExist = true;
                    break;
                }
            }
            Iif (!isCubeExist && fields.length > 0) {
                this.errorInfo = 'Invalid cube name ' + this.dataSourceSettings.cube;
            }
        };
        OlapEngine.prototype.getFieldList = function (dataSourceSettings) {
            var args = {
                catalog: dataSourceSettings.catalog,
                cube: dataSourceSettings.cube,
                url: dataSourceSettings.url,
                LCID: dataSourceSettings.localeIdentifier.toString(),
                request: 'MDSCHEMA_HIERARCHIES',
                roles: dataSourceSettings.roles
            };
            this.getTreeData(args, this.getFieldListItems.bind(this), { dataSourceSettings: dataSourceSettings, action: 'loadFieldElements' });
        };
        OlapEngine.prototype.getTreeData = function (args, successMethod, customArgs) {
            var connectionString = this.getConnectionInfo(args.url, args.LCID);
            var soapMessage = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><Discover xmlns="urn:schemas-microsoft-com:xml-analysis"><RequestType>' +
                args.request + '</RequestType><Restrictions><RestrictionList><CATALOG_NAME>' + args.catalog +
                '</CATALOG_NAME><CUBE_NAME>' + args.cube + '</CUBE_NAME></RestrictionList></Restrictions><Properties><PropertyList><Catalog>' + args.catalog +
                '</Catalog> <LocaleIdentifier>' + connectionString.LCID + '</LocaleIdentifier>' + (args.roles ? '<Roles>' + args.roles + '</Roles>' : '') + '</PropertyList></Properties></Discover></Body></Envelope>';
            this.doAjaxPost('POST', connectionString.url, soapMessage, successMethod, customArgs);
            Iif (this.errorInfo) {
                throw this.errorInfo;
            }
        };
        OlapEngine.prototype.getAxisFields = function () {
            this.rows = this.dataSourceSettings.rows ? this.dataSourceSettings.rows : [];
            this.columns = this.dataSourceSettings.columns ? this.dataSourceSettings.columns : [];
            this.filters = this.dataSourceSettings.filters ? this.dataSourceSettings.filters : [];
            this.values = this.dataSourceSettings.values ? this.dataSourceSettings.values : [];
            var dataFields = ej2_base_1.extend([], this.rows, null, true);
            dataFields = dataFields.concat(this.columns, this.values, this.filters);
            var len = dataFields.length;
            while (len--) {
                this.dataFields[dataFields[len].name] = dataFields[len];
                if (dataFields[len].name.toLowerCase() === '[measures]') {
                    this.isMeasureAvail = true;
                }
                else {
                    this.selectedItems.push(dataFields[len].name);
                }
            }
            this.mappingFields = {};
            Eif (this.dataSourceSettings.fieldMapping) {
                for (var _i = 0, _a = this.dataSourceSettings.fieldMapping; _i < _a.length; _i++) {
                    var field = _a[_i];
                    this.mappingFields[field.name] = field;
                }
            }
            Iif (!this.isMeasureAvail && this.values.length > 0) {
                var measureField = {
                    name: '[Measures]', caption: 'Measures', showRemoveIcon: true, allowDragAndDrop: true
                };
                if (this.valueAxis === 'row') {
                    this.rows.push(measureField);
                }
                else {
                    this.columns.push(measureField);
                }
                this.isMeasureAvail = true;
            }
        };
        OlapEngine.prototype.getAggregateType = function (fieldName, aggregateType) {
            var type;
            switch (aggregateType) {
                case '1':
                    type = 'Sum';
                    break;
                case '2':
                    type = 'Count';
                    break;
                case '3':
                    type = 'Min';
                    break;
                case '4':
                    type = 'Max';
                    break;
                case '5':
                    type = 'Avg';
                    break;
                case '8':
                    type = 'DistinctCount';
                    break;
                case '127':
                    type = 'CalculatedField';
                    break;
                default:
                    type = undefined;
                    break;
            }
            if (type) {
                return type;
            }
            else {
                return undefined;
            }
        };
        OlapEngine.prototype.getUniqueName = function (name) {
            var uName = name;
            for (var _i = 0, _a = this.calculatedFieldSettings; _i < _a.length; _i++) {
                var item = _a[_i];
                var expression = item.formula;
                var prefixName = (expression.toLowerCase().indexOf('measure') > -1 ? '[Measures].' : item.hierarchyUniqueName + '.');
                var uniqueName = prefixName + '[' + item.name + ']';
                if (name === uniqueName) {
                    uName = item.name;
                    break;
                }
            }
            return uName;
        };
        OlapEngine.prototype.updateFilterItems = function (filterItems) {
            var dataFields = ej2_base_1.extend([], this.rows, null, true);
            dataFields = dataFields.concat(this.columns);
            for (var _i = 0, filterItems_1 = filterItems; _i < filterItems_1.length; _i++) {
                var filter = filterItems_1[_i];
                Eif (filter.type === 'Include' && this.allowMemberFilter && this.fieldList[filter.name]) {
                    var members = this.fieldList[filter.name].members;
                    var isMembersAvail = (members && Object.keys(members).length > 0);
                    this.fieldList[filter.name].actualFilter = filter.items.slice();
                    var selectedElements = ej2_base_1.extend([], filter.items, null, true);
                    if (isMembersAvail) {
                        var i = 0;
                        while (i < selectedElements.length) {
                            var parentNodes = [];
                            parentNodes = this.getParentNode(selectedElements[i], members, parentNodes);
                            for (var _a = 0, parentNodes_1 = parentNodes; _a < parentNodes_1.length; _a++) {
                                var node = parentNodes_1[_a];
                                var index = util_1.PivotUtil.inArray(node, filter.items);
                                if (index !== -1) {
                                    filter.items.splice(index, 1);
                                }
                            }
                            i++;
                        }
                    }
                    var currentItems = [];
                    for (var _b = 0, _c = filter.items; _b < _c.length; _b++) {
                        var selectedElement = _c[_b];
                        var filterCaption = void 0;
                        Iif (!isMembersAvail && filter.items.length === 1) {
                            this.getMembers(this.dataSourceSettings, filter.name, undefined, undefined, undefined, filter.items[0]);
                            filterCaption = this.fieldList[filter.name].actualFilter[0];
                        }
                        currentItems.push(selectedElement);
                        if (isMembersAvail) {
                            this.fieldList[filter.name].filter.push(members[selectedElement].caption);
                        }
                        else {
                            this.fieldList[filter.name].filter.push(filterCaption ? filterCaption : selectedElement);
                        }
                    }
                    this.filterMembers[filter.name] = currentItems;
                    this.fieldList[filter.name].isExcelFilter = false;
                }
                else if ((this.allowValueFilter || this.allowLabelFilter) &&
                    ['Date', 'Label', 'Number', 'Value'].indexOf(filter.type) !== -1) {
                    for (var _d = 0, dataFields_1 = dataFields; _d < dataFields_1.length; _d++) {
                        var item = dataFields_1[_d];
                        if (item.name === filter.name) {
                            var filterMembers = this.filterMembers[filter.name];
                            if (filterMembers && (typeof filterMembers[0] === 'object' && filterMembers[0].type === filter.type)) {
                                filterMembers[filterMembers.length] = filter;
                            }
                            else {
                                this.filterMembers[filter.name] = [filter];
                            }
                            this.fieldList[filter.name].isExcelFilter = true;
                            break;
                        }
                    }
                }
            }
        };
        OlapEngine.prototype.getParentNode = function (name, members, items) {
            Iif (members[name].parent && name !== members[name].parent) {
                var parentItem = members[name].parent;
                items.push(parentItem);
                this.getParentNode(parentItem, members, items);
            }
            return items;
        };
        OlapEngine.prototype.updateDrilledItems = function (drilledMembers) {
            var drilledItems = [];
            var dataFields = ej2_base_1.extend([], this.rows, null, true);
            dataFields = dataFields.concat(this.columns);
            for (var _i = 0, drilledMembers_1 = drilledMembers; _i < drilledMembers_1.length; _i++) {
                var item = drilledMembers_1[_i];
                for (var _a = 0, dataFields_2 = dataFields; _a < dataFields_2.length; _a++) {
                    var field = dataFields_2[_a];
                    if (item.name === field.name) {
                        drilledItems.push(item);
                        break;
                    }
                }
            }
            return drilledItems;
        };
        OlapEngine.prototype.getDrillThroughData = function (pivotValue, maxRows) {
            var column = this.tupColumnInfo[pivotValue.colOrdinal] &&
                this.tupColumnInfo[pivotValue.colOrdinal].uNameCollection &&
                this.tupColumnInfo[pivotValue.colOrdinal].uNameCollection !== '' ?
                this.tupColumnInfo[pivotValue.colOrdinal].uNameCollection.split('::[').map(function (item) {
                    return item[0] === '[' ? item : ('[' + item);
                }) : [];
            var row = this.tupRowInfo[pivotValue.rowOrdinal] &&
                this.tupRowInfo[pivotValue.rowOrdinal].uNameCollection &&
                this.tupRowInfo[pivotValue.rowOrdinal].uNameCollection !== '' ?
                this.tupRowInfo[pivotValue.rowOrdinal].uNameCollection.split('::[').map(function (item) {
                    return item[0] === '[' ? item : ('[' + item);
                }) : [];
            var filters;
            var filteritems = [];
            var filterQuery = '';
            for (var i = 0; i < this.filters.length; i++) {
                filters = this.filterMembers[this.filters[i].name];
                if (filters) {
                    for (var j = 0; j < filters.length; j++) {
                        filterQuery = filterQuery + filters[j];
                        filterQuery = j < filters.length - 1 ? filterQuery + ',' : filterQuery + '';
                    }
                    filteritems[i] = filterQuery;
                    filterQuery = '';
                }
            }
            for (var i = 0; i < filteritems.length; i++) {
                filterQuery = filterQuery === '' ? '{' + filteritems[i] + '}' : (filterQuery + ',' + '{' + filteritems[i] + '}');
            }
            var columnQuery = '';
            var rowQuery = '';
            for (var i = 0; i < column.length; i++) {
                columnQuery = (columnQuery.length > 0 ? (columnQuery + ',') : '') + (column[i].split('~~').length > 1 ?
                    column[i].split('~~')[column[i].split('~~').length - 1] : column[i]);
            }
            for (var i = 0; i < row.length; i++) {
                rowQuery = (rowQuery.length > 0 ? (rowQuery + ',') : '') + (row[i].split('~~').length > 1 ?
                    row[i].split('~~')[row[i].split('~~').length - 1] : row[i]);
            }
            var drillQuery = 'DRILLTHROUGH MAXROWS ' + maxRows + ' Select(' + (columnQuery.length > 0 ? columnQuery : '') +
                (columnQuery.length > 0 && rowQuery.length > 0 ? ',' : '') + (rowQuery.length > 0 ? rowQuery : '') + ') on 0 from ' +
                (filterQuery === '' ? '[' + this.dataSourceSettings.cube + ']' : '(SELECT (' + filterQuery + ') ON COLUMNS FROM [' +
                    this.dataSourceSettings.cube + '])');
            drillQuery = drillQuery.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;');
            var xmla = this.getSoapMsg(this.dataSourceSettings, drillQuery);
            var connectionString = this.getConnectionInfo(this.dataSourceSettings.url, this.dataSourceSettings.localeIdentifier);
            this.doAjaxPost('POST', connectionString.url, xmla, this.drillThroughSuccess.bind(this), { dataSourceSettings: this.dataSourceSettings, action: 'drillThrough' });
            if (this.errorInfo) {
                throw this.errorInfo;
            }
        };
        OlapEngine.prototype.drillThroughSuccess = function (xmlDoc) {
            var tag = [].slice.call(xmlDoc.querySelectorAll('row'));
            var gridJSON = '';
            if (tag.length > 0) {
                var json = [];
                var i = 0;
                while (i < tag.length) {
                    var child = [].slice.call(tag[i].children);
                    var j = 0;
                    while (j < child.length) {
                        json.push('"' + child[j].tagName + '"' + ':' + '"' + child[j].textContent + '"');
                        j++;
                    }
                    i++;
                }
                var value = json[0];
                var k = 0;
                while (k < json.length) {
                    if (Object.keys(JSON.parse('[{' + json[k] + '}]')[0])[0] === Object.keys(JSON.parse('[{' + value + '}]')[0])[0]) {
                        gridJSON += gridJSON === '' ? '[{' + json[k] : '}, {' + json[k];
                        k++;
                        continue;
                    }
                    gridJSON += ',' + json[k];
                    k++;
                }
                gridJSON += '}]';
            }
            else {
                var tag_1 = [].slice.call(xmlDoc.querySelectorAll('faultstring'));
                var i = 0;
                while (i < tag_1.length) {
                    gridJSON += tag_1[i].textContent;
                    i++;
                }
            }
            this.gridJSON = gridJSON;
        };
        OlapEngine.prototype.getFilterMembers = function (dataSourceSettings, fieldName, levelCount, isSearchFilter, loadLevelMember) {
            var levels = this.fieldList[fieldName].levels;
            var cLevel = this.fieldList[fieldName].levelCount;
            var filterQuery;
            if (loadLevelMember) {
                filterQuery = 'Descendants({' + levels[cLevel].id + '}, ' +
                    levels[levelCount - 1].id + ', ' + ((levelCount - cLevel) === 1 ? 'SELF)' : 'SELF_AND_BEFORE)');
            }
            else {
                filterQuery = fieldName + ', Descendants({' + levels[0].id + '}, ' + levels[levelCount - 1].id + ', SELF_AND_BEFORE)';
            }
            this.fieldList[fieldName].levelCount = levelCount;
            if (!isSearchFilter) {
                this.getMembers(dataSourceSettings, fieldName, false, filterQuery, loadLevelMember);
            }
            return filterQuery;
        };
        OlapEngine.prototype.getMembers = function (dataSourceSettings, fieldName, isAllFilterData, filterParentQuery, loadLevelMember, filterItemName) {
            var dimProp = 'DIMENSION PROPERTIES PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, CHILDREN_CARDINALITY, MEMBER_TYPE, MEMBER_VALUE';
            var mdxQuery;
            var hasAllMember = this.fieldList[fieldName].hasAllMember;
            var hierarchy = (hasAllMember ? fieldName : fieldName + '.LEVELS(0)').replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;');
            Eif (!isAllFilterData && !filterItemName) {
                mdxQuery = 'SELECT ({' + (filterParentQuery ?
                    filterParentQuery : (hasAllMember ? hierarchy + ', ' + hierarchy + '.CHILDREN' : hierarchy + '.ALLMEMBERS')) + '})' +
                    dimProp + ' ON 0 FROM [' + dataSourceSettings.cube + ']';
            }
            else if (filterItemName) {
                filterItemName = filterItemName.replace(/&/g, '&amp;');
                mdxQuery = 'SELECT {' + filterItemName + '} ON 0 FROM [' + dataSourceSettings.cube + '] WHERE {}';
            }
            else {
                mdxQuery = 'SELECT ({' + hierarchy + '.ALLMEMBERS})' + dimProp + ' ON 0 FROM [' + dataSourceSettings.cube + ']';
            }
            var xmla = this.getSoapMsg(dataSourceSettings, mdxQuery);
            var connectionString = this.getConnectionInfo(dataSourceSettings.url, dataSourceSettings.localeIdentifier);
            Eif (!loadLevelMember) {
                this.fieldList[fieldName].filterMembers = [];
                this.fieldList[fieldName].childMembers = [];
                this.fieldList[fieldName].searchMembers = [];
                this.fieldList[fieldName].members = {};
                this.fieldList[fieldName].currrentMembers = {};
            }
            this.doAjaxPost('POST', connectionString.url, xmla, filterItemName ? this.getOlapFilterText.bind(this) : this.generateMembers.bind(this), { dataSourceSettings: dataSourceSettings, fieldName: fieldName, loadLevelMembers: loadLevelMember, action: 'fetchMembers' });
            Iif (this.errorInfo) {
                throw this.errorInfo;
            }
        };
        OlapEngine.prototype.getOlapFilterText = function (xmlDoc, request, customArgs) {
            var fields = [].slice.call(xmlDoc.querySelectorAll('Axis[name="Axis0"] Tuple'));
            if (fields.length > 0 && this.fieldList[customArgs.fieldName] && fields[fields.length - 1].getElementsByTagName('Caption')
                && fields[fields.length - 1].getElementsByTagName('Caption')[0]) {
                this.fieldList[customArgs.fieldName].actualFilter[0] = fields[fields.length - 1].getElementsByTagName('Caption')[0].textContent;
            }
        };
        OlapEngine.prototype.getChildMembers = function (dataSourceSettings, memberUQName, fieldName) {
            var dimProp = 'DIMENSION PROPERTIES PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, CHILDREN_CARDINALITY, MEMBER_TYPE, MEMBER_VALUE';
            var mdxQuery = 'SELECT ({' + memberUQName.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;') + '.CHILDREN})' + dimProp + ' ON 0 FROM [' + dataSourceSettings.cube + ']';
            var xmla = this.getSoapMsg(dataSourceSettings, mdxQuery);
            var connectionString = this.getConnectionInfo(dataSourceSettings.url, dataSourceSettings.localeIdentifier);
            this.doAjaxPost('POST', connectionString.url, xmla, this.generateMembers.bind(this), { dataSourceSettings: dataSourceSettings, fieldName: fieldName, action: 'fetchChildMembers' });
            if (this.errorInfo) {
                throw this.errorInfo;
            }
        };
        OlapEngine.prototype.getCalcChildMembers = function (dataSourceSettings, memberUQName) {
            this.calcChildMembers = [];
            var dimProp = 'DIMENSION PROPERTIES PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, CHILDREN_CARDINALITY, MEMBER_TYPE, MEMBER_VALUE';
            var mdxQuery = 'SELECT ({' + memberUQName.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;') + '.MEMBERS})' +
                dimProp + ' ON 0 FROM [' + dataSourceSettings.cube + ']';
            var connectionString = this.getConnectionInfo(dataSourceSettings.url, dataSourceSettings.localeIdentifier);
            var xmla = this.getSoapMsg(dataSourceSettings, mdxQuery);
            this.doAjaxPost('POST', connectionString.url, xmla, this.generateMembers.bind(this), { dataSourceSettings: dataSourceSettings, action: 'fetchCalcChildMembers' });
            if (this.errorInfo) {
                throw this.errorInfo;
            }
        };
        OlapEngine.prototype.getSearchMembers = function (dataSourceSettings, fieldName, searchString, maxNodeLimit, isAllFilterData, levelCount) {
            this.fieldList[fieldName].searchMembers = [];
            this.fieldList[fieldName].currrentMembers = {};
            if (searchString !== '') {
                var dimProp = 'DIMENSION PROPERTIES PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, CHILDREN_CARDINALITY, MEMBER_TYPE, MEMBER_VALUE';
                var hierarchy = fieldName.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/'/g, '&apos;').replace(/"/g, '&quot;');
                var mdxQuery = 'WITH SET [SearchMembersSet] AS &#39;FILTER(' + (isAllFilterData ? hierarchy + '.ALLMEMBERS, ' :
                    '{' + (levelCount > 1 ? this.getFilterMembers(dataSourceSettings, fieldName, levelCount, true) :
                        hierarchy + ', ' + hierarchy + '.CHILDREN') + '},') +
                    '(INSTR(1, ' + hierarchy + '.CurrentMember.member_caption, "' + searchString + '") > 0))&#39;' +
                    'SET [SearchParentsSet] AS &#39;GENERATE([SearchMembersSet], ASCENDANTS([SearchMembersSet].Current))&#39;' +
                    'SET [SearchSet] AS &#39;HIERARCHIZE(DISTINCT({[SearchMembersSet], [SearchParentsSet]}))&#39;' +
                    'SELECT SUBSET([SearchSet], 0, ' + maxNodeLimit + ')' + dimProp + ' ON 0 FROM [' + dataSourceSettings.cube + ']';
                var xmla = this.getSoapMsg(dataSourceSettings, mdxQuery);
                var connectionString = this.getConnectionInfo(dataSourceSettings.url, dataSourceSettings.localeIdentifier);
                this.doAjaxPost('POST', connectionString.url, xmla, this.generateMembers.bind(this), {
                    dataSourceSettings: dataSourceSettings,
                    fieldName: fieldName, action: 'fetchSearchMembers'
                });
                if (this.errorInfo) {
                    throw this.errorInfo;
                }
            }
            else {
                return;
            }
        };
        OlapEngine.prototype.generateMembers = function (xmlDoc, request, customArgs) {
            var fields = [].slice.call(xmlDoc.querySelectorAll('Axis[name="Axis0"] Tuple'));
            var fieldName = customArgs.fieldName;
            var allMember;
            var filterMembers = {};
            for (var _i = 0, fields_2 = fields; _i < fields_2.length; _i++) {
                var field = fields_2[_i];
                var member = field.querySelector('Member');
                var memberType = member.querySelector('MEMBER_TYPE').textContent;
                var memberUqName = member.querySelector('UName').textContent;
                var caption = member.querySelector('Caption').textContent;
                var parentUqName = member.querySelector('PARENT_UNIQUE_NAME') ? member.querySelector('PARENT_UNIQUE_NAME').textContent : '';
                var nodeAttr = { 'data-fieldName': fieldName, 'data-memberId': memberUqName };
                Iif (parentUqName === '' && memberType === '1') {
                    filterMembers = {
                        hasChildren: (field.querySelector('CHILDREN_CARDINALITY') ? (field.querySelector('CHILDREN_CARDINALITY').textContent !== '0') ? true : false : false),
                        isSelected: false,
                        id: memberUqName,
                        tag: memberUqName,
                        name: caption,
                        caption: caption,
                        htmlAttributes: nodeAttr
                    };
                    if (customArgs.action === 'fetchMembers' || customArgs.action === 'fetchChildMembers') {
                        this.fieldList[fieldName].members[memberUqName] =
                            { name: memberUqName, caption: caption, parent: undefined, isNodeExpand: false, isSelected: false };
                        this.fieldList[fieldName].filterMembers.push(filterMembers);
                        this.fieldList[fieldName].childMembers.push(filterMembers);
                    }
                    else if (customArgs.action === 'fetchSearchMembers') {
                        this.fieldList[fieldName].currrentMembers[memberUqName] =
                            { name: memberUqName, caption: caption, parent: undefined, isNodeExpand: false, isSelected: false };
                        this.fieldList[fieldName].searchMembers.push(filterMembers);
                        filterMembers.expanded = true;
                    }
                    else {
                        this.calcChildMembers.push(filterMembers);
                    }
                }
                else if (parentUqName !== '' && memberType === '1') {
                    Eif (parentUqName === allMember && memberType === '1') {
                        filterMembers = {
                            hasChildren: (field.querySelector('CHILDREN_CARDINALITY') ? (field.querySelector('CHILDREN_CARDINALITY').textContent !== '0') ? true : false : false),
                            id: memberUqName,
                            name: caption,
                            isSelected: false,
                            caption: caption,
                            htmlAttributes: nodeAttr,
                            tag: memberUqName
                        };
                        Eif (customArgs.action === 'fetchMembers' || customArgs.action === 'fetchChildMembers') {
                            this.fieldList[fieldName].filterMembers.push(filterMembers);
                            this.fieldList[fieldName].childMembers.push(filterMembers);
                            this.fieldList[fieldName].members[memberUqName] =
                                { name: memberUqName, caption: caption, parent: undefined, isNodeExpand: false, isSelected: false };
                        }
                        else if (customArgs.action === 'fetchSearchMembers') {
                            filterMembers.expanded = true;
                            this.fieldList[fieldName].searchMembers.push(filterMembers);
                            this.fieldList[fieldName].currrentMembers[memberUqName] =
                                { name: memberUqName, caption: caption, parent: undefined, isNodeExpand: false, isSelected: false };
                        }
                        else {
                            this.calcChildMembers.push(filterMembers);
                        }
                    }
                    else {
                        if (customArgs.action === 'fetchMembers' && this.fieldList[fieldName].members[memberUqName]) {
                            continue;
                        }
                        var nodeSelect = (customArgs.loadLevelMembers ?
                            this.fieldList[fieldName].members[parentUqName].isSelected : false);
                        filterMembers = {
                            hasChildren: (field.querySelector('CHILDREN_CARDINALITY') ?
                                (field.querySelector('CHILDREN_CARDINALITY').textContent !== '0') ? true : false : false),
                            htmlAttributes: nodeAttr,
                            isSelected: false,
                            id: memberUqName,
                            pid: parentUqName,
                            name: caption,
                            caption: caption,
                            tag: memberUqName
                        };
                        if (customArgs.action === 'fetchMembers' || customArgs.action === 'fetchChildMembers') {
                            this.fieldList[fieldName].isHierarchy = false;
                            this.fieldList[fieldName].filterMembers.push(filterMembers);
                            this.fieldList[fieldName].childMembers.push(filterMembers);
                            this.fieldList[fieldName].members[memberUqName] =
                                { name: memberUqName, caption: caption, parent: parentUqName, isNodeExpand: false, isSelected: nodeSelect };
                        }
                        else if (customArgs.action === 'fetchSearchMembers') {
                            this.fieldList[fieldName].searchMembers.push(filterMembers);
                            filterMembers.expanded = true;
                            this.fieldList[fieldName].currrentMembers[memberUqName] =
                                { name: memberUqName, caption: caption, parent: parentUqName, isNodeExpand: false, isSelected: false };
                        }
                        else {
                            this.calcChildMembers.push(filterMembers);
                        }
                    }
                }
                else Eif (memberType === '2') {
                    allMember = memberUqName;
                }
            }
        };
        OlapEngine.prototype.getFieldListItems = function (xmlDoc, request, customArgs) {
            var fieldDate = {};
            var hierarchyElements = [];
            var fields = [].slice.call(xmlDoc.querySelectorAll('row'));
            for (var _i = 0, fields_3 = fields; _i < fields_3.length; _i++) {
                var field = fields_3[_i];
                var isAllMemberAvail = [].slice.call(field.querySelectorAll('ALL_MEMBER')).length > 0;
                var dimensionName = field.querySelector('DIMENSION_UNIQUE_NAME').textContent;
                var hierarchyName = field.querySelector('HIERARCHY_UNIQUE_NAME').textContent;
                var isSameDim = dimensionName === hierarchyName && dimensionName.toLowerCase() !== '[measures]' && hierarchyName.toLowerCase() !== '[measures]';
                hierarchyElements.push({
                    pid: ((this.isMondrian || isSameDim) ? dimensionName + '~#^Dim' : dimensionName),
                    id: hierarchyName,
                    name: field.querySelector('HIERARCHY_CAPTION').textContent,
                    caption: field.querySelector('HIERARCHY_CAPTION').textContent,
                    tag: hierarchyName,
                    hasAllMember: isAllMemberAvail,
                    allMember: (isAllMemberAvail ? field.querySelectorAll('ALL_MEMBER')[0].textContent : undefined),
                    type: 'string'
                });
            }
            fieldDate = {
                hierarchy: hierarchyElements,
                hierarchySuccess: xmlDoc,
                measures: []
            };
            this.fieldListObj = fieldDate;
            var args = {
                catalog: customArgs.dataSourceSettings.catalog,
                cube: customArgs.dataSourceSettings.cube,
                url: customArgs.dataSourceSettings.url,
                LCID: customArgs.dataSourceSettings.localeIdentifier.toString(),
                request: 'MDSCHEMA_DIMENSIONS',
                roles: customArgs.dataSourceSettings.roles
            };
            this.getTreeData(args, this.loadDimensionElements.bind(this), customArgs);
        };
        OlapEngine.prototype.loadCalculatedMemberElements = function (calcMembers) {
            if (calcMembers.length > 0) {
                var fieldListElements = this.fieldListData;
                var calcObj = {
                    hasChildren: true,
                    isSelected: false,
                    id: '[Calculated Members].[_0]',
                    name: '[Calculated Members].[_0]',
                    caption: 'Calculated Members',
                    spriteCssClass: 'e-calcMemberGroupCDB' + ' ' + cls.ICON,
                    tag: '[Calculated Members].[_0]',
                    type: 'string'
                };
                if (fieldListElements.length > 0 && fieldListElements[0].id.toLowerCase() === '[measures]') {
                    fieldListElements.splice(0, 0, calcObj);
                }
                for (var _i = 0, calcMembers_1 = calcMembers; _i < calcMembers_1.length; _i++) {
                    var field = calcMembers_1[_i];
                    if (!this.fieldList[field.name]) {
                        var expression = field.formula;
                        var prefixName = (expression.toLowerCase().indexOf('measure') > -1 ? '[Measures].' :
                            field.hierarchyUniqueName + '.');
                        var uniqueName = prefixName + '[' + field.name + ']';
                        var caption = (this.dataFields[field.name] && this.dataFields[field.name].caption ?
                            this.dataFields[field.name].caption :
                            this.mappingFields[field.name] && this.mappingFields[field.name].caption ?
                                this.mappingFields[field.name].caption : field.name);
                        var formatString = field.formatString;
                        var calcField = {
                            hasChildren: false,
                            isSelected: false,
                            id: field.name,
                            pid: '[Calculated Members].[_0]',
                            name: field.name,
                            caption: caption,
                            spriteCssClass: 'e-calc-member' + ' ' + (expression.toLowerCase().indexOf('measure') > -1 ?
                                'e-calc-measure-icon' : 'e-calc-dimension-icon') + ' ' + cls.ICON,
                            tag: uniqueName,
                            formula: expression,
                            formatString: formatString,
                            aggregateType: undefined,
                            type: 'CalculatedField',
                            filter: [],
                            dateMember: [],
                            sort: 'Ascending',
                            actualFilter: [],
                            filterMembers: [],
                            childMembers: [],
                            searchMembers: [],
                            members: {},
                            currrentMembers: {},
                            isHierarchy: true,
                            isExcelFilter: false,
                            isCalculatedField: true,
                            allowDragAndDrop: (this.dataFields[field.name] ? this.dataFields[field.name].allowDragAndDrop :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].allowDragAndDrop : true),
                            showFilterIcon: (this.dataFields[field.name] ? this.dataFields[field.name].showFilterIcon :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].showFilterIcon : true),
                            showSortIcon: (this.dataFields[field.name] ? this.dataFields[field.name].showSortIcon :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].showSortIcon : true),
                            showEditIcon: (this.dataFields[field.name] ? this.dataFields[field.name].showEditIcon :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].showEditIcon : true),
                            showRemoveIcon: (this.dataFields[field.name] ? this.dataFields[field.name].showRemoveIcon :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].showRemoveIcon : true),
                            showValueTypeIcon: (this.dataFields[field.name] ? this.dataFields[field.name].showValueTypeIcon :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].showValueTypeIcon : true),
                            showSubTotals: (this.dataFields[field.name] ? this.dataFields[field.name].showSubTotals :
                                this.mappingFields[field.name] ? this.mappingFields[field.name].showSubTotals : true),
                            fieldType: (expression.toLowerCase().indexOf('measure') > -1 ? 'Measure' : 'Dimension'),
                            parentHierarchy: (expression.toLowerCase().indexOf('measure') > -1 ? undefined : field.hierarchyUniqueName)
                        };
                        fieldListElements.push(calcField);
                        this.fieldList[calcField.id] = calcField;
                        this.updateMembersOrder(field.name);
                    }
                }
            }
            else {
                return;
            }
        };
        OlapEngine.prototype.loadDimensionElements = function (xmlDoc, request, customArgs) {
            var hierarchyElements = [];
            var fields = [].slice.call(xmlDoc.querySelectorAll('row'));
            var measure = {};
            for (var _i = 0, fields_4 = fields; _i < fields_4.length; _i++) {
                var field = fields_4[_i];
                var dimensionName = field.querySelector('DIMENSION_UNIQUE_NAME').textContent;
                var defaultHierarchy = field.querySelector('DEFAULT_HIERARCHY').textContent;
                var dimensionCaption = field.querySelector('DIMENSION_CAPTION').textContent;
                var isSameDim = dimensionName === defaultHierarchy;
                if (dimensionName.toLowerCase().indexOf('[measure') >= 0) {
                    measure = {
                        hasChildren: true,
                        isSelected: false,
                        id: dimensionName,
                        name: dimensionName,
                        caption: dimensionCaption,
                        spriteCssClass: dimensionName.toLowerCase() === '[measures]' ? 'e-measureGroupCDB-icon' + ' ' + cls.ICON : 'e-dimensionCDB-icon' + ' ' + cls.ICON,
                        tag: dimensionName,
                        type: 'string'
                    };
                }
                else Eif (ej2_base_1.isNullOrUndefined(fields[0].querySelector('HIERARCHY_CAPTION'))) {
                    hierarchyElements.push({
                        hasChildren: true,
                        isSelected: false,
                        id: ((this.isMondrian || isSameDim) ? dimensionName + '~#^Dim' : dimensionName),
                        name: dimensionName,
                        caption: dimensionCaption,
                        spriteCssClass: 'e-dimensionCDB-icon' + ' ' + cls.ICON,
                        tag: dimensionName,
                        defaultHierarchy: field.querySelector('DEFAULT_HIERARCHY').textContent,
                        type: 'string'
                    });
                }
            }
            hierarchyElements.splice(0, 0, measure);
            this.fieldListData = hierarchyElements;
            var args = {
                catalog: customArgs.dataSourceSettings.catalog,
                cube: customArgs.dataSourceSettings.cube,
                url: customArgs.dataSourceSettings.url,
                LCID: customArgs.dataSourceSettings.localeIdentifier.toString(),
                request: 'MDSCHEMA_SETS',
                roles: customArgs.dataSourceSettings.roles
            };
            this.getTreeData(args, this.loadNamedSetElements.bind(this), customArgs);
        };
        OlapEngine.prototype.loadNamedSetElements = function (xmlDoc, request, customArgs) {
            var dataFields = ej2_base_1.extend([], this.rows, null, true);
            dataFields = dataFields.concat(this.columns, this.filters);
            var dimensionElements = this.fieldListData;
            var reportElement = [];
            for (var _i = 0, dataFields_3 = dataFields; _i < dataFields_3.length; _i++) {
                var field = dataFields_3[_i];
                reportElement.push(field.name);
            }
            var measureGroupItems = [];
            var fields = [].slice.call(xmlDoc.querySelectorAll('row'));
            for (var _a = 0, fields_5 = fields; _a < fields_5.length; _a++) {
                var field = fields_5[_a];
                if (!(measureGroupItems.indexOf(field.querySelector('DIMENSIONS').textContent.split('.')[0]) >= 0)) {
                    dimensionElements.push({
                        hasChildren: true,
                        isSelected: false,
                        pid: field.querySelector('DIMENSIONS').textContent.split('.')[0],
                        id: field.querySelector('SET_DISPLAY_FOLDER').textContent + '_' + field.querySelector('DIMENSIONS').textContent.split('.')[0],
                        name: field.querySelector('SET_DISPLAY_FOLDER').textContent,
                        spriteCssClass: 'e-folderCDB-icon' + ' ' + cls.ICON + ' ' + 'namedSets',
                        caption: field.querySelector('SET_DISPLAY_FOLDER').textContent,
                        type: 'string'
                    });
                    measureGroupItems.push(field.querySelector('DIMENSIONS').textContent.split('.')[0]);
                }
                var id = '[' + field.querySelector('SET_NAME').textContent.trim() + ']';
                var fieldObj = {
                    hasChildren: true,
                    isNamedSets: true,
                    isSelected: (reportElement.indexOf('[' + field.querySelector('SET_NAME').textContent + ']') >= 0),
                    pid: field.querySelector('SET_DISPLAY_FOLDER').textContent + '_' + field.querySelector('DIMENSIONS').textContent.split('.')[0],
                    id: id,
                    name: field.querySelector('SET_CAPTION').textContent,
                    caption: this.dataFields[id] && this.dataFields[id].caption ? this.dataFields[id].caption : this.mappingFields[id] && this.mappingFields[id].caption ? this.mappingFields[id].caption : field.querySelector('SET_CAPTION').textContent,
                    spriteCssClass: 'e-namedSetCDB-icon' + ' ' + cls.ICON,
                    tag: field.querySelector('EXPRESSION').textContent,
                    type: 'string',
                    filter: [],
                    dateMember: [],
                    actualFilter: [],
                    filterMembers: [],
                    childMembers: [],
                    searchMembers: [],
                    members: {},
                    currrentMembers: {},
                    isHierarchy: true,
                    isExcelFilter: false,
                    allowDragAndDrop: (this.dataFields[id] ? this.dataFields[id].allowDragAndDrop :
                        this.mappingFields[id] ? this.mappingFields[id].allowDragAndDrop : true),
                    showFilterIcon: (this.dataFields[id] ? this.dataFields[id].showFilterIcon :
                        this.mappingFields[id] ? this.mappingFields[id].showFilterIcon : true),
                    showSortIcon: (this.dataFields[id] ? this.dataFields[id].showSortIcon :
                        this.mappingFields[id] ? this.mappingFields[id].showSortIcon : true),
                    showEditIcon: (this.dataFields[id] ? this.dataFields[id].showEditIcon :
                        this.mappingFields[id] ? this.mappingFields[id].showEditIcon : true),
                    showRemoveIcon: (this.dataFields[id] ? this.dataFields[id].showRemoveIcon :
                        this.mappingFields[id] ? this.mappingFields[id].showRemoveIcon : true),
                    showValueTypeIcon: (this.dataFields[id] ? this.dataFields[id].showValueTypeIcon :
                        this.mappingFields[id] ? this.mappingFields[id].showValueTypeIcon : true),
                    showSubTotals: (this.dataFields[id] ? this.dataFields[id].showSubTotals :
                        this.mappingFields[id] ? this.mappingFields[id].showSubTotals : true)
                };
                dimensionElements.push(fieldObj);
                this.fieldList[id] = fieldObj;
                this.updateMembersOrder(id);
            }
            customArgs.hierarchy = this.fieldListData;
            customArgs.hierarchySuccess = this.fieldListObj.hierarchySuccess;
            this.loadHierarchyElements(customArgs);
        };
        OlapEngine.prototype.loadHierarchyElements = function (customArgs) {
            var data = customArgs.hierarchySuccess;
            var dimensionElements = customArgs.hierarchy;
            var dataFields = ej2_base_1.extend([], this.rows, null, true);
            dataFields = dataFields.concat(this.columns, this.filters);
            var reportElement = [];
            for (var _i = 0, dataFields_4 = dataFields; _i < dataFields_4.length; _i++) {
                var field = dataFields_4[_i];
                reportElement.push(field.name);
            }
            var fields = [].slice.call(data.querySelectorAll('row'));
            for (var _a = 0, fields_6 = fields; _a < fields_6.length; _a++) {
                var field = fields_6[_a];
                var dimensionName = field.querySelector('DIMENSION_UNIQUE_NAME').textContent;
                var hierarchyName = field.querySelector('HIERARCHY_UNIQUE_NAME').textContent;
                var isAllMemberAvail = [].slice.call(field.querySelectorAll('ALL_MEMBER')).length > 0;
                var allMember = void 0;
                if (isAllMemberAvail) {
                    var stringCollection = field.querySelectorAll('ALL_MEMBER')[0].textContent.replace(/[\]']+/g, '').split('.');
                    allMember = stringCollection[stringCollection.length - 1].trim();
                }
                else {
                    allMember = undefined;
                }
                var hierarchyFolderName = ((field.querySelector('HIERARCHY_DISPLAY_FOLDER')) ? (field.querySelector('HIERARCHY_DISPLAY_FOLDER').textContent) : '');
                var curElement = [];
                for (var _b = 0, dimensionElements_1 = dimensionElements; _b < dimensionElements_1.length; _b++) {
                    var item = dimensionElements_1[_b];
                    if (item.tag === dimensionName) {
                        curElement.push(item);
                    }
                }
                Eif (curElement.length > 0) {
                    var isSameDim = dimensionName === hierarchyName && dimensionName.toLowerCase() !== '[measures]' && hierarchyName.toLowerCase() !== '[measures]';
                    if (dimensionName.toLowerCase() !== '[measures]' && hierarchyName.toLowerCase() !== '[measures]') {
                        var parentID = dimensionName + ((this.isMondrian || isSameDim) ? '~#^Dim' : '');
                        if (hierarchyFolderName !== '') {
                            var folderName = dimensionName + ((this.isMondrian || isSameDim) ? '~#^Dim' : '') + '_' + hierarchyFolderName;
                            var curParentElement = [];
                            for (var _c = 0, dimensionElements_2 = dimensionElements; _c < dimensionElements_2.length; _c++) {
                                var item = dimensionElements_2[_c];
                                if (item.tag === folderName && item.pid === parentID) {
                                    curParentElement.push(item);
                                }
                            }
                            if (curParentElement.length === 0) {
                                var fieldObj_1 = {
                                    hasChildren: true,
                                    isSelected: false,
                                    pid: dimensionName + ((this.isMondrian || isSameDim) ? '~#^Dim' : ''),
                                    id: folderName,
                                    name: hierarchyFolderName,
                                    spriteCssClass: 'e-folderCDB-icon' + ' ' + cls.ICON,
                                    tag: folderName,
                                    caption: hierarchyFolderName,
                                    type: 'string'
                                };
                                dimensionElements.push(fieldObj_1);
                            }
                            parentID = folderName;
                        }
                        var fieldObj = {
                            hasChildren: (field.querySelector('HIERARCHY_ORIGIN') ? ((field.querySelector('HIERARCHY_ORIGIN').textContent !== '2') && field.querySelector('HIERARCHY_ORIGIN').textContent !== '6') ? true : false : true),
                            isSelected: (reportElement.indexOf(hierarchyName) >= 0),
                            pid: parentID,
                            id: hierarchyName,
                            name: field.querySelector('HIERARCHY_CAPTION').textContent,
                            spriteCssClass: (field.querySelector('HIERARCHY_ORIGIN') ? ((field.querySelector('HIERARCHY_ORIGIN').textContent !== '2') && field.querySelector('HIERARCHY_ORIGIN').textContent !== '6') ? 'e-hierarchyCDB-icon' : 'e-attributeCDB-icon' : 'e-hierarchyCDB-icon') + ' ' + cls.ICON,
                            hasAllMember: isAllMemberAvail,
                            allMember: allMember,
                            tag: hierarchyName,
                            caption: this.dataFields[hierarchyName] && this.dataFields[hierarchyName].caption ? this.dataFields[hierarchyName].caption : this.mappingFields[hierarchyName] && this.mappingFields[hierarchyName].caption ? this.mappingFields[hierarchyName].caption : field.querySelector('HIERARCHY_CAPTION').textContent,
                            type: 'string',
                            filter: [],
                            dateMember: [],
                            sort: (this.enableSort ? this.sortObject[hierarchyName] ? this.sortObject[hierarchyName] : 'Ascending' : 'None'),
                            actualFilter: [],
                            filterMembers: [],
                            childMembers: [],
                            searchMembers: [],
                            members: {},
                            currrentMembers: {},
                            levels: [],
                            levelCount: 1,
                            isHierarchy: (field.querySelector('HIERARCHY_ORIGIN') ? ((field.querySelector('HIERARCHY_ORIGIN').textContent !== '2') &&
                                field.querySelector('HIERARCHY_ORIGIN').textContent !== '6') ? false : true : false),
                            isExcelFilter: false,
                            allowDragAndDrop: (this.dataFields[hierarchyName] ?
                                this.dataFields[hierarchyName].allowDragAndDrop : this.mappingFields[hierarchyName] ?
                                this.mappingFields[hierarchyName].allowDragAndDrop : true),
                            showFilterIcon: (this.dataFields[hierarchyName] ?
                                this.dataFields[hierarchyName].showFilterIcon : this.mappingFields[hierarchyName] ?
                                this.mappingFields[hierarchyName].showFilterIcon : true),
                            showSortIcon: (this.dataFields[hierarchyName] ?
                                this.dataFields[hierarchyName].showSortIcon : this.mappingFields[hierarchyName] ?
                                this.mappingFields[hierarchyName].showSortIcon : true),
                            showEditIcon: (this.dataFields[hierarchyName] ?
                                this.dataFields[hierarchyName].showEditIcon : this.mappingFields[hierarchyName] ?
                                this.mappingFields[hierarchyName].showEditIcon : true),
                            showRemoveIcon: (this.dataFields[hierarchyName] ?
                                this.dataFields[hierarchyName].showRemoveIcon : this.mappingFields[hierarchyName] ?
                                this.mappingFields[hierarchyName].showRemoveIcon : true),
                            showValueTypeIcon: (this.dataFields[hierarchyName] ?
                                this.dataFields[hierarchyName].showValueTypeIcon : this.mappingFields[hierarchyName] ?
                                this.mappingFields[hierarchyName].showValueTypeIcon : true),
                            showSubTotals: (this.dataFields[hierarchyName] ? this.dataFields[hierarchyName].showSubTotals :
                                this.mappingFields[hierarchyName] ? this.mappingFields[hierarchyName].showSubTotals : true)
                        };
                        dimensionElements.push(fieldObj);
                        this.fieldList[hierarchyName] = fieldObj;
                        this.updateMembersOrder(hierarchyName);
                    }
                }
            }
            var args = {
                catalog: customArgs.dataSourceSettings.catalog,
                cube: customArgs.dataSourceSettings.cube,
                url: customArgs.dataSourceSettings.url,
                LCID: customArgs.dataSourceSettings.localeIdentifier.toString(),
                request: 'MDSCHEMA_LEVELS',
                roles: customArgs.dataSourceSettings.roles
            };
            this.getTreeData(args, this.loadLevelElements.bind(this), customArgs);
        };
        OlapEngine.prototype.updateMembersOrder = function (key) {
            for (var _i = 0, _a = this.sortSettings; _i < _a.length; _i++) {
                var sortInfo = _a[_i];
                if (key === sortInfo.name && sortInfo.membersOrder) {
                    this.fieldList[key].membersOrder = sortInfo.membersOrder;
                    break;
                }
            }
        };
        OlapEngine.prototype.loadLevelElements = function (xmlDoc, request, customArgs) {
            var newDataSource = [];
            var dimensionElements = this.fieldListData;
            newDataSource = [];
            var fields = [].slice.call(xmlDoc.querySelectorAll('row'));
            for (var _i = 0, fields_7 = fields; _i < fields_7.length; _i++) {
                var field = fields_7[_i];
                if (parseInt(field.querySelector('LEVEL_TYPE').textContent, 10) !== 1 && field.querySelector('HIERARCHY_UNIQUE_NAME').textContent.toLowerCase() !== '[measures]') {
                    var dimensionName = field.querySelector('HIERARCHY_UNIQUE_NAME').textContent;
                    var levelName = field.querySelector('LEVEL_UNIQUE_NAME').textContent;
                    var levelCaption = field.querySelector('LEVEL_CAPTION').textContent;
                    var levelObj = {
                        hasChildren: false,
                        isChecked: false,
                        isSelected: this.fieldList[dimensionName].isSelected,
                        pid: dimensionName,
                        id: levelName,
                        name: levelCaption,
                        tag: levelName,
                        spriteCssClass: 'e-level-members e-hierarchy-level-' + parseInt(field.querySelector('LEVEL_NUMBER').textContent, 10) + '-icon' + ' ' + cls.ICON,
                        caption: levelCaption,
                        type: 'string'
                    };
                    newDataSource.push(levelObj);
                    if (this.fieldList[dimensionName] && this.fieldList[dimensionName].spriteCssClass &&
                        this.fieldList[dimensionName].spriteCssClass.indexOf('e-attributeCDB-icon') === -1) {
                        this.fieldList[dimensionName].levels.push(levelObj);
                        this.fieldList[dimensionName].isHierarchy = false;
                    }
                    else {
                        this.fieldList[dimensionName].isHierarchy = true;
                    }
                }
            }
            this.fieldListData = dimensionElements = dimensionElements.concat(newDataSource);
            var args = {
                catalog: customArgs.dataSourceSettings.catalog,
                cube: customArgs.dataSourceSettings.cube,
                url: customArgs.dataSourceSettings.url,
                LCID: customArgs.dataSourceSettings.localeIdentifier.toString(),
                request: 'MDSCHEMA_MEASURES',
                roles: customArgs.dataSourceSettings.roles
            };
            this.getTreeData(args, this.loadMeasureElements.bind(this), customArgs);
        };
        OlapEngine.prototype.loadMeasureElements = function (xmlDoc, request, customArgs) {
            var dimensionElements = this.fieldListData;
            var measureGroupItems = [];
            var caption;
            var dataFields = ej2_base_1.extend([], this.values, null, true);
            var reportElement = [];
            for (var _i = 0, dataFields_5 = dataFields; _i < dataFields_5.length; _i++) {
                var field = dataFields_5[_i];
                reportElement.push(field.name);
            }
            Iif (this.locale !== 'en-US') {
                var args = {
                    catalog: customArgs.dataSourceSettings.catalog,
                    cube: customArgs.dataSourceSettings.cube,
                    url: customArgs.dataSourceSettings.url,
                    LCID: customArgs.dataSourceSettings.localeIdentifier.toString(),
                    request: 'MDSCHEMA_MEASUREGROUPS',
                    roles: customArgs.dataSourceSettings.roles
                };
                this.getTreeData(args, this.loadMeasureGroups.bind(this), customArgs);
            }
            var fields = [].slice.call(xmlDoc.querySelectorAll('row'));
            for (var _a = 0, fields_8 = fields; _a < fields_8.length; _a++) {
                var field = fields_8[_a];
                var measureGRPName = ej2_base_1.isNullOrUndefined(field.querySelector('MEASUREGROUP_NAME')) ? '' : field.querySelector('MEASUREGROUP_NAME').textContent;
                var measureName = field.querySelector('MEASURE_UNIQUE_NAME').textContent;
                var formatString = field.querySelector('DEFAULT_FORMAT_STRING') ?
                    field.querySelector('DEFAULT_FORMAT_STRING').textContent : '#,#';
                var aggregateType = field.querySelector('MEASURE_AGGREGATOR') ?
                    field.querySelector('MEASURE_AGGREGATOR').textContent : '1';
                if (!(measureGroupItems.indexOf(measureGRPName) >= 0)) {
                    Iif (this.locale !== 'en-US') {
                        var measureInfo = [];
                        for (var _b = 0, _c = this.fieldListObj.measuresGroups; _b < _c.length; _b++) {
                            var item = _c[_b];
                            if (item.querySelector('MEASUREGROUP_NAME').textContent === measureGRPName) {
                                measureInfo.push(item);
                            }
                        }
                        caption = measureInfo.length > 0 ? measureInfo[0].querySelector('MEASUREGROUP_CAPTION').textContent : measureGRPName;
                    }
                    else {
                        caption = measureGRPName;
                    }
                    Eif (measureGRPName !== '') {
                        dimensionElements.push({
                            hasChildren: true,
                            isChecked: false,
                            isSelected: false,
                            pid: '[Measures]',
                            id: measureGRPName,
                            name: caption,
                            spriteCssClass: 'e-measureCDB e-folderCDB-icon' + ' ' + cls.ICON,
                            tag: measureGRPName,
                            caption: caption,
                            aggregateType: this.getAggregateType(measureGRPName, aggregateType),
                            type: 'string'
                        });
                        measureGroupItems.push(measureGRPName);
                    }
                }
                var fieldObj = {
                    hasChildren: false,
                    isSelected: (reportElement.indexOf(measureName) >= 0),
                    pid: measureGRPName === '' ? '[Measures]' : measureGRPName,
                    id: measureName,
                    name: field.querySelector('MEASURE_CAPTION').textContent,
                    spriteCssClass: 'e-measure-icon' + ' ' + cls.ICON,
                    tag: measureName,
                    caption: this.dataFields[measureName] && this.dataFields[measureName].caption ?
                        this.dataFields[measureName].caption : this.mappingFields[measureName] &&
                        this.mappingFields[measureName].caption ? this.mappingFields[measureName].caption :
                        field.querySelector('MEASURE_CAPTION').textContent,
                    aggregateType: this.getAggregateType(measureName, aggregateType),
                    type: 'number',
                    filter: [],
                    actualFilter: [],
                    filterMembers: [],
                    childMembers: [],
                    searchMembers: [],
                    members: {},
                    currrentMembers: {},
                    formatString: formatString,
                    allowDragAndDrop: (this.dataFields[measureName] ? this.dataFields[measureName].allowDragAndDrop :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].allowDragAndDrop : true),
                    showFilterIcon: (this.dataFields[measureName] ? this.dataFields[measureName].showFilterIcon :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].showFilterIcon : true),
                    showSortIcon: (this.dataFields[measureName] ? this.dataFields[measureName].showSortIcon :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].showSortIcon : true),
                    showEditIcon: (this.dataFields[measureName] ? this.dataFields[measureName].showEditIcon :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].showEditIcon : true),
                    showRemoveIcon: (this.dataFields[measureName] ? this.dataFields[measureName].showRemoveIcon :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].showRemoveIcon : true),
                    showValueTypeIcon: (this.dataFields[measureName] ? this.dataFields[measureName].showValueTypeIcon :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].showValueTypeIcon : true),
                    showSubTotals: (this.dataFields[measureName] ? this.dataFields[measureName].showSubTotals :
                        this.mappingFields[measureName] ? this.mappingFields[measureName].showSubTotals : true)
                };
                dimensionElements.push(fieldObj);
                this.fieldList[measureName] = fieldObj;
                if ((reportElement.indexOf(measureName) >= 0)) {
                    reportElement.splice(reportElement.indexOf(measureName), 1);
                }
            }
            this.measureReportItems = reportElement;
        };
        OlapEngine.prototype.loadMeasureGroups = function (xmlDoc) {
            if (ej2_base_1.isNullOrUndefined(this.fieldListObj)) {
                this.fieldListObj = {};
            }
            this.fieldListObj.measuresGroups = [].slice.call(xmlDoc.querySelectorAll('row'));
        };
        OlapEngine.prototype.doAjaxPost = function (type, url, data, success, customArgs) {
            var _this = this;
            var ajax = new ej2_base_1.Ajax({
                mode: false,
                contentType: 'text/xml',
                url: url,
                data: data,
                dataType: 'xml',
                type: type,
                beforeSend: this.beforeSend.bind(this),
                onSuccess: function (args, request) {
                    var parser = new DOMParser();
                    var xmlDoc = parser.parseFromString(args, 'text/xml');
                    var body = xmlDoc.querySelector('Body');
                    if (!body.querySelector('OlapInfo')) {
                        Iif (!body.querySelector('DiscoverResponse')) {
                            if (body.querySelector('Fault')) {
                                _this.errorInfo = body.querySelector('Fault').querySelector('faultstring').innerHTML;
                            }
                            else {
                                _this.errorInfo = body.querySelector('return').querySelector('Error').getAttribute('Description');
                            }
                        }
                    }
                    success(xmlDoc, request, customArgs);
                },
                onFailure: function (e) {
                    _this.errorInfo = e;
                }
            });
            ajax.send();
        };
        OlapEngine.prototype.beforeSend = function (args) {
            Iif (this.dataSourceSettings.authentication.userName && this.dataSourceSettings.authentication.password) {
                args.httpRequest.setRequestHeader('Authorization', 'Basic ' + btoa(this.dataSourceSettings.authentication.userName +
                    ':' + this.dataSourceSettings.authentication.password));
            }
        };
        OlapEngine.prototype.getSoapMsg = function (dataSourceSettings, query) {
            var xmlMsg = '';
            var sourceInfo = '';
            var connectionString = this.getConnectionInfo(dataSourceSettings.url, dataSourceSettings.localeIdentifier);
            Iif (this.isMondrian) {
                sourceInfo = '';
                xmlMsg = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><Execute xmlns="urn:schemas-microsoft-com:xml-analysis"><Command><Statement><![CDATA[' +
                    query + ']]></Statement></Command><Properties><PropertyList><DataSourceInfo>' + sourceInfo +
                    '</DataSourceInfo><Catalog>' + dataSourceSettings.catalog + '</Catalog><AxisFormat>TupleFormat</AxisFormat><Content>Data</Content><Format>Multidimensional</Format></PropertyList></Properties></Execute></SOAP-ENV:Body></SOAP-ENV:Envelope>';
            }
            else {
                xmlMsg = '<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Header></Header> <Body> <Execute xmlns="urn:schemas-microsoft-com:xml-analysis"> <Command> <Statement> ' +
                    query + ' </Statement> </Command> <Properties> <PropertyList> <Catalog>' + dataSourceSettings.catalog +
                    '</Catalog> <LocaleIdentifier>' + connectionString.LCID + '</LocaleIdentifier>' + (dataSourceSettings.roles ? '<Roles>' + dataSourceSettings.roles + '</Roles>' : '') + '</PropertyList> </Properties> </Execute> </Body> </Envelope>';
            }
            return xmlMsg;
        };
        OlapEngine.prototype.getConnectionInfo = function (connectionString, locale) {
            var connectionInfo = { url: '', LCID: !ej2_base_1.isNullOrUndefined(locale) ? locale.toString() : '1033' };
            Eif (connectionString !== '') {
                for (var _i = 0, _a = connectionString.split(';'); _i < _a.length; _i++) {
                    var obj = _a[_i];
                    Eif (obj.toLowerCase().indexOf('locale') < 0 && connectionInfo.url.length === 0) {
                        connectionInfo.url = obj;
                    }
                    else if (obj.toLowerCase().indexOf('locale') >= 0) {
                        connectionInfo.LCID = obj.replace(/ /g, '').split('=')[1];
                    }
                }
            }
            return connectionInfo;
        };
        OlapEngine.prototype.getMDXQuery = function (dataSourceSettings) {
            mdx_query_1.MDXQuery.getCellSets(dataSourceSettings, this, true, undefined, true);
            return this.mdxQuery;
        };
        return OlapEngine;
    }());
    exports.OlapEngine = OlapEngine;
});