grid.js
172 KB
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
/***********************************************
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 04/22/2014 16:27
***********************************************/
(function(window, $) {
'use strict';
// the # of rows we want to add to the top and bottom of the rendered grid rows
var EXCESS_ROWS = 6;
var SCROLL_THRESHOLD = 4;
var ASC = "asc";
// constant for sorting direction
var DESC = "desc";
// constant for sorting direction
var NG_FIELD = '_ng_field_';
var NG_DEPTH = '_ng_depth_';
var NG_HIDDEN = '_ng_hidden_';
var NG_COLUMN = '_ng_column_';
var CUSTOM_FILTERS = /CUSTOM_FILTERS/g;
var COL_FIELD = /COL_FIELD/g;
var DISPLAY_CELL_TEMPLATE = /DISPLAY_CELL_TEMPLATE/g;
var EDITABLE_CELL_TEMPLATE = /EDITABLE_CELL_TEMPLATE/g;
var CELL_EDITABLE_CONDITION = /CELL_EDITABLE_CONDITION/g;
var TEMPLATE_REGEXP = /<.+>/;
window.ngGrid = {};
window.ngGrid.i18n = {};
// Declare app level module which depends on filters, and services
var ngGridServices = angular.module('ngGrid.services', []);
var ngGridDirectives = angular.module('ngGrid.directives', []);
var ngGridFilters = angular.module('ngGrid.filters', []);
// initialization of services into the main module
angular.module('ngGrid', ['ngGrid.services', 'ngGrid.directives', 'ngGrid.filters']);
//set event binding on the grid so we can select using the up/down keys
var ngMoveSelectionHandler = function($scope, elm, evt, grid) {
if ($scope.selectionProvider.selectedItems === undefined) {
return true;
}
var charCode = evt.which || evt.keyCode,
newColumnIndex,
lastInRow = false,
firstInRow = false,
rowIndex = $scope.selectionProvider.lastClickedRow === undefined ? 1 : $scope.selectionProvider.lastClickedRow.rowIndex,
visibleCols = $scope.columns.filter(function(c) { return c.visible; }),
pinnedCols = $scope.columns.filter(function(c) { return c.pinned; });
if ($scope.col) {
newColumnIndex = visibleCols.indexOf($scope.col);
}
if (charCode !== 37 && charCode !== 38 && charCode !== 39 && charCode !== 40 && (grid.config.noTabInterference || charCode !== 9) && charCode !== 13) {
return true;
}
if ($scope.enableCellSelection) {
if (charCode === 9) { //tab key
evt.preventDefault();
}
var focusedOnFirstColumn = $scope.showSelectionCheckbox ? $scope.col.index === 1 : $scope.col.index === 0;
var focusedOnFirstVisibleColumns = $scope.$index === 1 || $scope.$index === 0;
var focusedOnLastVisibleColumns = $scope.$index === ($scope.renderedColumns.length - 1) || $scope.$index === ($scope.renderedColumns.length - 2);
var focusedOnLastColumn = visibleCols.indexOf($scope.col) === (visibleCols.length - 1);
var focusedOnLastPinnedColumn = pinnedCols.indexOf($scope.col) === (pinnedCols.length - 1);
if (charCode === 37 || charCode === 9 && evt.shiftKey) {
var scrollTo = 0;
if (!focusedOnFirstColumn) {
newColumnIndex -= 1;
}
if (focusedOnFirstVisibleColumns) {
if (focusedOnFirstColumn && charCode === 9 && evt.shiftKey){
scrollTo = grid.$canvas.width();
newColumnIndex = visibleCols.length - 1;
firstInRow = true;
}
else {
scrollTo = grid.$viewport.scrollLeft() - $scope.col.width;
}
}
else if (pinnedCols.length > 0) {
scrollTo = grid.$viewport.scrollLeft() - visibleCols[newColumnIndex].width;
}
grid.$viewport.scrollLeft(scrollTo);
}
else if (charCode === 39 || charCode === 9 && !evt.shiftKey) {
if (focusedOnLastVisibleColumns) {
if (focusedOnLastColumn && charCode === 9 && !evt.shiftKey) {
grid.$viewport.scrollLeft(0);
newColumnIndex = $scope.showSelectionCheckbox ? 1 : 0;
lastInRow = true;
}
else {
grid.$viewport.scrollLeft(grid.$viewport.scrollLeft() + $scope.col.width);
}
}
else if (focusedOnLastPinnedColumn) {
grid.$viewport.scrollLeft(0);
}
if (!focusedOnLastColumn) {
newColumnIndex += 1;
}
}
}
var items;
if ($scope.configGroups.length > 0) {
items = grid.rowFactory.parsedData.filter(function (row) {
return !row.isAggRow;
});
}
else {
items = grid.filteredRows;
}
var offset = 0;
if (rowIndex !== 0 && (charCode === 38 || charCode === 13 && evt.shiftKey || charCode === 9 && evt.shiftKey && firstInRow)) { //arrow key up or shift enter or tab key and first item in row
offset = -1;
}
else if (rowIndex !== items.length - 1 && (charCode === 40 || charCode === 13 && !evt.shiftKey || charCode === 9 && lastInRow)) {//arrow key down, enter, or tab key and last item in row?
offset = 1;
}
if (offset) {
var r = items[rowIndex + offset];
if (r.beforeSelectionChange(r, evt)) {
r.continueSelection(evt);
$scope.$emit('ngGridEventDigestGridParent');
if ($scope.selectionProvider.lastClickedRow.renderedRowIndex >= $scope.renderedRows.length - EXCESS_ROWS - 2) {
grid.$viewport.scrollTop(grid.$viewport.scrollTop() + $scope.rowHeight);
}
else if ($scope.selectionProvider.lastClickedRow.renderedRowIndex <= EXCESS_ROWS + 2) {
grid.$viewport.scrollTop(grid.$viewport.scrollTop() - $scope.rowHeight);
}
}
}
if ($scope.enableCellSelection) {
setTimeout(function(){
$scope.domAccessProvider.focusCellElement($scope, $scope.renderedColumns.indexOf(visibleCols[newColumnIndex]));
}, 3);
}
return false;
};
if (!String.prototype.trim) {
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, '');
};
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/) {
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0) {
from += len;
}
for (; from < len; from++) {
if (from in this && this[from] === elt) {
return from;
}
}
return -1;
};
}
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp */) {
"use strict";
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var res = [];
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
var val = t[i]; // in case fun mutates this
if (fun.call(thisp, val, i, t)) {
res.push(val);
}
}
}
return res;
};
}
ngGridFilters.filter('checkmark', function() {
return function(input) {
return input ? '\u2714' : '\u2718';
};
});
ngGridFilters.filter('ngColumns', function() {
return function(input) {
return input.filter(function(col) {
return !col.isAggCol;
});
};
});
angular.module('ngGrid.services').factory('$domUtilityService',['$utilityService', '$window', function($utils, $window) {
var domUtilityService = {};
var regexCache = {};
var getWidths = function() {
var $testContainer = $('<div></div>');
$testContainer.appendTo('body');
// 1. Run all the following measurements on startup!
//measure Scroll Bars
$testContainer.height(100).width(100).css("position", "absolute").css("overflow", "scroll");
$testContainer.append('<div style="height: 400px; width: 400px;"></div>');
domUtilityService.ScrollH = ($testContainer.height() - $testContainer[0].clientHeight);
domUtilityService.ScrollW = ($testContainer.width() - $testContainer[0].clientWidth);
$testContainer.empty();
//clear styles
$testContainer.attr('style', '');
//measure letter sizes using a pretty typical font size and fat font-family
$testContainer.append('<span style="font-family: Verdana, Helvetica, Sans-Serif; font-size: 14px;"><strong>M</strong></span>');
domUtilityService.LetterW = $testContainer.children().first().width();
$testContainer.remove();
};
domUtilityService.eventStorage = {};
domUtilityService.AssignGridContainers = function($scope, rootEl, grid) {
grid.$root = $(rootEl);
//Headers
grid.$topPanel = grid.$root.find(".ngTopPanel");
grid.$groupPanel = grid.$root.find(".ngGroupPanel");
grid.$headerContainer = grid.$topPanel.find(".ngHeaderContainer");
$scope.$headerContainer = grid.$headerContainer;
grid.$headerScroller = grid.$topPanel.find(".ngHeaderScroller");
grid.$headers = grid.$headerScroller.children();
//Viewport
grid.$viewport = grid.$root.find(".ngViewport");
//Canvas
grid.$canvas = grid.$viewport.find(".ngCanvas");
//Footers
grid.$footerPanel = grid.$root.find(".ngFooterPanel");
var scopeDereg = $scope.$watch(function () {
return grid.$viewport.scrollLeft();
}, function (newLeft) {
return grid.$headerContainer.scrollLeft(newLeft);
});
$scope.$on('$destroy', function() {
// Remove all references to DOM elements, otherwise we get memory leaks
$(grid.$root.parent()).off('resize.nggrid');
grid.$root = null;
grid.$topPanel = null;
// grid.$groupPanel = null;
grid.$headerContainer = null;
// grid.$headerScroller = null;
grid.$headers = null;
grid.$canvas = null;
grid.$footerPanel = null;
scopeDereg();
});
domUtilityService.UpdateGridLayout($scope, grid);
};
domUtilityService.getRealWidth = function (obj) {
var width = 0;
var props = { visibility: "hidden", display: "block" };
var hiddenParents = obj.parents().andSelf().not(':visible');
$.swap(hiddenParents[0], props, function () {
width = obj.outerWidth();
});
return width;
};
domUtilityService.UpdateGridLayout = function($scope, grid) {
//catch this so we can return the viewer to their original scroll after the resize!
var scrollTop = grid.$viewport.scrollTop();
grid.elementDims.rootMaxW = grid.$root.width();
if (grid.$root.is(':hidden')) {
grid.elementDims.rootMaxW = domUtilityService.getRealWidth(grid.$root);
}
grid.elementDims.rootMaxH = grid.$root.height();
//check to see if anything has changed
grid.refreshDomSizes();
$scope.adjustScrollTop(scrollTop, true); //ensure that the user stays scrolled where they were
};
domUtilityService.numberOfGrids = 0;
domUtilityService.setStyleText = function(grid, css) {
var style = grid.styleSheet,
gridId = grid.gridId,
doc = $window.document;
if (!style) {
style = doc.getElementById(gridId);
}
if (!style) {
style = doc.createElement('style');
style.type = 'text/css';
style.id = gridId;
(doc.head || doc.getElementsByTagName('head')[0]).appendChild(style);
}
if (style.styleSheet && !style.sheet) {
style.styleSheet.cssText = css;
} else {
style.innerHTML = css;
}
grid.styleSheet = style;
grid.styleText = css;
};
domUtilityService.BuildStyles = function($scope, grid, digest) {
var rowHeight = grid.config.rowHeight,
gridId = grid.gridId,
css,
cols = $scope.columns,
sumWidth = 0;
var trw = $scope.totalRowWidth();
css = "." + gridId + " .ngCanvas { width: " + trw + "px; }" +
"." + gridId + " .ngRow { width: " + trw + "px; }" +
"." + gridId + " .ngCanvas { width: " + trw + "px; }" +
"." + gridId + " .ngHeaderScroller { width: " + (trw + domUtilityService.ScrollH) + "px}";
for (var i = 0; i < cols.length; i++) {
var col = cols[i];
if (col.visible !== false) {
css += "." + gridId + " .col" + i + " { width: " + col.width + "px; left: " + sumWidth + "px; height: " + rowHeight + "px }" +
"." + gridId + " .colt" + i + " { width: " + col.width + "px; }";
sumWidth += col.width;
}
}
domUtilityService.setStyleText(grid, css);
$scope.adjustScrollLeft(grid.$viewport.scrollLeft());
if (digest) {
domUtilityService.digest($scope);
}
};
domUtilityService.setColLeft = function(col, colLeft, grid) {
if (grid.styleText) {
var regex = regexCache[col.index];
if (!regex) {
regex = regexCache[col.index] = new RegExp(".col" + col.index + " { width: [0-9]+px; left: [0-9]+px");
}
var css = grid.styleText.replace(regex, ".col" + col.index + " { width: " + col.width + "px; left: " + colLeft + "px");
domUtilityService.setStyleText(grid, css);
}
};
domUtilityService.setColLeft.immediate = 1;
domUtilityService.RebuildGrid = function($scope, grid){
domUtilityService.UpdateGridLayout($scope, grid);
if (grid.config.maintainColumnRatios == null || grid.config.maintainColumnRatios) {
grid.configureColumnWidths();
}
$scope.adjustScrollLeft(grid.$viewport.scrollLeft());
domUtilityService.BuildStyles($scope, grid, true);
};
domUtilityService.digest = function($scope) {
if (!$scope.$root.$$phase) {
$scope.$digest();
}
};
domUtilityService.ScrollH = 17; // default in IE, Chrome, & most browsers
domUtilityService.ScrollW = 17; // default in IE, Chrome, & most browsers
domUtilityService.LetterW = 10;
getWidths();
return domUtilityService;
}]);
angular.module('ngGrid.services').factory('$sortService', ['$parse', function($parse) {
var sortService = {};
sortService.colSortFnCache = {}; // cache of sorting functions. Once we create them, we don't want to keep re-doing it
sortService.isCustomSort = false; // track if we're using an internal sort or a user provided sort
// this takes an piece of data from the cell and tries to determine its type and what sorting
// function to use for it
// @item - the cell data
sortService.guessSortFn = function(item) {
var itemType = typeof(item);
//check for numbers and booleans
switch (itemType) {
case "number":
return sortService.sortNumber;
case "boolean":
return sortService.sortBool;
case "string":
// if number string return number string sort fn. else return the str
return item.match(/^[-+]?[£$¤]?[\d,.]+%?$/) ? sortService.sortNumberStr : sortService.sortAlpha;
default:
//check if the item is a valid Date
if (Object.prototype.toString.call(item) === '[object Date]') {
return sortService.sortDate;
}
else {
//finally just sort the basic sort...
return sortService.basicSort;
}
}
};
//#region Sorting Functions
sortService.basicSort = function(a, b) {
if (a === b) {
return 0;
}
if (a < b) {
return -1;
}
return 1;
};
sortService.sortNumber = function(a, b) {
return a - b;
};
sortService.sortNumberStr = function(a, b) {
var numA, numB, badA = false, badB = false;
numA = parseFloat(a.replace(/[^0-9.-]/g, ''));
if (isNaN(numA)) {
badA = true;
}
numB = parseFloat(b.replace(/[^0-9.-]/g, ''));
if (isNaN(numB)) {
badB = true;
}
// we want bad ones to get pushed to the bottom... which effectively is "greater than"
if (badA && badB) {
return 0;
}
if (badA) {
return 1;
}
if (badB) {
return -1;
}
return numA - numB;
};
sortService.sortAlpha = function(a, b) {
var strA = a.toLowerCase(),
strB = b.toLowerCase();
return strA === strB ? 0 : (strA < strB ? -1 : 1);
};
sortService.sortDate = function(a, b) {
var timeA = a.getTime(),
timeB = b.getTime();
return timeA === timeB ? 0 : (timeA < timeB ? -1 : 1);
};
sortService.sortBool = function(a, b) {
if (a && b) {
return 0;
}
if (!a && !b) {
return 0;
} else {
return a ? 1 : -1;
}
};
//#endregion
// the core sorting logic trigger
sortService.sortData = function(sortInfo, data /*datasource*/) {
// first make sure we are even supposed to do work
if (!data || !sortInfo) {
return;
}
var l = sortInfo.fields.length,
order = sortInfo.fields,
col,
direction,
// IE9 HACK.... omg, I can't reference data array within the sort fn below. has to be a separate reference....!!!!
d = data.slice(0);
//now actually sort the data
data.sort(function (itemA, itemB) {
var tem = 0,
indx = 0,
res,
sortFn;
while (tem === 0 && indx < l) {
// grab the metadata for the rest of the logic
col = sortInfo.columns[indx];
direction = sortInfo.directions[indx];
sortFn = sortService.getSortFn(col, d);
var propA = $parse(order[indx])(itemA);
var propB = $parse(order[indx])(itemB);
// if user provides custom sort, we want them to have full control of the sort
if (sortService.isCustomSort) {
res = sortFn(propA, propB);
tem = direction === ASC ? res : 0 - res;
} else {
// we want to allow zero values to be evaluated in the sort function
if ((!propA && propA !== 0) || (!propB && propB !== 0)) {
// we want to force nulls and such to the bottom when we sort... which effectively is "greater than"
if (!propB && !propA) {
tem = 0;
}
else if (!propA) {
tem = 1;
}
else if (!propB) {
tem = -1;
}
}
else {
// this will keep nulls at the bottom regardless of ordering
res = sortFn(propA, propB);
tem = direction === ASC ? res : 0 - res;
}
}
indx++;
}
return tem;
});
};
sortService.Sort = function(sortInfo, data) {
if (sortService.isSorting) {
return;
}
sortService.isSorting = true;
sortService.sortData(sortInfo, data);
sortService.isSorting = false;
};
sortService.getSortFn = function(col, data) {
var sortFn, item;
//see if we already figured out what to use to sort the column
if (sortService.colSortFnCache[col.field]) {
sortFn = sortService.colSortFnCache[col.field];
}
else if (col.sortingAlgorithm !== undefined) {
sortFn = col.sortingAlgorithm;
sortService.colSortFnCache[col.field] = col.sortingAlgorithm;
sortService.isCustomSort = true;
}
else { // try and guess what sort function to use
item = data[0];
if (!item) {
return sortFn;
}
sortFn = sortService.guessSortFn($parse(col.field)(item));
//cache it
if (sortFn) {
sortService.colSortFnCache[col.field] = sortFn;
} else {
// we assign the alpha sort because anything that is null/undefined will never get passed to
// the actual sorting function. It will get caught in our null check and returned to be sorted
// down to the bottom
sortFn = sortService.sortAlpha;
}
}
return sortFn;
};
return sortService;
}]);
angular.module('ngGrid.services').factory('$utilityService', ['$parse', function ($parse) {
var funcNameRegex = /function (.{1,})\(/;
var utils = {
visualLength: function(node) {
var elem = document.getElementById('testDataLength');
if (!elem) {
elem = document.createElement('SPAN');
elem.id = "testDataLength";
elem.style.visibility = "hidden";
document.body.appendChild(elem);
}
var $node = $(node);
$(elem).css({'font': $node.css('font'),
'font-size': $node.css('font-size'),
'font-family': $node.css('font-family')});
elem.innerHTML = $node.text();
var width = elem.offsetWidth;
document.body.removeChild(elem);
return width;
},
forIn: function(obj, action) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
action(obj[prop], prop);
}
}
},
evalProperty: function (entity, path) {
return $parse("entity." + path)({ entity: entity });
},
endsWith: function(str, suffix) {
if (!str || !suffix || typeof str !== "string") {
return false;
}
return str.indexOf(suffix, str.length - suffix.length) !== -1;
},
isNullOrUndefined: function(obj) {
if (obj === undefined || obj === null) {
return true;
}
return false;
},
getElementsByClassName: function(cl) {
if (document.getElementsByClassName) {
return document.getElementsByClassName(cl);
}
else {
var retnode = [];
var myclass = new RegExp('\\b' + cl + '\\b');
var elem = document.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) {
retnode.push(elem[i]);
}
}
return retnode;
}
},
newId: (function() {
var seedId = new Date().getTime();
return function() {
return seedId += 1;
};
})(),
seti18n: function($scope, language) {
var $langPack = window.ngGrid.i18n[language];
for (var label in $langPack) {
$scope.i18n[label] = $langPack[label];
}
},
getInstanceType: function (o) {
var results = (funcNameRegex).exec(o.constructor.toString());
if (results && results.length > 1) {
var instanceType = results[1].replace(/^\s+|\s+$/g, ""); // Trim surrounding whitespace; IE appears to add a space at the end
return instanceType;
}
else {
return "";
}
}
};
return utils;
}]);
var ngAggregate = function (aggEntity, rowFactory, rowHeight, groupInitState) {
this.rowIndex = 0;
this.offsetTop = this.rowIndex * rowHeight;
this.entity = aggEntity;
this.label = aggEntity.gLabel;
this.field = aggEntity.gField;
this.depth = aggEntity.gDepth;
this.parent = aggEntity.parent;
this.children = aggEntity.children;
this.aggChildren = aggEntity.aggChildren;
this.aggIndex = aggEntity.aggIndex;
this.collapsed = groupInitState;
this.groupInitState = groupInitState;
this.rowFactory = rowFactory;
this.rowHeight = rowHeight;
this.isAggRow = true;
this.offsetLeft = aggEntity.gDepth * 25;
this.aggLabelFilter = aggEntity.aggLabelFilter;
};
ngAggregate.prototype.toggleExpand = function () {
this.collapsed = this.collapsed ? false : true;
if (this.orig) {
this.orig.collapsed = this.collapsed;
}
this.notifyChildren();
};
ngAggregate.prototype.setExpand = function (state) {
this.collapsed = state;
this.notifyChildren();
};
ngAggregate.prototype.notifyChildren = function () {
var longest = Math.max(this.rowFactory.aggCache.length, this.children.length);
for (var i = 0; i < longest; i++) {
if (this.aggChildren[i]) {
this.aggChildren[i].entity[NG_HIDDEN] = this.collapsed;
if (this.collapsed) {
this.aggChildren[i].setExpand(this.collapsed);
}
}
if (this.children[i]) {
this.children[i][NG_HIDDEN] = this.collapsed;
}
if (i > this.aggIndex && this.rowFactory.aggCache[i]) {
var agg = this.rowFactory.aggCache[i];
var offset = (30 * this.children.length);
agg.offsetTop = this.collapsed ? agg.offsetTop - offset : agg.offsetTop + offset;
}
}
this.rowFactory.renderedChange();
};
ngAggregate.prototype.aggClass = function () {
return this.collapsed ? "ngAggArrowCollapsed" : "ngAggArrowExpanded";
};
ngAggregate.prototype.totalChildren = function () {
if (this.aggChildren.length > 0) {
var i = 0;
var recurse = function (cur) {
if (cur.aggChildren.length > 0) {
angular.forEach(cur.aggChildren, function (a) {
recurse(a);
});
} else {
i += cur.children.length;
}
};
recurse(this);
return i;
} else {
return this.children.length;
}
};
ngAggregate.prototype.copy = function () {
var ret = new ngAggregate(this.entity, this.rowFactory, this.rowHeight, this.groupInitState);
ret.orig = this;
return ret;
};
var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache, $utils) {
var self = this,
colDef = config.colDef,
delay = 500,
clicks = 0,
timer = null;
self.colDef = config.colDef;
self.width = colDef.width;
self.groupIndex = 0;
self.isGroupedBy = false;
self.minWidth = !colDef.minWidth ? 50 : colDef.minWidth;
self.maxWidth = !colDef.maxWidth ? 9000 : colDef.maxWidth;
// TODO: Use the column's definition for enabling cell editing
// self.enableCellEdit = config.enableCellEdit || colDef.enableCellEdit;
self.enableCellEdit = colDef.enableCellEdit !== undefined ? colDef.enableCellEdit : (config.enableCellEdit || config.enableCellEditOnFocus);
self.cellEditableCondition = colDef.cellEditableCondition || config.cellEditableCondition || 'true';
self.headerRowHeight = config.headerRowHeight;
// Use colDef.displayName as long as it's not undefined, otherwise default to the field name
self.displayName = (colDef.displayName === undefined) ? colDef.field : colDef.displayName;
self.index = config.index;
self.isAggCol = config.isAggCol;
self.cellClass = colDef.cellClass;
self.sortPriority = undefined;
self.cellFilter = colDef.cellFilter ? colDef.cellFilter : "";
self.field = colDef.field;
self.aggLabelFilter = colDef.aggLabelFilter || colDef.cellFilter;
self.visible = $utils.isNullOrUndefined(colDef.visible) || colDef.visible;
self.sortable = false;
self.resizable = false;
self.pinnable = false;
self.pinned = (config.enablePinning && colDef.pinned);
self.originalIndex = config.originalIndex == null ? self.index : config.originalIndex;
self.groupable = $utils.isNullOrUndefined(colDef.groupable) || colDef.groupable;
if (config.enableSort) {
self.sortable = $utils.isNullOrUndefined(colDef.sortable) || colDef.sortable;
}
if (config.enableResize) {
self.resizable = $utils.isNullOrUndefined(colDef.resizable) || colDef.resizable;
}
if (config.enablePinning) {
self.pinnable = $utils.isNullOrUndefined(colDef.pinnable) || colDef.pinnable;
}
self.sortDirection = undefined;
self.sortingAlgorithm = colDef.sortFn;
self.headerClass = colDef.headerClass;
self.cursor = self.sortable ? 'pointer' : 'default';
self.headerCellTemplate = colDef.headerCellTemplate || $templateCache.get('headerCellTemplate.html');
self.cellTemplate = colDef.cellTemplate || $templateCache.get('cellTemplate.html').replace(CUSTOM_FILTERS, self.cellFilter ? "|" + self.cellFilter : "");
if(self.enableCellEdit) {
self.cellEditTemplate = colDef.cellEditTemplate || $templateCache.get('cellEditTemplate.html');
self.editableCellTemplate = colDef.editableCellTemplate || $templateCache.get('editableCellTemplate.html');
}
if (colDef.cellTemplate && !TEMPLATE_REGEXP.test(colDef.cellTemplate)) {
self.cellTemplate = $templateCache.get(colDef.cellTemplate) || $.ajax({
type: "GET",
url: colDef.cellTemplate,
async: false
}).responseText;
}
if (self.enableCellEdit && colDef.editableCellTemplate && !TEMPLATE_REGEXP.test(colDef.editableCellTemplate)) {
self.editableCellTemplate = $templateCache.get(colDef.editableCellTemplate) || $.ajax({
type: "GET",
url: colDef.editableCellTemplate,
async: false
}).responseText;
}
if (colDef.headerCellTemplate && !TEMPLATE_REGEXP.test(colDef.headerCellTemplate)) {
self.headerCellTemplate = $templateCache.get(colDef.headerCellTemplate) || $.ajax({
type: "GET",
url: colDef.headerCellTemplate,
async: false
}).responseText;
}
self.colIndex = function () {
var classes = self.pinned ? "pinned " : "";
classes += "col" + self.index + " colt" + self.index;
if (self.cellClass) {
classes += " " + self.cellClass;
}
return classes;
};
self.groupedByClass = function() {
return self.isGroupedBy ? "ngGroupedByIcon" : "ngGroupIcon";
};
self.toggleVisible = function() {
self.visible = !self.visible;
};
self.showSortButtonUp = function() {
return self.sortable ? self.sortDirection === DESC : self.sortable;
};
self.showSortButtonDown = function() {
return self.sortable ? self.sortDirection === ASC : self.sortable;
};
self.noSortVisible = function() {
return !self.sortDirection;
};
self.sort = function(evt) {
if (!self.sortable) {
return true; // column sorting is disabled, do nothing
}
var dir = self.sortDirection === ASC ? DESC : ASC;
self.sortDirection = dir;
config.sortCallback(self, evt);
return false;
};
self.gripClick = function() {
clicks++; //count clicks
if (clicks === 1) {
timer = setTimeout(function() {
//Here you can add a single click action.
clicks = 0; //after action performed, reset counter
}, delay);
} else {
clearTimeout(timer); //prevent single-click action
config.resizeOnDataCallback(self); //perform double-click action
clicks = 0; //after action performed, reset counter
}
};
self.gripOnMouseDown = function(event) {
$scope.isColumnResizing = true;
if (event.ctrlKey && !self.pinned) {
self.toggleVisible();
domUtilityService.BuildStyles($scope, grid);
return true;
}
event.target.parentElement.style.cursor = 'col-resize';
self.startMousePosition = event.clientX;
self.origWidth = self.width;
$(document).mousemove(self.onMouseMove);
$(document).mouseup(self.gripOnMouseUp);
return false;
};
self.onMouseMove = function(event) {
var diff = event.clientX - self.startMousePosition;
var newWidth = diff + self.origWidth;
self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
$scope.hasUserChangedGridColumnWidths = true;
domUtilityService.BuildStyles($scope, grid);
return false;
};
self.gripOnMouseUp = function (event) {
$(document).off('mousemove', self.onMouseMove);
$(document).off('mouseup', self.gripOnMouseUp);
event.target.parentElement.style.cursor = 'default';
domUtilityService.digest($scope);
$scope.isColumnResizing = false;
return false;
};
self.copy = function() {
var ret = new ngColumn(config, $scope, grid, domUtilityService, $templateCache, $utils);
ret.isClone = true;
ret.orig = self;
return ret;
};
self.setVars = function (fromCol) {
self.orig = fromCol;
self.width = fromCol.width;
self.groupIndex = fromCol.groupIndex;
self.isGroupedBy = fromCol.isGroupedBy;
self.displayName = fromCol.displayName;
self.index = fromCol.index;
self.isAggCol = fromCol.isAggCol;
self.cellClass = fromCol.cellClass;
self.cellFilter = fromCol.cellFilter;
self.field = fromCol.field;
self.aggLabelFilter = fromCol.aggLabelFilter;
self.visible = fromCol.visible;
self.sortable = fromCol.sortable;
self.resizable = fromCol.resizable;
self.pinnable = fromCol.pinnable;
self.pinned = fromCol.pinned;
self.originalIndex = fromCol.originalIndex;
self.sortDirection = fromCol.sortDirection;
self.sortingAlgorithm = fromCol.sortingAlgorithm;
self.headerClass = fromCol.headerClass;
self.headerCellTemplate = fromCol.headerCellTemplate;
self.cellTemplate = fromCol.cellTemplate;
self.cellEditTemplate = fromCol.cellEditTemplate;
};
};
var ngDimension = function (options) {
this.outerHeight = null;
this.outerWidth = null;
$.extend(this, options);
};
var ngDomAccessProvider = function (grid) {
this.previousColumn = null;
this.grid = grid;
};
ngDomAccessProvider.prototype.changeUserSelect = function (elm, value) {
elm.css({
'-webkit-touch-callout': value,
'-webkit-user-select': value,
'-khtml-user-select': value,
'-moz-user-select': value === 'none' ? '-moz-none' : value,
'-ms-user-select': value,
'user-select': value
});
};
ngDomAccessProvider.prototype.focusCellElement = function ($scope, index) {
if ($scope.selectionProvider.lastClickedRow) {
var columnIndex = index !== undefined ? index : this.previousColumn;
var elm = $scope.selectionProvider.lastClickedRow.clone ? $scope.selectionProvider.lastClickedRow.clone.elm : $scope.selectionProvider.lastClickedRow.elm;
if (columnIndex !== undefined && elm) {
var columns = angular.element(elm[0].children).filter(function () { return this.nodeType !== 8; }); //Remove html comments for IE8
var i = Math.max(Math.min($scope.renderedColumns.length - 1, columnIndex), 0);
if (this.grid.config.showSelectionCheckbox && angular.element(columns[i]).scope() && angular.element(columns[i]).scope().col.index === 0) {
i = 1; //don't want to focus on checkbox
}
if (columns[i]) {
columns[i].children[1].children[0].focus();
}
this.previousColumn = columnIndex;
}
}
};
ngDomAccessProvider.prototype.selectionHandlers = function ($scope, elm) {
var doingKeyDown = false;
var self = this;
function keydown (evt) {
if (evt.keyCode === 16) { //shift key
self.changeUserSelect(elm, 'none', evt);
return true;
} else if (!doingKeyDown) {
doingKeyDown = true;
var ret = ngMoveSelectionHandler($scope, elm, evt, self.grid);
doingKeyDown = false;
return ret;
}
return true;
}
elm.bind('keydown', keydown);
function keyup (evt) {
if (evt.keyCode === 16) { //shift key
self.changeUserSelect(elm, 'text', evt);
}
return true;
}
elm.bind('keyup', keyup);
elm.on('$destroy', function() {
elm.off('keydown', keydown);
elm.off('keyup', keyup);
});
};
var ngEventProvider = function (grid, $scope, domUtilityService, $timeout) {
var self = this;
// The init method gets called during the ng-grid directive execution.
self.colToMove = undefined;
self.groupToMove = undefined;
self.assignEvents = function() {
// Here we set the onmousedown event handler to the header container.
if (grid.config.jqueryUIDraggable && !grid.config.enablePinning) {
grid.$groupPanel.droppable({
addClasses: false,
drop: function(event) {
self.onGroupDrop(event);
}
});
grid.$groupPanel.on('$destroy', function() {
grid.$groupPanel = null;
});
} else {
grid.$groupPanel.on('mousedown', self.onGroupMouseDown).on('dragover', self.dragOver).on('drop', self.onGroupDrop);
grid.$topPanel.on('mousedown', '.ngHeaderScroller', self.onHeaderMouseDown).on('dragover', '.ngHeaderScroller', self.dragOver);
grid.$groupPanel.on('$destroy', function() {
grid.$groupPanel.off('mousedown');
grid.$groupPanel = null;
});
if (grid.config.enableColumnReordering) {
grid.$topPanel.on('drop', '.ngHeaderScroller', self.onHeaderDrop);
}
grid.$topPanel.on('$destroy', function() {
grid.$topPanel.off('mousedown');
if (grid.config.enableColumnReordering) {
grid.$topPanel.off('drop');
}
grid.$topPanel = null;
});
}
$scope.$on('$destroy', $scope.$watch('renderedColumns', function() {
$timeout(self.setDraggables);
}));
};
self.dragStart = function(evt){
//FireFox requires there to be dataTransfer if you want to drag and drop.
evt.dataTransfer.setData('text', ''); //cannot be empty string
};
self.dragOver = function(evt) {
evt.preventDefault();
};
//For JQueryUI
self.setDraggables = function() {
if (!grid.config.jqueryUIDraggable) {
//Fix for FireFox. Instead of using jQuery on('dragstart', function) on find, we have to use addEventListeners for each column.
var columns = grid.$root.find('.ngHeaderSortColumn'); //have to iterate if using addEventListener
angular.forEach(columns, function(col){
if(col.className && col.className.indexOf("ngHeaderSortColumn") !== -1){
col.setAttribute('draggable', 'true');
//jQuery 'on' function doesn't have dataTransfer as part of event in handler unless added to event props, which is not recommended
//See more here: http://api.jquery.com/category/events/event-object/
if (col.addEventListener) { //IE8 doesn't have drag drop or event listeners
col.addEventListener('dragstart', self.dragStart);
angular.element(col).on('$destroy', function() {
angular.element(col).off('dragstart', self.dragStart);
col.removeEventListener('dragstart', self.dragStart);
});
}
}
});
if (navigator.userAgent.indexOf("MSIE") !== -1){
//call native IE dragDrop() to start dragging
var sortColumn = grid.$root.find('.ngHeaderSortColumn');
sortColumn.bind('selectstart', function () {
this.dragDrop();
return false;
});
angular.element(sortColumn).on('$destroy', function() {
sortColumn.off('selectstart');
});
}
} else {
if (grid.$root) {
grid.$root.find('.ngHeaderSortColumn').draggable({
helper: 'clone',
appendTo: 'body',
stack: 'div',
addClasses: false,
start: function(event) {
self.onHeaderMouseDown(event);
}
}).droppable({
drop: function(event) {
self.onHeaderDrop(event);
}
});
}
}
};
self.onGroupMouseDown = function(event) {
var groupItem = $(event.target);
// Get the scope from the header container
if (groupItem[0].className !== 'ngRemoveGroup') {
var groupItemScope = angular.element(groupItem).scope();
if (groupItemScope) {
// set draggable events
if (!grid.config.jqueryUIDraggable) {
groupItem.attr('draggable', 'true');
if(this.addEventListener){//IE8 doesn't have drag drop or event listeners
this.addEventListener('dragstart', self.dragStart);
angular.element(this).on('$destroy', function() {
this.removeEventListener('dragstart', self.dragStart);
});
}
if (navigator.userAgent.indexOf("MSIE") !== -1){
//call native IE dragDrop() to start dragging
groupItem.bind('selectstart', function () {
this.dragDrop();
return false;
});
groupItem.on('$destroy', function() {
groupItem.off('selectstart');
});
}
}
// Save the column for later.
self.groupToMove = { header: groupItem, groupName: groupItemScope.group, index: groupItemScope.$index };
}
} else {
self.groupToMove = undefined;
}
};
self.onGroupDrop = function(event) {
event.stopPropagation();
// clear out the colToMove object
var groupContainer;
var groupScope;
if (self.groupToMove) {
// Get the closest header to where we dropped
groupContainer = $(event.target).closest('.ngGroupElement'); // Get the scope from the header.
if (groupContainer.context.className === 'ngGroupPanel') {
$scope.configGroups.splice(self.groupToMove.index, 1);
$scope.configGroups.push(self.groupToMove.groupName);
} else {
groupScope = angular.element(groupContainer).scope();
if (groupScope) {
// If we have the same column, do nothing.
if (self.groupToMove.index !== groupScope.$index) {
// Splice the columns
$scope.configGroups.splice(self.groupToMove.index, 1);
$scope.configGroups.splice(groupScope.$index, 0, self.groupToMove.groupName);
}
}
}
self.groupToMove = undefined;
grid.fixGroupIndexes();
} else if (self.colToMove) {
if ($scope.configGroups.indexOf(self.colToMove.col) === -1) {
groupContainer = $(event.target).closest('.ngGroupElement'); // Get the scope from the header.
if (groupContainer.context.className === 'ngGroupPanel' || groupContainer.context.className === 'ngGroupPanelDescription ng-binding') {
$scope.groupBy(self.colToMove.col);
} else {
groupScope = angular.element(groupContainer).scope();
if (groupScope) {
// Splice the columns
$scope.removeGroup(groupScope.$index);
}
}
}
self.colToMove = undefined;
}
if (!$scope.$$phase) {
$scope.$apply();
}
};
//Header functions
self.onHeaderMouseDown = function(event) {
// Get the closest header container from where we clicked.
var headerContainer = $(event.target).closest('.ngHeaderSortColumn');
// Get the scope from the header container
var headerScope = angular.element(headerContainer).scope();
if (headerScope) {
// Save the column for later.
self.colToMove = { header: headerContainer, col: headerScope.col };
}
};
self.onHeaderDrop = function(event) {
if (!self.colToMove || self.colToMove.col.pinned) {
return;
}
// Get the closest header to where we dropped
var headerContainer = $(event.target).closest('.ngHeaderSortColumn');
// Get the scope from the header.
var headerScope = angular.element(headerContainer).scope();
if (headerScope) {
// If we have the same column or the target column is pinned, do nothing.
if (self.colToMove.col === headerScope.col || headerScope.col.pinned) {
return;
}
// Splice the columns
$scope.columns.splice(self.colToMove.col.index, 1);
$scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
// clear out the colToMove object
self.colToMove = undefined;
domUtilityService.digest($scope);
}
};
self.assignGridEventHandlers = function() {
//Chrome and firefox both need a tab index so the grid can recieve focus.
//need to give the grid a tabindex if it doesn't already have one so
//we'll just give it a tab index of the corresponding gridcache index
//that way we'll get the same result every time it is run.
//configurable within the options.
if (grid.config.tabIndex === -1) {
grid.$viewport.attr('tabIndex', domUtilityService.numberOfGrids);
domUtilityService.numberOfGrids++;
} else {
grid.$viewport.attr('tabIndex', grid.config.tabIndex);
}
// resize on window resize
var windowThrottle;
var windowResize = function(){
clearTimeout(windowThrottle);
windowThrottle = setTimeout(function() {
//in function for IE8 compatibility
domUtilityService.RebuildGrid($scope,grid);
}, 100);
};
$(window).on('resize.nggrid', windowResize);
// resize on parent resize as well.
var parentThrottle;
var parentResize = function() {
clearTimeout(parentThrottle);
parentThrottle = setTimeout(function() {
//in function for IE8 compatibility
domUtilityService.RebuildGrid($scope,grid);
}, 100);
};
$(grid.$root.parent()).on('resize.nggrid', parentResize);
$scope.$on('$destroy', function(){
$(window).off('resize.nggrid', windowResize);
// $(grid.$root.parent()).off('resize.nggrid', parentResize);
});
};
// In this example we want to assign grid events.
self.assignGridEventHandlers();
self.assignEvents();
};
var ngFooter = function ($scope, grid) {
$scope.maxRows = function () {
var ret = Math.max($scope.totalServerItems, grid.data.length);
return ret;
};
$scope.$on('$destroy', $scope.$watch('totalServerItems',function(n,o){
$scope.currentMaxPages = $scope.maxPages();
}));
$scope.multiSelect = (grid.config.enableRowSelection && grid.config.multiSelect);
$scope.selectedItemCount = grid.selectedItemCount;
$scope.maxPages = function () {
if($scope.maxRows() === 0) {
return 1;
}
return Math.ceil($scope.maxRows() / $scope.pagingOptions.pageSize);
};
$scope.pageForward = function() {
var page = $scope.pagingOptions.currentPage;
if ($scope.totalServerItems > 0) {
$scope.pagingOptions.currentPage = Math.min(page + 1, $scope.maxPages());
} else {
$scope.pagingOptions.currentPage++;
}
};
$scope.pageBackward = function() {
var page = $scope.pagingOptions.currentPage;
$scope.pagingOptions.currentPage = Math.max(page - 1, 1);
};
$scope.pageToFirst = function() {
$scope.pagingOptions.currentPage = 1;
};
$scope.pageToLast = function() {
var maxPages = $scope.maxPages();
$scope.pagingOptions.currentPage = maxPages;
};
$scope.cantPageForward = function() {
var curPage = $scope.pagingOptions.currentPage;
var maxPages = $scope.maxPages();
if ($scope.totalServerItems > 0) {
return curPage >= maxPages;
} else {
return grid.data.length < 1;
}
};
$scope.cantPageToLast = function() {
if ($scope.totalServerItems > 0) {
return $scope.cantPageForward();
} else {
return true;
}
};
$scope.cantPageBackward = function() {
var curPage = $scope.pagingOptions.currentPage;
return curPage <= 1;
};
};
/// <reference path="footer.js" />
/// <reference path="../services/SortService.js" />
/// <reference path="../../lib/jquery-1.8.2.min" />
var ngGrid = function ($scope, options, sortService, domUtilityService, $filter, $templateCache, $utils, $timeout, $parse, $http, $q) {
var defaults = {
//Define an aggregate template to customize the rows when grouped. See github wiki for more details.
aggregateTemplate: undefined,
//Callback for when you want to validate something after selection.
afterSelectionChange: function() {
},
/* Callback if you want to inspect something before selection,
return false if you want to cancel the selection. return true otherwise.
If you need to wait for an async call to proceed with selection you can
use rowItem.changeSelection(event) method after returning false initially.
Note: when shift+ Selecting multiple items in the grid this will only get called
once and the rowItem will be an array of items that are queued to be selected. */
beforeSelectionChange: function() {
return true;
},
//checkbox templates.
checkboxCellTemplate: undefined,
checkboxHeaderTemplate: undefined,
//definitions of columns as an array [], if not defines columns are auto-generated. See github wiki for more details.
columnDefs: undefined,
//*Data being displayed in the grid. Each item in the array is mapped to a row being displayed.
data: [],
//Data updated callback, fires every time the data is modified from outside the grid.
dataUpdated: function() {
},
//Enables cell editing.
enableCellEdit: false,
//Enables cell editing on focus
enableCellEditOnFocus: false,
//Enables cell selection.
enableCellSelection: false,
//Enable or disable resizing of columns
enableColumnResize: false,
//Enable or disable reordering of columns
enableColumnReordering: false,
//Enable or disable HEAVY column virtualization. This turns off selection checkboxes and column pinning and is designed for spreadsheet-like data.
enableColumnHeavyVirt: false,
//Enables the server-side paging feature
enablePaging: false,
//Enable column pinning
enablePinning: false,
//To be able to have selectable rows in grid.
enableRowSelection: true,
//Enables or disables sorting in grid.
enableSorting: true,
//Enables or disables text highlighting in grid by adding the "unselectable" class (See CSS file)
enableHighlighting: false,
// string list of properties to exclude when auto-generating columns.
excludeProperties: [],
/* filterOptions -
filterText: The text bound to the built-in search box.
useExternalFilter: Bypass internal filtering if you want to roll your own filtering mechanism but want to use builtin search box.
*/
filterOptions: {
filterText: "",
useExternalFilter: false
},
//Defining the height of the footer in pixels.
footerRowHeight: 55,
// the template for the column menu and filter, including the button.
footerTemplate: undefined,
// Enables a trade off between refreshing the contents of the grid continuously while scrolling (behaviour when true)
// and keeping the scroll bar button responsive at the expense of refreshing grid contents (behaviour when false)
forceSyncScrolling: true,
//Initial fields to group data by. Array of field names, not displayName.
groups: [],
// set the initial state of aggreagate grouping. "true" means they will be collapsed when grouping changes, "false" means they will be expanded by default.
groupsCollapsedByDefault: true,
//The height of the header row in pixels.
headerRowHeight: 30,
//Define a header row template for further customization. See github wiki for more details.
headerRowTemplate: undefined,
/*Enables the use of jquery UI reaggable/droppable plugin. requires jqueryUI to work if enabled.
Useful if you want drag + drop but your users insist on crappy browsers. */
jqueryUIDraggable: false,
//Enable the use jqueryUIThemes
jqueryUITheme: false,
//Prevent unselections when in single selection mode.
keepLastSelected: true,
/*Maintains the column widths while resizing.
Defaults to true when using *'s or undefined widths. Can be ovverriden by setting to false.*/
maintainColumnRatios: undefined,
// the template for the column menu and filter, including the button.
menuTemplate: undefined,
//Set this to false if you only want one item selected at a time
multiSelect: true,
// pagingOptions -
pagingOptions: {
// pageSizes: list of available page sizes.
pageSizes: [250, 500, 1000],
//pageSize: currently selected page size.
pageSize: 250,
//currentPage: the uhm... current page.
currentPage: 1
},
//the selection checkbox is pinned to the left side of the viewport or not.
pinSelectionCheckbox: false,
//Array of plugin functions to register in ng-grid
plugins: [],
//User defined unique ID field that allows for better handling of selections and for server-side paging
primaryKey: undefined,
//Row height of rows in grid.
rowHeight: 30,
//Define a row template to customize output. See github wiki for more details.
rowTemplate: undefined,
//all of the items selected in the grid. In single select mode there will only be one item in the array.
selectedItems: [],
//Disable row selections by clicking on the row and only when the checkbox is clicked.
selectWithCheckboxOnly: false,
/*Enables menu to choose which columns to display and group by.
If both showColumnMenu and showFilter are false the menu button will not display.*/
showColumnMenu: false,
/*Enables display of the filterbox in the column menu.
If both showColumnMenu and showFilter are false the menu button will not display.*/
showFilter: false,
//Show or hide the footer alltogether the footer is enabled by default
showFooter: false,
//Show the dropzone for drag and drop grouping
showGroupPanel: false,
//Row selection check boxes appear as the first column.
showSelectionCheckbox: false,
/*Define a sortInfo object to specify a default sorting state.
You can also observe this variable to utilize server-side sorting (see useExternalSorting).
Syntax is sortinfo: { fields: ['fieldName1',' fieldName2'], direction: 'ASC'/'asc' || 'desc'/'DESC'}*/
sortInfo: {fields: [], columns: [], directions: [] },
//Set the tab index of the Vieport.
tabIndex: -1,
//totalServerItems: Total items are on the server.
totalServerItems: 0,
/*Prevents the internal sorting from executing.
The sortInfo object will be updated with the sorting information so you can handle sorting (see sortInfo)*/
useExternalSorting: false,
/*i18n language support. choose from the installed or included languages, en, fr, sp, etc...*/
i18n: 'en',
//the threshold in rows to force virtualization on
virtualizationThreshold: 50,
// Don't handle tabs, so they can be used to navigate between controls.
noTabInterference: false
},
self = this;
self.maxCanvasHt = 0;
//self vars
self.config = $.extend(defaults, window.ngGrid.config, options);
// override conflicting settings
self.config.showSelectionCheckbox = (self.config.showSelectionCheckbox && self.config.enableColumnHeavyVirt === false);
self.config.enablePinning = (self.config.enablePinning && self.config.enableColumnHeavyVirt === false);
self.config.selectWithCheckboxOnly = (self.config.selectWithCheckboxOnly && self.config.showSelectionCheckbox !== false);
self.config.pinSelectionCheckbox = self.config.enablePinning;
if (typeof options.columnDefs === "string") {
self.config.columnDefs = $scope.$eval(options.columnDefs);
}
self.rowCache = [];
self.rowMap = [];
self.gridId = "ng" + $utils.newId();
self.$root = null; //this is the root element that is passed in with the binding handler
self.$groupPanel = null;
self.$topPanel = null;
self.$headerContainer = null;
self.$headerScroller = null;
self.$headers = null;
self.$viewport = null;
self.$canvas = null;
self.rootDim = self.config.gridDim;
self.data = [];
self.lateBindColumns = false;
self.filteredRows = [];
self.initTemplates = function() {
var templates = ['rowTemplate', 'aggregateTemplate', 'headerRowTemplate', 'checkboxCellTemplate', 'checkboxHeaderTemplate', 'menuTemplate', 'footerTemplate'];
var promises = [];
angular.forEach(templates, function(template) {
promises.push( self.getTemplate(template) );
});
return $q.all(promises);
};
//Templates
// test templates for urls and get the tempaltes via synchronous ajax calls
self.getTemplate = function (key) {
var t = self.config[key];
var uKey = self.gridId + key + ".html";
var p = $q.defer();
if (t && !TEMPLATE_REGEXP.test(t)) {
$http.get(t, {
cache: $templateCache
})
.success(function(data){
$templateCache.put(uKey, data);
p.resolve();
})
.error(function(err){
p.reject("Could not load template: " + t);
});
} else if (t) {
$templateCache.put(uKey, t);
p.resolve();
} else {
var dKey = key + ".html";
$templateCache.put(uKey, $templateCache.get(dKey));
p.resolve();
}
return p.promise;
};
if (typeof self.config.data === "object") {
self.data = self.config.data; // we cannot watch for updates if you don't pass the string name
}
self.calcMaxCanvasHeight = function() {
var calculatedHeight;
if(self.config.groups.length > 0){
calculatedHeight = self.rowFactory.parsedData.filter(function(e) {
return !e[NG_HIDDEN];
}).length * self.config.rowHeight;
} else {
calculatedHeight = self.filteredRows.length * self.config.rowHeight;
}
return calculatedHeight;
};
self.elementDims = {
scrollW: 0,
scrollH: 0,
rowIndexCellW: 25,
rowSelectedCellW: 25,
rootMaxW: 0,
rootMaxH: 0
};
//self funcs
self.setRenderedRows = function (newRows) {
$scope.renderedRows.length = newRows.length;
for (var i = 0; i < newRows.length; i++) {
if (!$scope.renderedRows[i] || (newRows[i].isAggRow || $scope.renderedRows[i].isAggRow)) {
$scope.renderedRows[i] = newRows[i].copy();
$scope.renderedRows[i].collapsed = newRows[i].collapsed;
if (!newRows[i].isAggRow) {
$scope.renderedRows[i].setVars(newRows[i]);
}
} else {
$scope.renderedRows[i].setVars(newRows[i]);
}
$scope.renderedRows[i].rowIndex = newRows[i].rowIndex;
$scope.renderedRows[i].offsetTop = newRows[i].offsetTop;
$scope.renderedRows[i].selected = newRows[i].selected;
newRows[i].renderedRowIndex = i;
}
self.refreshDomSizes();
$scope.$emit('ngGridEventRows', newRows);
};
self.minRowsToRender = function() {
var viewportH = $scope.viewportDimHeight() || 1;
return Math.floor(viewportH / self.config.rowHeight);
};
self.refreshDomSizes = function() {
var dim = new ngDimension();
dim.outerWidth = self.elementDims.rootMaxW;
dim.outerHeight = self.elementDims.rootMaxH;
self.rootDim = dim;
self.maxCanvasHt = self.calcMaxCanvasHeight();
};
self.buildColumnDefsFromData = function () {
self.config.columnDefs = [];
var item = self.data[0];
if (!item) {
self.lateBoundColumns = true;
return;
}
$utils.forIn(item, function (prop, propName) {
if (self.config.excludeProperties.indexOf(propName) === -1) {
self.config.columnDefs.push({
field: propName
});
}
});
};
self.buildColumns = function() {
var columnDefs = self.config.columnDefs,
cols = [];
if (!columnDefs) {
self.buildColumnDefsFromData();
columnDefs = self.config.columnDefs;
}
if (self.config.showSelectionCheckbox) {
cols.push(new ngColumn({
colDef: {
field: '\u2714',
width: self.elementDims.rowSelectedCellW,
sortable: false,
resizable: false,
groupable: false,
headerCellTemplate: $templateCache.get($scope.gridId + 'checkboxHeaderTemplate.html'),
cellTemplate: $templateCache.get($scope.gridId + 'checkboxCellTemplate.html'),
pinned: self.config.pinSelectionCheckbox
},
index: 0,
headerRowHeight: self.config.headerRowHeight,
sortCallback: self.sortData,
resizeOnDataCallback: self.resizeOnData,
enableResize: self.config.enableColumnResize,
enableSort: self.config.enableSorting,
enablePinning: self.config.enablePinning
}, $scope, self, domUtilityService, $templateCache, $utils));
}
if (columnDefs.length > 0) {
var checkboxOffset = self.config.showSelectionCheckbox ? 1 : 0;
var groupOffset = $scope.configGroups.length;
$scope.configGroups.length = 0;
angular.forEach(columnDefs, function(colDef, i) {
i += checkboxOffset;
var column = new ngColumn({
colDef: colDef,
index: i + groupOffset,
originalIndex: i,
headerRowHeight: self.config.headerRowHeight,
sortCallback: self.sortData,
resizeOnDataCallback: self.resizeOnData,
enableResize: self.config.enableColumnResize,
enableSort: self.config.enableSorting,
enablePinning: self.config.enablePinning,
enableCellEdit: self.config.enableCellEdit || self.config.enableCellEditOnFocus,
cellEditableCondition: self.config.cellEditableCondition
}, $scope, self, domUtilityService, $templateCache, $utils);
var indx = self.config.groups.indexOf(colDef.field);
if (indx !== -1) {
column.isGroupedBy = true;
$scope.configGroups.splice(indx, 0, column);
column.groupIndex = $scope.configGroups.length;
}
cols.push(column);
});
$scope.columns = cols;
if (self.config.groups.length > 0) {
self.rowFactory.getGrouping(self.config.groups);
}
}
};
self.configureColumnWidths = function() {
var asterisksArray = [],
percentArray = [],
asteriskNum = 0,
totalWidth = 0;
// When rearranging columns, their index in $scope.columns will no longer match the original column order from columnDefs causing
// their width config to be out of sync. We can use "originalIndex" on the ngColumns to get hold of the correct setup from columnDefs, but to
// avoid O(n) lookups in $scope.columns per column we setup a map.
var indexMap = {};
// Build a map of columnDefs column indices -> ngColumn indices (via the "originalIndex" property on ngColumns).
angular.forEach($scope.columns, function(ngCol, i) {
// Disregard columns created by grouping (the grouping columns don't match a column from columnDefs)
if (!$utils.isNullOrUndefined(ngCol.originalIndex)) {
var origIndex = ngCol.originalIndex;
if (self.config.showSelectionCheckbox) {
//if visible, takes up 25 pixels
if(ngCol.originalIndex === 0 && ngCol.visible){
totalWidth += 25;
}
// The originalIndex will be offset 1 when including the selection column
origIndex--;
}
indexMap[origIndex] = i;
}
});
angular.forEach(self.config.columnDefs, function(colDef, i) {
// Get the ngColumn that matches the current column from columnDefs
var ngColumn = $scope.columns[indexMap[i]];
colDef.index = i;
var isPercent = false, t;
//if width is not defined, set it to a single star
if ($utils.isNullOrUndefined(colDef.width)) {
colDef.width = "*";
} else { // get column width
isPercent = isNaN(colDef.width) ? $utils.endsWith(colDef.width, "%") : false;
t = isPercent ? colDef.width : parseInt(colDef.width, 10);
}
// check if it is a number
if (isNaN(t) && !$scope.hasUserChangedGridColumnWidths) {
t = colDef.width;
// figure out if the width is defined or if we need to calculate it
if (t === 'auto') { // set it for now until we have data and subscribe when it changes so we can set the width.
ngColumn.width = ngColumn.minWidth;
totalWidth += ngColumn.width;
var temp = ngColumn;
$scope.$on('$destroy', $scope.$on("ngGridEventData", function () {
self.resizeOnData(temp);
}));
return;
} else if (t.indexOf("*") !== -1) { // we need to save it until the end to do the calulations on the remaining width.
if (ngColumn.visible !== false) {
asteriskNum += t.length;
}
asterisksArray.push(colDef);
return;
} else if (isPercent) { // If the width is a percentage, save it until the very last.
percentArray.push(colDef);
return;
} else { // we can't parse the width so lets throw an error.
throw "unable to parse column width, use percentage (\"10%\",\"20%\", etc...) or \"*\" to use remaining width of grid";
}
} else if (ngColumn.visible !== false) {
totalWidth += ngColumn.width = parseInt(ngColumn.width, 10);
}
});
// Now we check if we saved any percentage columns for calculating last
if (percentArray.length > 0) {
//If they specificy for maintain column ratios to be false in grid config, then it will remain false. If not specifiied or true, will be true.
self.config.maintainColumnRatios = self.config.maintainColumnRatios !== false;
// If any columns with % widths have been hidden, then let other % based columns use their width
var percentWidth = 0; // The total % value for all columns setting their width using % (will e.g. be 40 for 2 columns with 20% each)
var hiddenPercent = 0; // The total % value for all columns setting their width using %, but which have been hidden
angular.forEach(percentArray, function(colDef) {
// Get the ngColumn that matches the current column from columnDefs
var ngColumn = $scope.columns[indexMap[colDef.index]];
var percent = parseFloat(colDef.width) / 100;
percentWidth += percent;
if (!ngColumn.visible) {
hiddenPercent += percent;
}
});
var percentWidthUsed = percentWidth - hiddenPercent;
// do the math
angular.forEach(percentArray, function(colDef) {
// Get the ngColumn that matches the current column from columnDefs
var ngColumn = $scope.columns[indexMap[colDef.index]];
// Calc the % relative to the amount of % reserved for the visible columns (that use % based widths)
var percent = parseFloat(colDef.width) / 100;
if (hiddenPercent > 0) {
percent = percent / percentWidthUsed;
}
else {
percent = percent / percentWidth;
}
var pixelsForPercentBasedWidth = self.rootDim.outerWidth * percentWidth;
ngColumn.width = pixelsForPercentBasedWidth * percent;
totalWidth += ngColumn.width;
});
}
// check if we saved any asterisk columns for calculating later
if (asterisksArray.length > 0) {
//If they specificy for maintain column ratios to be false in grid config, then it will remain false. If not specifiied or true, will be true.
self.config.maintainColumnRatios = self.config.maintainColumnRatios !== false;
// get the remaining width
var remainingWidth = self.rootDim.outerWidth - totalWidth;
// are we overflowing vertically?
if (self.maxCanvasHt > $scope.viewportDimHeight()) {
//compensate for scrollbar
remainingWidth -= domUtilityService.ScrollW;
}
// calculate the weight of each asterisk rounded down
var asteriskVal = Math.floor(remainingWidth / asteriskNum);
// set the width of each column based on the number of stars
angular.forEach(asterisksArray, function(colDef, i) {
// Get the ngColumn that matches the current column from columnDefs
var ngColumn = $scope.columns[indexMap[colDef.index]];
ngColumn.width = asteriskVal * colDef.width.length;
if (ngColumn.visible !== false) {
totalWidth += ngColumn.width;
}
var isLast = (i === (asterisksArray.length - 1));
//if last asterisk and doesn't fill width of grid, add the difference
if(isLast && totalWidth < self.rootDim.outerWidth){
var gridWidthDifference = self.rootDim.outerWidth - totalWidth;
if(self.maxCanvasHt > $scope.viewportDimHeight()){
gridWidthDifference -= domUtilityService.ScrollW;
}
ngColumn.width += gridWidthDifference;
}
});
}
};
self.init = function() {
return self.initTemplates().then(function(){
//factories and services
$scope.selectionProvider = new ngSelectionProvider(self, $scope, $parse);
$scope.domAccessProvider = new ngDomAccessProvider(self);
self.rowFactory = new ngRowFactory(self, $scope, domUtilityService, $templateCache, $utils);
self.searchProvider = new ngSearchProvider($scope, self, $filter);
self.styleProvider = new ngStyleProvider($scope, self);
$scope.$on('$destroy', $scope.$watch('configGroups', function(a) {
var tempArr = [];
angular.forEach(a, function(item) {
tempArr.push(item.field || item);
});
self.config.groups = tempArr;
self.rowFactory.filteredRowsChanged();
$scope.$emit('ngGridEventGroups', a);
}, true));
$scope.$on('$destroy', $scope.$watch('columns', function (a) {
if(!$scope.isColumnResizing){
domUtilityService.RebuildGrid($scope, self);
}
$scope.$emit('ngGridEventColumns', a);
}, true));
$scope.$on('$destroy', $scope.$watch(function() {
return options.i18n;
}, function(newLang) {
$utils.seti18n($scope, newLang);
}));
self.maxCanvasHt = self.calcMaxCanvasHeight();
if (self.config.sortInfo.fields && self.config.sortInfo.fields.length > 0) {
$scope.$on('$destroy', $scope.$watch(function() {
return self.config.sortInfo;
}, function(sortInfo){
if (!sortService.isSorting) {
self.sortColumnsInit();
$scope.$emit('ngGridEventSorted', self.config.sortInfo);
}
}, true));
}
});
// var p = $q.defer();
// p.resolve();
// return p.promise;
};
self.resizeOnData = function(col) {
// we calculate the longest data.
var longest = col.minWidth;
var arr = $utils.getElementsByClassName('col' + col.index);
angular.forEach(arr, function(elem, index) {
var i;
if (index === 0) {
var kgHeaderText = $(elem).find('.ngHeaderText');
i = $utils.visualLength(kgHeaderText) + 10; // +10 some margin
} else {
var ngCellText = $(elem).find('.ngCellText');
i = $utils.visualLength(ngCellText) + 10; // +10 some margin
}
if (i > longest) {
longest = i;
}
});
col.width = col.longest = Math.min(col.maxWidth, longest + 7); // + 7 px to make it look decent.
domUtilityService.BuildStyles($scope, self, true);
};
self.lastSortedColumns = [];
self.sortData = function(col, evt) {
if (evt && evt.shiftKey && self.config.sortInfo) {
var indx = self.config.sortInfo.columns.indexOf(col);
if (indx === -1) {
if (self.config.sortInfo.columns.length === 1) {
self.config.sortInfo.columns[0].sortPriority = 1;
}
self.config.sortInfo.columns.push(col);
col.sortPriority = self.config.sortInfo.columns.length;
self.config.sortInfo.fields.push(col.field);
self.config.sortInfo.directions.push(col.sortDirection);
self.lastSortedColumns.push(col);
} else {
self.config.sortInfo.directions[indx] = col.sortDirection;
}
} else if (!self.config.useExternalSorting || (self.config.useExternalSorting && self.config.sortInfo )) {
var isArr = $.isArray(col);
self.config.sortInfo.columns.length = 0;
self.config.sortInfo.fields.length = 0;
self.config.sortInfo.directions.length = 0;
var push = function (c) {
self.config.sortInfo.columns.push(c);
self.config.sortInfo.fields.push(c.field);
self.config.sortInfo.directions.push(c.sortDirection);
self.lastSortedColumns.push(c);
};
if (isArr) {
angular.forEach(col, function (c, i) {
c.sortPriority = i + 1;
push(c);
});
} else {
self.clearSortingData(col);
col.sortPriority = undefined;
push(col);
}
self.sortActual();
self.searchProvider.evalFilter();
$scope.$emit('ngGridEventSorted', self.config.sortInfo);
}
};
self.sortColumnsInit = function() {
if (self.config.sortInfo.columns) {
self.config.sortInfo.columns.length = 0;
} else {
self.config.sortInfo.columns = [];
}
var cols = [];
angular.forEach($scope.columns, function(c) {
var i = self.config.sortInfo.fields.indexOf(c.field);
if (i !== -1) {
c.sortDirection = self.config.sortInfo.directions[i] || 'asc';
cols[i] = c;
}
});
if(cols.length === 1){
self.sortData(cols[0]);
}else{
self.sortData(cols);
}
};
self.sortActual = function() {
if (!self.config.useExternalSorting) {
var tempData = self.data.slice(0);
angular.forEach(tempData, function(item, i) {
var e = self.rowMap[i];
if (e !== undefined) {
var v = self.rowCache[e];
if (v !== undefined) {
item.preSortSelected = v.selected;
item.preSortIndex = i;
}
}
});
sortService.Sort(self.config.sortInfo, tempData);
angular.forEach(tempData, function(item, i) {
self.rowCache[i].entity = item;
self.rowCache[i].selected = item.preSortSelected;
self.rowMap[item.preSortIndex] = i;
delete item.preSortSelected;
delete item.preSortIndex;
});
}
};
self.clearSortingData = function (col) {
if (!col) {
angular.forEach(self.lastSortedColumns, function (c) {
c.sortDirection = "";
c.sortPriority = null;
});
self.lastSortedColumns = [];
} else {
angular.forEach(self.lastSortedColumns, function (c) {
if (col.index !== c.index) {
c.sortDirection = "";
c.sortPriority = null;
}
});
self.lastSortedColumns[0] = col;
self.lastSortedColumns.length = 1;
}
};
self.fixColumnIndexes = function() {
//fix column indexes
for (var i = 0; i < $scope.columns.length; i++) {
$scope.columns[i].index = i;
}
};
self.fixGroupIndexes = function() {
angular.forEach($scope.configGroups, function(item, i) {
item.groupIndex = i + 1;
});
};
//$scope vars
$scope.elementsNeedMeasuring = true;
$scope.columns = [];
$scope.renderedRows = [];
$scope.renderedColumns = [];
$scope.headerRow = null;
$scope.rowHeight = self.config.rowHeight;
$scope.jqueryUITheme = self.config.jqueryUITheme;
$scope.showSelectionCheckbox = self.config.showSelectionCheckbox;
$scope.enableCellSelection = self.config.enableCellSelection;
$scope.enableCellEditOnFocus = self.config.enableCellEditOnFocus;
$scope.footer = null;
$scope.selectedItems = self.config.selectedItems;
$scope.multiSelect = self.config.multiSelect;
$scope.showFooter = self.config.showFooter;
$scope.footerRowHeight = $scope.showFooter ? self.config.footerRowHeight : 0;
$scope.showColumnMenu = self.config.showColumnMenu;
$scope.forceSyncScrolling = self.config.forceSyncScrolling;
$scope.showMenu = false;
$scope.configGroups = [];
$scope.gridId = self.gridId;
//Paging
$scope.enablePaging = self.config.enablePaging;
$scope.pagingOptions = self.config.pagingOptions;
//i18n support
$scope.i18n = {};
$utils.seti18n($scope, self.config.i18n);
$scope.adjustScrollLeft = function (scrollLeft) {
var colwidths = 0,
totalLeft = 0,
x = $scope.columns.length,
newCols = [],
dcv = !self.config.enableColumnHeavyVirt;
var r = 0;
var addCol = function (c) {
if (dcv) {
newCols.push(c);
} else {
if (!$scope.renderedColumns[r]) {
$scope.renderedColumns[r] = c.copy();
} else {
$scope.renderedColumns[r].setVars(c);
}
}
r++;
};
for (var i = 0; i < x; i++) {
var col = $scope.columns[i];
if (col.visible !== false) {
var w = col.width + colwidths;
if (col.pinned) {
addCol(col);
var newLeft = i > 0 ? (scrollLeft + totalLeft) : scrollLeft;
domUtilityService.setColLeft(col, newLeft, self);
totalLeft += col.width;
} else {
if (w >= scrollLeft) {
if (colwidths <= scrollLeft + self.rootDim.outerWidth) {
addCol(col);
}
}
}
colwidths += col.width;
}
}
if (dcv) {
$scope.renderedColumns = newCols;
}
};
self.prevScrollTop = 0;
self.prevScrollIndex = 0;
$scope.adjustScrollTop = function(scrollTop, force) {
if (self.prevScrollTop === scrollTop && !force) {
return;
}
if (scrollTop > 0 && self.$viewport[0].scrollHeight - scrollTop <= self.$viewport.outerHeight()) {
$scope.$emit('ngGridEventScroll');
}
var rowIndex = Math.floor(scrollTop / self.config.rowHeight);
var newRange;
if (self.filteredRows.length > self.config.virtualizationThreshold) {
// Have we hit the threshold going down?
if (self.prevScrollTop < scrollTop && rowIndex < self.prevScrollIndex + SCROLL_THRESHOLD) {
return;
}
//Have we hit the threshold going up?
if (self.prevScrollTop > scrollTop && rowIndex > self.prevScrollIndex - SCROLL_THRESHOLD) {
return;
}
newRange = new ngRange(Math.max(0, rowIndex - EXCESS_ROWS), rowIndex + self.minRowsToRender() + EXCESS_ROWS);
} else {
var maxLen = $scope.configGroups.length > 0 ? self.rowFactory.parsedData.length : self.filteredRows.length;
newRange = new ngRange(0, Math.max(maxLen, self.minRowsToRender() + EXCESS_ROWS));
}
self.prevScrollTop = scrollTop;
self.rowFactory.UpdateViewableRange(newRange);
self.prevScrollIndex = rowIndex;
};
//scope funcs
$scope.toggleShowMenu = function() {
$scope.showMenu = !$scope.showMenu;
};
$scope.toggleSelectAll = function(state, selectOnlyVisible) {
$scope.selectionProvider.toggleSelectAll(state, false, selectOnlyVisible);
};
$scope.totalFilteredItemsLength = function() {
return self.filteredRows.length;
};
$scope.showGroupPanel = function() {
return self.config.showGroupPanel;
};
$scope.topPanelHeight = function() {
return self.config.showGroupPanel === true ? self.config.headerRowHeight + 32 : self.config.headerRowHeight;
};
$scope.viewportDimHeight = function() {
return Math.max(0, self.rootDim.outerHeight - $scope.topPanelHeight() - $scope.footerRowHeight - 2);
};
$scope.groupBy = function (col) {
if (self.data.length < 1 || !col.groupable || !col.field) {
return;
}
//first sort the column
if (!col.sortDirection) {
col.sort({ shiftKey: $scope.configGroups.length > 0 ? true : false });
}
var indx = $scope.configGroups.indexOf(col);
if (indx === -1) {
col.isGroupedBy = true;
$scope.configGroups.push(col);
col.groupIndex = $scope.configGroups.length;
} else {
$scope.removeGroup(indx);
}
self.$viewport.scrollTop(0);
domUtilityService.digest($scope);
};
$scope.removeGroup = function(index) {
var col = $scope.columns.filter(function(item) {
return item.groupIndex === (index + 1);
})[0];
col.isGroupedBy = false;
col.groupIndex = 0;
if ($scope.columns[index].isAggCol) {
$scope.columns.splice(index, 1);
$scope.configGroups.splice(index, 1);
self.fixGroupIndexes();
}
if ($scope.configGroups.length === 0) {
self.fixColumnIndexes();
domUtilityService.digest($scope);
}
$scope.adjustScrollLeft(0);
};
$scope.togglePin = function (col) {
var indexFrom = col.index;
var indexTo = 0;
for (var i = 0; i < $scope.columns.length; i++) {
if (!$scope.columns[i].pinned) {
break;
}
indexTo++;
}
if (col.pinned) {
indexTo = Math.max(col.originalIndex, indexTo - 1);
}
col.pinned = !col.pinned;
// Splice the columns
$scope.columns.splice(indexFrom, 1);
$scope.columns.splice(indexTo, 0, col);
self.fixColumnIndexes();
// Finally, rebuild the CSS styles.
domUtilityService.BuildStyles($scope, self, true);
self.$viewport.scrollLeft(self.$viewport.scrollLeft() - col.width);
};
$scope.totalRowWidth = function() {
var totalWidth = 0,
cols = $scope.columns;
for (var i = 0; i < cols.length; i++) {
if (cols[i].visible !== false) {
totalWidth += cols[i].width;
}
}
return totalWidth;
};
$scope.headerScrollerDim = function() {
var viewportH = $scope.viewportDimHeight(),
maxHeight = self.maxCanvasHt,
vScrollBarIsOpen = (maxHeight > viewportH),
newDim = new ngDimension();
newDim.autoFitHeight = true;
newDim.outerWidth = $scope.totalRowWidth();
if (vScrollBarIsOpen) {
newDim.outerWidth += self.elementDims.scrollW;
} else if ((maxHeight - viewportH) <= self.elementDims.scrollH) { //if the horizontal scroll is open it forces the viewport to be smaller
newDim.outerWidth += self.elementDims.scrollW;
}
return newDim;
};
};
var ngRange = function (top, bottom) {
this.topRow = top;
this.bottomRow = bottom;
};
var ngRow = function (entity, config, selectionProvider, rowIndex, $utils) {
this.entity = entity;
this.config = config;
this.selectionProvider = selectionProvider;
this.rowIndex = rowIndex;
this.utils = $utils;
this.selected = selectionProvider.getSelection(entity);
this.cursor = this.config.enableRowSelection && !this.config.selectWithCheckboxOnly ? 'pointer' : 'default';
this.beforeSelectionChange = config.beforeSelectionChangeCallback;
this.afterSelectionChange = config.afterSelectionChangeCallback;
this.offsetTop = this.rowIndex * config.rowHeight;
this.rowDisplayIndex = 0;
};
ngRow.prototype.setSelection = function (isSelected) {
this.selectionProvider.setSelection(this, isSelected);
this.selectionProvider.lastClickedRow = this;
};
ngRow.prototype.continueSelection = function (event) {
this.selectionProvider.ChangeSelection(this, event);
};
ngRow.prototype.ensureEntity = function (expected) {
if (this.entity !== expected) {
// Update the entity and determine our selected property
this.entity = expected;
this.selected = this.selectionProvider.getSelection(this.entity);
}
};
ngRow.prototype.toggleSelected = function (event) {
if (!this.config.enableRowSelection && !this.config.enableCellSelection) {
return true;
}
var element = event.target || event;
//check and make sure its not the bubbling up of our checked 'click' event
if (element.type === "checkbox" && element.parentElement.className !== "ngSelectionCell ng-scope") {
return true;
}
if (this.config.selectWithCheckboxOnly && element.type !== "checkbox") {
this.selectionProvider.lastClickedRow = this;
return true;
}
if (this.beforeSelectionChange(this, event)) {
this.continueSelection(event);
}
return false;
};
ngRow.prototype.alternatingRowClass = function () {
var isEven = (this.rowIndex % 2) === 0;
var classes = {
'ngRow' : true,
'selected': this.selected,
'even': isEven,
'odd': !isEven,
'ui-state-default': this.config.jqueryUITheme && isEven,
'ui-state-active': this.config.jqueryUITheme && !isEven
};
return classes;
};
ngRow.prototype.getProperty = function (path) {
return this.utils.evalProperty(this.entity, path);
};
ngRow.prototype.copy = function () {
this.clone = new ngRow(this.entity, this.config, this.selectionProvider, this.rowIndex, this.utils);
this.clone.isClone = true;
this.clone.elm = this.elm;
this.clone.orig = this;
return this.clone;
};
ngRow.prototype.setVars = function (fromRow) {
fromRow.clone = this;
this.entity = fromRow.entity;
this.selected = fromRow.selected;
this.orig = fromRow;
};
var ngRowFactory = function (grid, $scope, domUtilityService, $templateCache, $utils) {
var self = this;
// we cache rows when they are built, and then blow the cache away when sorting
self.aggCache = {};
self.parentCache = []; // Used for grouping and is cleared each time groups are calulated.
self.dataChanged = true;
self.parsedData = [];
self.rowConfig = {};
self.selectionProvider = $scope.selectionProvider;
self.rowHeight = 30;
self.numberOfAggregates = 0;
self.groupedData = undefined;
self.rowHeight = grid.config.rowHeight;
self.rowConfig = {
enableRowSelection: grid.config.enableRowSelection,
rowClasses: grid.config.rowClasses,
selectedItems: $scope.selectedItems,
selectWithCheckboxOnly: grid.config.selectWithCheckboxOnly,
beforeSelectionChangeCallback: grid.config.beforeSelectionChange,
afterSelectionChangeCallback: grid.config.afterSelectionChange,
jqueryUITheme: grid.config.jqueryUITheme,
enableCellSelection: grid.config.enableCellSelection,
rowHeight: grid.config.rowHeight
};
self.renderedRange = new ngRange(0, grid.minRowsToRender() + EXCESS_ROWS);
// @entity - the data item
// @rowIndex - the index of the row
self.buildEntityRow = function(entity, rowIndex) {
// build the row
return new ngRow(entity, self.rowConfig, self.selectionProvider, rowIndex, $utils);
};
self.buildAggregateRow = function(aggEntity, rowIndex) {
var agg = self.aggCache[aggEntity.aggIndex]; // first check to see if we've already built it
if (!agg) {
// build the row
agg = new ngAggregate(aggEntity, self, self.rowConfig.rowHeight, grid.config.groupsCollapsedByDefault);
self.aggCache[aggEntity.aggIndex] = agg;
}
agg.rowIndex = rowIndex;
agg.offsetTop = rowIndex * self.rowConfig.rowHeight;
return agg;
};
self.UpdateViewableRange = function(newRange) {
self.renderedRange = newRange;
self.renderedChange();
};
self.filteredRowsChanged = function() {
// check for latebound autogenerated columns
if (grid.lateBoundColumns && grid.filteredRows.length > 0) {
grid.config.columnDefs = undefined;
grid.buildColumns();
grid.lateBoundColumns = false;
$scope.$evalAsync(function() {
$scope.adjustScrollLeft(0);
});
}
self.dataChanged = true;
if (grid.config.groups.length > 0) {
self.getGrouping(grid.config.groups);
}
self.UpdateViewableRange(self.renderedRange);
};
self.renderedChange = function() {
if (!self.groupedData || grid.config.groups.length < 1) {
self.renderedChangeNoGroups();
grid.refreshDomSizes();
return;
}
self.wasGrouped = true;
self.parentCache = [];
var x = 0;
var temp = self.parsedData.filter(function (e) {
if (e.isAggRow) {
if (e.parent && e.parent.collapsed) {
return false;
}
return true;
}
if (!e[NG_HIDDEN]) {
e.rowIndex = x++;
}
return !e[NG_HIDDEN];
});
self.totalRows = temp.length;
var rowArr = [];
for (var i = self.renderedRange.topRow; i < self.renderedRange.bottomRow; i++) {
if (temp[i]) {
temp[i].offsetTop = i * grid.config.rowHeight;
rowArr.push(temp[i]);
}
}
grid.setRenderedRows(rowArr);
};
self.renderedChangeNoGroups = function () {
var rowArr = [];
for (var i = self.renderedRange.topRow; i < self.renderedRange.bottomRow; i++) {
if (grid.filteredRows[i]) {
grid.filteredRows[i].rowIndex = i;
grid.filteredRows[i].offsetTop = i * grid.config.rowHeight;
rowArr.push(grid.filteredRows[i]);
}
}
grid.setRenderedRows(rowArr);
};
self.fixRowCache = function () {
var newLen = grid.data.length;
var diff = newLen - grid.rowCache.length;
if (diff < 0) {
grid.rowCache.length = grid.rowMap.length = newLen;
} else {
for (var i = grid.rowCache.length; i < newLen; i++) {
grid.rowCache[i] = grid.rowFactory.buildEntityRow(grid.data[i], i);
}
}
};
//magical recursion. it works. I swear it. I figured it out in the shower one day.
self.parseGroupData = function(g) {
if (g.values) {
for (var x = 0; x < g.values.length; x++){
// get the last parent in the array because that's where our children want to be
self.parentCache[self.parentCache.length - 1].children.push(g.values[x]);
//add the row to our return array
self.parsedData.push(g.values[x]);
}
} else {
for (var prop in g) {
// exclude the meta properties.
if (prop === NG_FIELD || prop === NG_DEPTH || prop === NG_COLUMN) {
continue;
} else if (g.hasOwnProperty(prop)) {
//build the aggregate row
var agg = self.buildAggregateRow({
gField: g[NG_FIELD],
gLabel: prop,
gDepth: g[NG_DEPTH],
isAggRow: true,
'_ng_hidden_': false,
children: [],
aggChildren: [],
aggIndex: self.numberOfAggregates,
aggLabelFilter: g[NG_COLUMN].aggLabelFilter
}, 0);
self.numberOfAggregates++;
//set the aggregate parent to the parent in the array that is one less deep.
agg.parent = self.parentCache[agg.depth - 1];
// if we have a parent, set the parent to not be collapsed and append the current agg to its children
if (agg.parent) {
agg.parent.collapsed = false;
agg.parent.aggChildren.push(agg);
}
// add the aggregate row to the parsed data.
self.parsedData.push(agg);
// the current aggregate now the parent of the current depth
self.parentCache[agg.depth] = agg;
// dig deeper for more aggregates or children.
self.parseGroupData(g[prop]);
}
}
}
};
//Shuffle the data into their respective groupings.
self.getGrouping = function(groups) {
self.aggCache = [];
self.numberOfAggregates = 0;
self.groupedData = {};
// Here we set the onmousedown event handler to the header container.
var rows = grid.filteredRows,
maxDepth = groups.length,
cols = $scope.columns;
function filterCols(cols, group) {
return cols.filter(function(c) {
return c.field === group;
});
}
for (var x = 0; x < rows.length; x++) {
var model = rows[x].entity;
if (!model) {
return;
}
rows[x][NG_HIDDEN] = grid.config.groupsCollapsedByDefault;
var ptr = self.groupedData;
for (var y = 0; y < groups.length; y++) {
var group = groups[y];
var col = filterCols(cols, group)[0];
var val = $utils.evalProperty(model, group);
val = val ? val.toString() : 'null';
if (!ptr[val]) {
ptr[val] = {};
}
if (!ptr[NG_FIELD]) {
ptr[NG_FIELD] = group;
}
if (!ptr[NG_DEPTH]) {
ptr[NG_DEPTH] = y;
}
if (!ptr[NG_COLUMN]) {
ptr[NG_COLUMN] = col;
}
ptr = ptr[val];
}
if (!ptr.values) {
ptr.values = [];
}
ptr.values.push(rows[x]);
}
//moved out of above loops due to if no data initially, but has initial grouping, columns won't be added
if(cols.length > 0) {
for (var z = 0; z < groups.length; z++) {
if (!cols[z].isAggCol && z <= maxDepth) {
cols.splice(0, 0, new ngColumn({
colDef: {
field: '',
width: 25,
sortable: false,
resizable: false,
headerCellTemplate: '<div class="ngAggHeader"></div>',
pinned: grid.config.pinSelectionCheckbox
},
enablePinning: grid.config.enablePinning,
isAggCol: true,
headerRowHeight: grid.config.headerRowHeight
}, $scope, grid, domUtilityService, $templateCache, $utils));
}
}
}
grid.fixColumnIndexes();
$scope.adjustScrollLeft(0);
self.parsedData.length = 0;
self.parseGroupData(self.groupedData);
self.fixRowCache();
};
if (grid.config.groups.length > 0 && grid.filteredRows.length > 0) {
self.getGrouping(grid.config.groups);
}
};
var ngSearchProvider = function ($scope, grid, $filter) {
var self = this,
searchConditions = [];
self.extFilter = grid.config.filterOptions.useExternalFilter;
$scope.showFilter = grid.config.showFilter;
$scope.filterText = '';
self.fieldMap = {};
var convertToFieldMap = function(obj) {
var fieldMap = {};
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
fieldMap[prop.toLowerCase()] = obj[prop];
}
}
return fieldMap;
};
var searchEntireRow = function(condition, item, fieldMap){
var result;
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
var c = fieldMap[prop.toLowerCase()];
if (!c) {
continue;
}
var pVal = item[prop];
if(typeof pVal === 'object' && !(pVal instanceof Date)) {
var objectFieldMap = convertToFieldMap(c);
result = searchEntireRow(condition, pVal, objectFieldMap);
if (result) {
return true;
}
} else {
var f = null,
s = null;
if (c && c.cellFilter) {
s = c.cellFilter.split(':');
f = $filter(s[0]);
}
if (pVal !== null && pVal !== undefined) {
if (typeof f === "function") {
// Have to slice off the quotes the parser would have removed
var filterRes = f(pVal, s[1].slice(1,-1)).toString();
result = condition.regex.test(filterRes);
} else {
result = condition.regex.test(pVal.toString());
}
if (result) {
return true;
}
}
}
}
}
return false;
};
var searchColumn = function(condition, item){
var result;
var col = self.fieldMap[condition.columnDisplay];
if (!col) {
return false;
}
var sp = col.cellFilter.split(':');
var filter = col.cellFilter ? $filter(sp[0]) : null;
var value = item[condition.column] || item[col.field.split('.')[0]];
if (value === null || value === undefined) {
return false;
}
if (typeof filter === "function") {
var filterResults = filter(typeof value === "object" ? evalObject(value, col.field) : value, sp[1]).toString();
result = condition.regex.test(filterResults);
}
else {
result = condition.regex.test(typeof value === "object" ? evalObject(value, col.field).toString() : value.toString());
}
if (result) {
return true;
}
return false;
};
var filterFunc = function(item) {
for (var x = 0, len = searchConditions.length; x < len; x++) {
var condition = searchConditions[x];
var result;
if (!condition.column) {
result = searchEntireRow(condition, item, self.fieldMap);
} else {
result = searchColumn(condition, item);
}
if(!result) {
return false;
}
}
return true;
};
self.evalFilter = function () {
if (searchConditions.length === 0) {
grid.filteredRows = grid.rowCache;
} else {
grid.filteredRows = grid.rowCache.filter(function(row) {
return filterFunc(row.entity);
});
}
for (var i = 0; i < grid.filteredRows.length; i++)
{
grid.filteredRows[i].rowIndex = i;
}
grid.rowFactory.filteredRowsChanged();
};
//Traversing through the object to find the value that we want. If fail, then return the original object.
var evalObject = function (obj, columnName) {
if (typeof obj !== "object" || typeof columnName !== "string") {
return obj;
}
var args = columnName.split('.');
var cObj = obj;
if (args.length > 1) {
for (var i = 1, len = args.length; i < len; i++) {
cObj = cObj[args[i]];
if (!cObj) {
return obj;
}
}
return cObj;
}
return obj;
};
var getRegExp = function (str, modifiers) {
try {
return new RegExp(str, modifiers);
} catch (err) {
//Escape all RegExp metacharacters.
return new RegExp(str.replace(/(\^|\$|\(|\)|<|>|\[|\]|\{|\}|\\|\||\.|\*|\+|\?)/g, '\\$1'));
}
};
var buildSearchConditions = function (a) {
//reset.
searchConditions = [];
var qStr;
if (!(qStr = $.trim(a))) {
return;
}
var columnFilters = qStr.split(";");
for (var i = 0; i < columnFilters.length; i++) {
var args = columnFilters[i].split(':');
if (args.length > 1) {
var columnName = $.trim(args[0]);
var columnValue = $.trim(args[1]);
if (columnName && columnValue) {
searchConditions.push({
column: columnName,
columnDisplay: columnName.replace(/\s+/g, '').toLowerCase(),
regex: getRegExp(columnValue, 'i')
});
}
} else {
var val = $.trim(args[0]);
if (val) {
searchConditions.push({
column: '',
regex: getRegExp(val, 'i')
});
}
}
}
};
if (!self.extFilter) {
$scope.$on('$destroy', $scope.$watch('columns', function (cs) {
for (var i = 0; i < cs.length; i++) {
var col = cs[i];
if (col.field) {
if(col.field.match(/\./g)){
var properties = col.field.split('.');
var currentProperty = self.fieldMap;
for(var j = 0; j < properties.length - 1; j++) {
currentProperty[ properties[j] ] = currentProperty[ properties[j] ] || {};
currentProperty = currentProperty[properties[j]];
}
currentProperty[ properties[properties.length - 1] ] = col;
} else {
self.fieldMap[col.field.toLowerCase()] = col;
}
}
if (col.displayName) {
self.fieldMap[col.displayName.toLowerCase().replace(/\s+/g, '')] = col;
}
}
}));
}
$scope.$on('$destroy', $scope.$watch(
function () {
return grid.config.filterOptions.filterText;
},
function (a) {
$scope.filterText = a;
}
));
$scope.$on('$destroy', $scope.$watch('filterText', function(a){
if (!self.extFilter) {
$scope.$emit('ngGridEventFilter', a);
buildSearchConditions(a);
self.evalFilter();
}
}));
};
var ngSelectionProvider = function (grid, $scope, $parse) {
var self = this;
self.multi = grid.config.multiSelect;
self.selectedItems = grid.config.selectedItems;
self.selectedIndex = grid.config.selectedIndex;
self.lastClickedRow = undefined;
self.ignoreSelectedItemChanges = false; // flag to prevent circular event loops keeping single-select var in sync
self.pKeyParser = $parse(grid.config.primaryKey);
// function to manage the selection action of a data item (entity)
self.ChangeSelection = function (rowItem, evt) {
// ctrl-click + shift-click multi-selections
// up/down key navigation in multi-selections
var charCode = evt.which || evt.keyCode;
var isUpDownKeyPress = (charCode === 40 || charCode === 38);
if (evt && evt.shiftKey && !evt.keyCode && self.multi && grid.config.enableRowSelection) {
if (self.lastClickedRow) {
var rowsArr;
if ($scope.configGroups.length > 0) {
rowsArr = grid.rowFactory.parsedData.filter(function(row) {
return !row.isAggRow;
});
}
else {
rowsArr = grid.filteredRows;
}
var thisIndx = rowItem.rowIndex;
var prevIndx = self.lastClickedRowIndex;
if (thisIndx === prevIndx) {
return false;
}
if (thisIndx < prevIndx) {
thisIndx = thisIndx ^ prevIndx;
prevIndx = thisIndx ^ prevIndx;
thisIndx = thisIndx ^ prevIndx;
thisIndx--;
}
else {
prevIndx++;
}
var rows = [];
for (; prevIndx <= thisIndx; prevIndx++) {
rows.push(rowsArr[prevIndx]);
}
if (rows[rows.length - 1].beforeSelectionChange(rows, evt)) {
for (var i = 0; i < rows.length; i++) {
var ri = rows[i];
var selectionState = ri.selected;
ri.selected = !selectionState;
if (ri.clone) {
ri.clone.selected = ri.selected;
}
var index = self.selectedItems.indexOf(ri.entity);
if (index === -1) {
self.selectedItems.push(ri.entity);
}
else {
self.selectedItems.splice(index, 1);
}
}
rows[rows.length - 1].afterSelectionChange(rows, evt);
}
self.lastClickedRow = rowItem;
self.lastClickedRowIndex = rowItem.rowIndex;
return true;
}
}
else if (!self.multi) {
if (self.lastClickedRow === rowItem) {
self.setSelection(self.lastClickedRow, grid.config.keepLastSelected ? true : !rowItem.selected);
} else {
if (self.lastClickedRow) {
self.setSelection(self.lastClickedRow, false);
}
self.setSelection(rowItem, !rowItem.selected);
}
}
else if (!evt.keyCode || isUpDownKeyPress && !grid.config.selectWithCheckboxOnly) {
self.setSelection(rowItem, !rowItem.selected);
}
self.lastClickedRow = rowItem;
self.lastClickedRowIndex = rowItem.rowIndex;
return true;
};
self.getSelection = function (entity) {
return self.getSelectionIndex(entity) !== -1;
};
self.getSelectionIndex = function (entity) {
var index = -1;
if (grid.config.primaryKey) {
var val = self.pKeyParser(entity);
angular.forEach(self.selectedItems, function (c, k) {
if (val === self.pKeyParser(c)) {
index = k;
}
});
}
else {
index = self.selectedItems.indexOf(entity);
}
return index;
};
// just call this func and hand it the rowItem you want to select (or de-select)
self.setSelection = function (rowItem, isSelected) {
if(grid.config.enableRowSelection){
if (!isSelected) {
var indx = self.getSelectionIndex(rowItem.entity);
if (indx !== -1) {
self.selectedItems.splice(indx, 1);
}
}
else {
if (self.getSelectionIndex(rowItem.entity) === -1) {
if (!self.multi && self.selectedItems.length > 0) {
self.toggleSelectAll(false, true);
}
self.selectedItems.push(rowItem.entity);
}
}
rowItem.selected = isSelected;
if (rowItem.orig) {
rowItem.orig.selected = isSelected;
}
if (rowItem.clone) {
rowItem.clone.selected = isSelected;
}
rowItem.afterSelectionChange(rowItem);
}
};
// @return - boolean indicating if all items are selected or not
// @val - boolean indicating whether to select all/de-select all
self.toggleSelectAll = function (checkAll, bypass, selectFiltered) {
var rows = selectFiltered ? grid.filteredRows : grid.rowCache;
if (bypass || grid.config.beforeSelectionChange(rows, checkAll)) {
var selectedlength = self.selectedItems.length;
if (selectedlength > 0) {
self.selectedItems.length = 0;
}
for (var i = 0; i < rows.length; i++) {
rows[i].selected = checkAll;
if (rows[i].clone) {
rows[i].clone.selected = checkAll;
}
if (checkAll) {
self.selectedItems.push(rows[i].entity);
}
}
if (!bypass) {
grid.config.afterSelectionChange(rows, checkAll);
}
}
};
};
var ngStyleProvider = function($scope, grid) {
$scope.headerCellStyle = function(col) {
return { "height": col.headerRowHeight + "px" };
};
$scope.rowStyle = function (row) {
var ret = { "top": row.offsetTop + "px", "height": $scope.rowHeight + "px" };
if (row.isAggRow) {
ret.left = row.offsetLeft;
}
return ret;
};
$scope.canvasStyle = function() {
return { "height": grid.maxCanvasHt + "px" };
};
$scope.headerScrollerStyle = function() {
return { "height": grid.config.headerRowHeight + "px" };
};
$scope.topPanelStyle = function() {
return { "width": grid.rootDim.outerWidth + "px", "height": $scope.topPanelHeight() + "px" };
};
$scope.headerStyle = function() {
return { "width": grid.rootDim.outerWidth + "px", "height": grid.config.headerRowHeight + "px" };
};
$scope.groupPanelStyle = function () {
return { "width": grid.rootDim.outerWidth + "px", "height": "32px" };
};
$scope.viewportStyle = function() {
return { "width": grid.rootDim.outerWidth + "px", "height": $scope.viewportDimHeight() + "px" };
};
$scope.footerStyle = function() {
return { "width": grid.rootDim.outerWidth + "px", "height": $scope.footerRowHeight + "px" };
};
};
ngGridDirectives.directive('ngCellHasFocus', ['$domUtilityService',
function (domUtilityService) {
var focusOnInputElement = function($scope, elm) {
$scope.isFocused = true;
domUtilityService.digest($scope);
$scope.$broadcast('ngGridEventStartCellEdit');
$scope.$emit('ngGridEventStartCellEdit');
$scope.$on('$destroy', $scope.$on('ngGridEventEndCellEdit', function() {
$scope.isFocused = false;
domUtilityService.digest($scope);
}));
};
return function($scope, elm) {
var isFocused = false;
var isCellEditableOnMouseDown = false;
$scope.editCell = function() {
if(!$scope.enableCellEditOnFocus) {
setTimeout(function() {
focusOnInputElement($scope,elm);
}, 0);
}
};
function mousedown (evt) {
if($scope.enableCellEditOnFocus) {
isCellEditableOnMouseDown = true;
} else {
elm.focus();
}
return true;
}
function click (evt) {
if($scope.enableCellEditOnFocus) {
evt.preventDefault();
isCellEditableOnMouseDown = false;
focusOnInputElement($scope,elm);
}
}
elm.bind('mousedown', mousedown);
elm.bind('click', click);
function focus (evt) {
isFocused = true;
if($scope.enableCellEditOnFocus && !isCellEditableOnMouseDown) {
focusOnInputElement($scope,elm);
}
return true;
}
elm.bind('focus', focus);
function blur() {
isFocused = false;
return true;
}
elm.bind('blur', blur);
function keydown (evt) {
if(!$scope.enableCellEditOnFocus) {
if (isFocused && evt.keyCode !== 37 && evt.keyCode !== 38 && evt.keyCode !== 39 && evt.keyCode !== 40 && evt.keyCode !== 9 && !evt.shiftKey && evt.keyCode !== 13) {
focusOnInputElement($scope,elm);
}
if (isFocused && evt.shiftKey && (evt.keyCode >= 65 && evt.keyCode <= 90)) {
focusOnInputElement($scope, elm);
}
if (evt.keyCode === 27) {
elm.focus();
}
}
return true;
}
elm.bind('keydown', keydown);
elm.on('$destroy', function() {
elm.off('mousedown', mousedown);
elm.off('click', click);
elm.off('focus', focus);
elm.off('blur', blur);
elm.off('keydown', keydown);
});
};
}]);
ngGridDirectives.directive('ngCellText',
function () {
return function(scope, elm) {
function mouseover (evt) {
evt.preventDefault();
}
elm.bind('mouseover', mouseover);
function mouseleave(evt) {
evt.preventDefault();
}
elm.bind('mouseleave', mouseleave);
elm.on('$destroy', function() {
elm.off('mouseover', mouseover);
elm.off('mouseleave', mouseleave);
});
};
});
ngGridDirectives.directive('ngCell', ['$compile', '$domUtilityService', function ($compile, domUtilityService) {
var ngCell = {
scope: false,
compile: function() {
return {
pre: function($scope, iElement) {
var html;
var cellTemplate = $scope.col.cellTemplate.replace(COL_FIELD, 'row.entity.' + $scope.col.field);
if ($scope.col.enableCellEdit) {
html = $scope.col.cellEditTemplate;
html = html.replace(CELL_EDITABLE_CONDITION, $scope.col.cellEditableCondition);
html = html.replace(DISPLAY_CELL_TEMPLATE, cellTemplate);
html = html.replace(EDITABLE_CELL_TEMPLATE, $scope.col.editableCellTemplate.replace(COL_FIELD, 'row.entity.' + $scope.col.field));
} else {
html = cellTemplate;
}
var cellElement = $(html);
iElement.append(cellElement);
$compile(cellElement)($scope);
if ($scope.enableCellSelection && cellElement[0].className.indexOf('ngSelectionCell') === -1) {
cellElement[0].setAttribute('tabindex', 0);
cellElement.addClass('ngCellElement');
}
},
post: function($scope, iElement) {
if ($scope.enableCellSelection) {
$scope.domAccessProvider.selectionHandlers($scope, iElement);
}
$scope.$on('$destroy', $scope.$on('ngGridEventDigestCell', function() {
domUtilityService.digest($scope);
}));
}
};
}
};
return ngCell;
}]);
/*
* Defines the ui-if tag. This removes/adds an element from the dom depending on a condition
* Originally created by @tigbro, for the @jquery-mobile-angular-adapter
* https://github.com/tigbro/jquery-mobile-angular-adapter
*/
ngGridDirectives.directive('ngEditCellIf', [function () {
return {
transclude: 'element',
priority: 1000,
terminal: true,
restrict: 'A',
compile: function (e, a, transclude) {
return function (scope, element, attr) {
var childElement;
var childScope;
scope.$on('$destroy', scope.$watch(attr['ngEditCellIf'], function (newValue) {
if (childElement) {
childElement.remove();
childElement = undefined;
}
if (childScope) {
childScope.$destroy();
childScope = undefined;
}
if (newValue) {
childScope = scope.$new();
transclude(childScope, function (clone) {
childElement = clone;
element.after(clone);
});
}
}));
};
}
};
}]);
ngGridDirectives.directive('ngGridFooter', ['$compile', '$templateCache', function ($compile, $templateCache) {
var ngGridFooter = {
scope: false,
compile: function () {
return {
pre: function ($scope, iElement) {
if (iElement.children().length === 0) {
iElement.append($compile($templateCache.get($scope.gridId + 'footerTemplate.html'))($scope));
}
}
};
}
};
return ngGridFooter;
}]);
ngGridDirectives.directive('ngGridMenu', ['$compile', '$templateCache', function ($compile, $templateCache) {
var ngGridMenu = {
scope: false,
compile: function () {
return {
pre: function ($scope, iElement) {
if (iElement.children().length === 0) {
iElement.append($compile($templateCache.get($scope.gridId + 'menuTemplate.html'))($scope));
}
}
};
}
};
return ngGridMenu;
}]);
ngGridDirectives.directive('ngGrid', ['$compile', '$filter', '$templateCache', '$sortService', '$domUtilityService', '$utilityService', '$timeout', '$parse', '$http', '$q', function ($compile, $filter, $templateCache, sortService, domUtilityService, $utils, $timeout, $parse, $http, $q) {
var ngGridDirective = {
scope: true,
compile: function() {
return {
pre: function($scope, iElement, iAttrs) {
var $element = $(iElement);
var options = $scope.$eval(iAttrs.ngGrid);
options.gridDim = new ngDimension({ outerHeight: $($element).height(), outerWidth: $($element).width() });
var grid = new ngGrid($scope, options, sortService, domUtilityService, $filter, $templateCache, $utils, $timeout, $parse, $http, $q);
// Set up cleanup now in case something fails
$scope.$on('$destroy', function cleanOptions() {
options.gridDim = null;
options.selectRow = null;
options.selectItem = null;
options.selectAll = null;
options.selectVisible = null;
options.groupBy = null;
options.sortBy = null;
options.gridId = null;
options.ngGrid = null;
options.$gridScope = null;
options.$gridServices = null;
$scope.domAccessProvider.grid = null;
// Plugins should already have been killed as they are children of $scope
// Remove the grid's stylesheet from dom
angular.element(grid.styleSheet).remove();
grid.styleSheet = null;
});
return grid.init().then(function() {
// if columndefs are a string of a property ont he scope watch for changes and rebuild columns.
if (typeof options.columnDefs === "string") {
$scope.$on('$destroy', $scope.$parent.$watch(options.columnDefs, function (a) {
if (!a) {
grid.refreshDomSizes();
grid.buildColumns();
return;
}
// we have to set this to false in case we want to autogenerate columns with no initial data.
grid.lateBoundColumns = false;
$scope.columns = [];
grid.config.columnDefs = a;
grid.buildColumns();
grid.eventProvider.assignEvents();
domUtilityService.RebuildGrid($scope, grid);
}, true));
}
else {
grid.buildColumns();
}
// Watch totalServerItems if it's a string
if (typeof options.totalServerItems === "string") {
$scope.$on('$destroy', $scope.$parent.$watch(options.totalServerItems, function (newTotal, oldTotal) {
// If the newTotal is not defined (like during init, set the value to 0)
if (!angular.isDefined(newTotal)) {
$scope.totalServerItems = 0;
}
// Otherwise set the value to the new total
else {
$scope.totalServerItems = newTotal;
}
}));
}
// If it's NOT a string, then just set totalServerItems to 0 since they should only be setting this if using a string
else {
$scope.totalServerItems = 0;
}
// if it is a string we can watch for data changes. otherwise you won't be able to update the grid data
if (typeof options.data === "string") {
var dataWatcher = function (a) {
// make a temporary copy of the data
grid.data = $.extend([], a);
grid.rowFactory.fixRowCache();
angular.forEach(grid.data, function (item, j) {
var indx = grid.rowMap[j] || j;
if (grid.rowCache[indx]) {
grid.rowCache[indx].ensureEntity(item);
}
grid.rowMap[indx] = j;
});
grid.searchProvider.evalFilter();
grid.configureColumnWidths();
grid.refreshDomSizes();
if (grid.config.sortInfo.fields.length > 0) {
grid.sortColumnsInit();
$scope.$emit('ngGridEventSorted', grid.config.sortInfo);
}
$scope.$emit("ngGridEventData", grid.gridId);
};
$scope.$on('$destroy', $scope.$parent.$watch(options.data, dataWatcher));
$scope.$on('$destroy', $scope.$parent.$watch(options.data + '.length', function() {
dataWatcher($scope.$eval(options.data));
$scope.adjustScrollTop(grid.$viewport.scrollTop(), true);
}));
}
grid.footerController = new ngFooter($scope, grid);
//set the right styling on the container
iElement.addClass("ngGrid").addClass(grid.gridId.toString());
if (!options.enableHighlighting) {
iElement.addClass("unselectable");
}
if (options.jqueryUITheme) {
iElement.addClass('ui-widget');
}
iElement.append($compile($templateCache.get('gridTemplate.html'))($scope)); // make sure that if any of these change, we re-fire the calc logic
//walk the element's graph and the correct properties on the grid
domUtilityService.AssignGridContainers($scope, iElement, grid);
//now use the manager to assign the event handlers
grid.eventProvider = new ngEventProvider(grid, $scope, domUtilityService, $timeout);
// method for user to select a specific row programatically
options.selectRow = function (rowIndex, state) {
if (grid.rowCache[rowIndex]) {
if (grid.rowCache[rowIndex].clone) {
grid.rowCache[rowIndex].clone.setSelection(state ? true : false);
}
grid.rowCache[rowIndex].setSelection(state ? true : false);
}
};
// method for user to select the row by data item programatically
options.selectItem = function (itemIndex, state) {
options.selectRow(grid.rowMap[itemIndex], state);
};
// method for user to set the select all state.
options.selectAll = function (state) {
$scope.toggleSelectAll(state);
};
// method for user to set the select all state on visible items.
options.selectVisible = function (state) {
$scope.toggleSelectAll(state, true);
};
// method for user to set the groups programatically
options.groupBy = function (field) {
if (field) {
$scope.groupBy($scope.columns.filter(function(c) {
return c.field === field;
})[0]);
} else {
var arr = $.extend(true, [], $scope.configGroups);
angular.forEach(arr, $scope.groupBy);
}
};
// method for user to set the sort field programatically
options.sortBy = function (field) {
var col = $scope.columns.filter(function (c) {
return c.field === field;
})[0];
if (col) {
col.sort();
}
};
// the grid Id, entity, scope for convenience
options.gridId = grid.gridId;
options.ngGrid = grid;
options.$gridScope = $scope;
options.$gridServices = { SortService: sortService, DomUtilityService: domUtilityService, UtilityService: $utils };
$scope.$on('$destroy', $scope.$on('ngGridEventDigestGrid', function(){
domUtilityService.digest($scope.$parent);
}));
$scope.$on('$destroy', $scope.$on('ngGridEventDigestGridParent', function(){
domUtilityService.digest($scope.$parent);
}));
// set up the columns
$scope.$evalAsync(function() {
$scope.adjustScrollLeft(0);
});
//initialize plugins.
angular.forEach(options.plugins, function (p) {
if (typeof p === "function") {
p = new p(); //If p is a function, then we assume it is a class.
}
var newScope = $scope.$new();
p.init(newScope, grid, options.$gridServices);
options.plugins[$utils.getInstanceType(p)] = p;
$scope.$on('$destroy', function() {
newScope.$destroy();
});
});
//send initi finalize notification.
if (typeof options.init === "function") {
options.init(grid, $scope);
}
return null;
});
}
};
}
};
return ngGridDirective;
}]);
ngGridDirectives.directive('ngHeaderCell', ['$compile', function($compile) {
var ngHeaderCell = {
scope: false,
compile: function() {
return {
pre: function($scope, iElement) {
iElement.append($compile($scope.col.headerCellTemplate)($scope));
}
};
}
};
return ngHeaderCell;
}]);
ngGridDirectives.directive('ngHeaderRow', ['$compile', '$templateCache', function ($compile, $templateCache) {
var ngHeaderRow = {
scope: false,
compile: function () {
return {
pre: function ($scope, iElement) {
if (iElement.children().length === 0) {
iElement.append($compile($templateCache.get($scope.gridId + 'headerRowTemplate.html'))($scope));
}
}
};
}
};
return ngHeaderRow;
}]);
ngGridDirectives.directive('ngInput', [function() {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ngModel) {
// Store the initial cell value so we can reset to it if need be
var oldCellValue;
var dereg = scope.$watch('ngModel', function() {
oldCellValue = ngModel.$modelValue;
dereg(); // only run this watch once, we don't want to overwrite our stored value when the input changes
});
function keydown (evt) {
switch (evt.keyCode) {
case 37: // Left arrow
case 38: // Up arrow
case 39: // Right arrow
case 40: // Down arrow
evt.stopPropagation();
break;
case 27: // Esc (reset to old value)
if (!scope.$$phase) {
scope.$apply(function() {
ngModel.$setViewValue(oldCellValue);
elm.blur();
});
}
break;
case 13: // Enter (Leave Field)
if(scope.enableCellEditOnFocus && scope.totalFilteredItemsLength() - 1 > scope.row.rowIndex && scope.row.rowIndex > 0 || scope.col.enableCellEdit) {
elm.blur();
}
break;
}
return true;
}
elm.bind('keydown', keydown);
function click (evt) {
evt.stopPropagation();
}
elm.bind('click', click);
function mousedown (evt) {
evt.stopPropagation();
}
elm.bind('mousedown', mousedown);
elm.on('$destroy', function() {
elm.off('keydown', keydown);
elm.off('click', click);
elm.off('mousedown', mousedown);
});
scope.$on('$destroy', scope.$on('ngGridEventStartCellEdit', function () {
elm.focus();
elm.select();
}));
angular.element(elm).bind('blur', function () {
scope.$emit('ngGridEventEndCellEdit');
});
}
};
}]);
ngGridDirectives.directive('ngRow', ['$compile', '$domUtilityService', '$templateCache', function ($compile, domUtilityService, $templateCache) {
var ngRow = {
scope: false,
compile: function() {
return {
pre: function($scope, iElement) {
$scope.row.elm = iElement;
if ($scope.row.clone) {
$scope.row.clone.elm = iElement;
}
if ($scope.row.isAggRow) {
var html = $templateCache.get($scope.gridId + 'aggregateTemplate.html');
if ($scope.row.aggLabelFilter) {
html = html.replace(CUSTOM_FILTERS, '| ' + $scope.row.aggLabelFilter);
} else {
html = html.replace(CUSTOM_FILTERS, "");
}
iElement.append($compile(html)($scope));
} else {
iElement.append($compile($templateCache.get($scope.gridId + 'rowTemplate.html'))($scope));
}
$scope.$on('$destroy', $scope.$on('ngGridEventDigestRow', function(){
domUtilityService.digest($scope);
}));
}
};
}
};
return ngRow;
}]);
ngGridDirectives.directive('ngViewport', [function() {
return function($scope, elm) {
var isMouseWheelActive;
var prevScollLeft;
var prevScollTop = 0;
var ensureDigest = function() {
if (!$scope.$root.$$phase) {
$scope.$digest();
}
};
var scrollTimer;
function scroll (evt) {
var scrollLeft = evt.target.scrollLeft,
scrollTop = evt.target.scrollTop;
if ($scope.$headerContainer) {
$scope.$headerContainer.scrollLeft(scrollLeft);
}
$scope.adjustScrollLeft(scrollLeft);
$scope.adjustScrollTop(scrollTop);
if ($scope.forceSyncScrolling) {
ensureDigest();
} else {
clearTimeout(scrollTimer);
scrollTimer = setTimeout(ensureDigest, 150);
}
prevScollLeft = scrollLeft;
prevScollTop = scrollTop;
isMouseWheelActive = false;
return true;
}
elm.bind('scroll', scroll);
function mousewheel() {
isMouseWheelActive = true;
if (elm.focus) { elm.focus(); }
return true;
}
elm.bind("mousewheel DOMMouseScroll", mousewheel);
elm.on('$destroy', function() {
elm.off('scroll', scroll);
elm.off('mousewheel DOMMouseScroll', mousewheel);
});
if (!$scope.enableCellSelection) {
$scope.domAccessProvider.selectionHandlers($scope, elm);
}
};
}]);
window.ngGrid.i18n['da'] = {
ngAggregateLabel: 'artikler',
ngGroupPanelDescription: 'Grupér rækker udfra en kolonne ved at trække dens overskift hertil.',
ngSearchPlaceHolder: 'Søg...',
ngMenuText: 'Vælg kolonner:',
ngShowingItemsLabel: 'Viste rækker:',
ngTotalItemsLabel: 'Rækker totalt:',
ngSelectedItemsLabel: 'Valgte rækker:',
ngPageSizeLabel: 'Side størrelse:',
ngPagerFirstTitle: 'Første side',
ngPagerNextTitle: 'Næste side',
ngPagerPrevTitle: 'Forrige side',
ngPagerLastTitle: 'Sidste side'
};
window.ngGrid.i18n['de'] = {
ngAggregateLabel: 'eintrag',
ngGroupPanelDescription: 'Ziehen Sie eine Spaltenüberschrift hierhin um nach dieser Spalte zu gruppieren.',
ngSearchPlaceHolder: 'Suche...',
ngMenuText: 'Spalten auswählen:',
ngShowingItemsLabel: 'Zeige Einträge:',
ngTotalItemsLabel: 'Einträge gesamt:',
ngSelectedItemsLabel: 'Ausgewählte Einträge:',
ngPageSizeLabel: 'Einträge pro Seite:',
ngPagerFirstTitle: 'Erste Seite',
ngPagerNextTitle: 'Nächste Seite',
ngPagerPrevTitle: 'Vorherige Seite',
ngPagerLastTitle: 'Letzte Seite'
};
window.ngGrid.i18n['en'] = {
ngAggregateLabel: 'items',
ngGroupPanelDescription: 'Drag a column header here and drop it to group by that column.',
ngSearchPlaceHolder: 'Search...',
ngMenuText: 'Choose Columns:',
ngShowingItemsLabel: 'Showing Items:',
ngTotalItemsLabel: 'Total Items:',
ngSelectedItemsLabel: 'Selected Items:',
ngPageSizeLabel: 'Page Size:',
ngPagerFirstTitle: 'First Page',
ngPagerNextTitle: 'Next Page',
ngPagerPrevTitle: 'Previous Page',
ngPagerLastTitle: 'Last Page'
};
window.ngGrid.i18n['es'] = {
ngAggregateLabel: 'Artículos',
ngGroupPanelDescription: 'Arrastre un encabezado de columna aquí y soltarlo para agrupar por esa columna.',
ngSearchPlaceHolder: 'Buscar...',
ngMenuText: 'Elegir columnas:',
ngShowingItemsLabel: 'Artículos Mostrando:',
ngTotalItemsLabel: 'Artículos Totales:',
ngSelectedItemsLabel: 'Artículos Seleccionados:',
ngPageSizeLabel: 'Tamaño de Página:',
ngPagerFirstTitle: 'Primera Página',
ngPagerNextTitle: 'Página Siguiente',
ngPagerPrevTitle: 'Página Anterior',
ngPagerLastTitle: 'Última Página'
};
window.ngGrid.i18n['fa'] = {
ngAggregateLabel: 'موردها',
ngGroupPanelDescription: 'یک عنوان ستون اینجا را بردار و به گروهی از آن ستون بیانداز.',
ngSearchPlaceHolder: 'جستجو...',
ngMenuText: 'انتخاب ستون\u200cها:',
ngShowingItemsLabel: 'نمایش موردها:',
ngTotalItemsLabel: 'همهٔ موردها:',
ngSelectedItemsLabel: 'موردهای انتخاب\u200cشده:',
ngPageSizeLabel: 'اندازهٔ صفحه:',
ngPagerFirstTitle: 'صفحهٔ اول',
ngPagerNextTitle: 'صفحهٔ بعد',
ngPagerPrevTitle: 'صفحهٔ قبل',
ngPagerLastTitle: 'آخرین صفحه'
};
window.ngGrid.i18n['fr'] = {
ngAggregateLabel: 'articles',
ngGroupPanelDescription: 'Faites glisser un en-tête de colonne ici et déposez-le vers un groupe par cette colonne.',
ngSearchPlaceHolder: 'Recherche...',
ngMenuText: 'Choisir des colonnes:',
ngShowingItemsLabel: 'Articles Affichage des:',
ngTotalItemsLabel: 'Nombre total d\'articles:',
ngSelectedItemsLabel: 'Éléments Articles:',
ngPageSizeLabel: 'Taille de page:',
ngPagerFirstTitle: 'Première page',
ngPagerNextTitle: 'Page Suivante',
ngPagerPrevTitle: 'Page précédente',
ngPagerLastTitle: 'Dernière page'
};
window.ngGrid.i18n['nl'] = {
ngAggregateLabel: 'items',
ngGroupPanelDescription: 'Sleep hier een kolomkop om op te groeperen.',
ngSearchPlaceHolder: 'Zoeken...',
ngMenuText: 'Kies kolommen:',
ngShowingItemsLabel: 'Toon items:',
ngTotalItemsLabel: 'Totaal items:',
ngSelectedItemsLabel: 'Geselecteerde items:',
ngPageSizeLabel: 'Pagina grootte:, ',
ngPagerFirstTitle: 'Eerste pagina',
ngPagerNextTitle: 'Volgende pagina',
ngPagerPrevTitle: 'Vorige pagina',
ngPagerLastTitle: 'Laatste pagina'
};
window.ngGrid.i18n['pt-br'] = {
ngAggregateLabel: 'itens',
ngGroupPanelDescription: 'Arraste e solte uma coluna aqui para agrupar por essa coluna',
ngSearchPlaceHolder: 'Procurar...',
ngMenuText: 'Selecione as colunas:',
ngShowingItemsLabel: 'Mostrando os Itens:',
ngTotalItemsLabel: 'Total de Itens:',
ngSelectedItemsLabel: 'Items Selecionados:',
ngPageSizeLabel: 'Tamanho da Página:',
ngPagerFirstTitle: 'Primeira Página',
ngPagerNextTitle: 'Próxima Página',
ngPagerPrevTitle: 'Página Anterior',
ngPagerLastTitle: 'Última Página'
};
window.ngGrid.i18n['zh-cn'] = {
ngAggregateLabel: '条目',
ngGroupPanelDescription: '拖曳表头到此处以进行分组',
ngSearchPlaceHolder: '搜索...',
ngMenuText: '数据分组与选择列:',
ngShowingItemsLabel: '当前显示条目:',
ngTotalItemsLabel: '条目总数:',
ngSelectedItemsLabel: '选中条目:',
ngPageSizeLabel: '每页显示数:',
ngPagerFirstTitle: '回到首页',
ngPagerNextTitle: '下一页',
ngPagerPrevTitle: '上一页',
ngPagerLastTitle: '前往尾页'
};
window.ngGrid.i18n['zh-tw'] = {
ngAggregateLabel: '筆',
ngGroupPanelDescription: '拖拉表頭到此處以進行分組',
ngSearchPlaceHolder: '搜尋...',
ngMenuText: '選擇欄位:',
ngShowingItemsLabel: '目前顯示筆數:',
ngTotalItemsLabel: '總筆數:',
ngSelectedItemsLabel: '選取筆數:',
ngPageSizeLabel: '每頁顯示:',
ngPagerFirstTitle: '第一頁',
ngPagerNextTitle: '下一頁',
ngPagerPrevTitle: '上一頁',
ngPagerLastTitle: '最後頁'
};
angular.module('ngGrid').run(['$templateCache', function($templateCache) {
'use strict';
$templateCache.put('aggregateTemplate.html',
"<div ng-click=\"row.toggleExpand()\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">\r" +
"\n" +
" <span class=\"ngAggregateText\">{{row.label CUSTOM_FILTERS}} ({{row.totalChildren()}} {{AggItemsLabel}})</span>\r" +
"\n" +
" <div class=\"{{row.aggClass()}}\"></div>\r" +
"\n" +
"</div>\r" +
"\n"
);
$templateCache.put('cellEditTemplate.html',
"<div ng-cell-has-focus ng-dblclick=\"CELL_EDITABLE_CONDITION && editCell()\">\r" +
"\n" +
"\t<div ng-edit-cell-if=\"!(isFocused && CELL_EDITABLE_CONDITION)\">\t\r" +
"\n" +
"\t\tDISPLAY_CELL_TEMPLATE\r" +
"\n" +
"\t</div>\r" +
"\n" +
"\t<div ng-edit-cell-if=\"isFocused && CELL_EDITABLE_CONDITION\">\r" +
"\n" +
"\t\tEDITABLE_CELL_TEMPLATE\r" +
"\n" +
"\t</div>\r" +
"\n" +
"</div>\r" +
"\n"
);
$templateCache.put('cellTemplate.html',
"<div class=\"ngCellText\" ng-class=\"col.colIndex()\"><span ng-cell-text>{{COL_FIELD CUSTOM_FILTERS}}</span></div>"
);
$templateCache.put('checkboxCellTemplate.html',
"<div class=\"ngSelectionCell\"><input tabindex=\"-1\" class=\"ngSelectionCheckbox\" type=\"checkbox\" ng-checked=\"row.selected\" /></div>"
);
$templateCache.put('checkboxHeaderTemplate.html',
"<input class=\"ngSelectionHeader\" type=\"checkbox\" ng-show=\"multiSelect\" ng-model=\"allSelected\" ng-change=\"toggleSelectAll(allSelected, true)\"/>"
);
$templateCache.put('editableCellTemplate.html',
"<input ng-class=\"'colt' + col.index\" ng-input=\"COL_FIELD\" ng-model=\"COL_FIELD\" />"
);
$templateCache.put('footerTemplate.html',
"<div ng-show=\"showFooter\" class=\"ngFooterPanel\" ng-class=\"{'ui-widget-content': jqueryUITheme, 'ui-corner-bottom': jqueryUITheme}\" ng-style=\"footerStyle()\">\r" +
"\n" +
" <div class=\"ngTotalSelectContainer\" >\r" +
"\n" +
" <div class=\"ngFooterTotalItems\" ng-class=\"{'ngNoMultiSelect': !multiSelect}\" >\r" +
"\n" +
" <span class=\"ngLabel\">{{i18n.ngTotalItemsLabel}} {{maxRows()}}</span><span ng-show=\"filterText.length > 0\" class=\"ngLabel\">({{i18n.ngShowingItemsLabel}} {{totalFilteredItemsLength()}})</span>\r" +
"\n" +
" </div>\r" +
"\n" +
" <div class=\"ngFooterSelectedItems\" ng-show=\"multiSelect\">\r" +
"\n" +
" <span class=\"ngLabel\">{{i18n.ngSelectedItemsLabel}} {{selectedItems.length}}</span>\r" +
"\n" +
" </div>\r" +
"\n" +
" </div>\r" +
"\n" +
" <div class=\"ngPagerContainer\" style=\"float: right; margin-top: 10px;\" ng-show=\"enablePaging\" ng-class=\"{'ngNoMultiSelect': !multiSelect}\">\r" +
"\n" +
" <div style=\"float:left; margin-right: 10px;\" class=\"ngRowCountPicker\">\r" +
"\n" +
" <span style=\"float: left; margin-top: 3px;\" class=\"ngLabel\">{{i18n.ngPageSizeLabel}}</span>\r" +
"\n" +
" <select style=\"float: left;height: 27px; width: 100px\" ng-model=\"pagingOptions.pageSize\" >\r" +
"\n" +
" <option ng-repeat=\"size in pagingOptions.pageSizes\">{{size}}</option>\r" +
"\n" +
" </select>\r" +
"\n" +
" </div>\r" +
"\n" +
" <div style=\"float:left; margin-right: 10px; line-height:25px;\" class=\"ngPagerControl\" style=\"float: left; min-width: 135px;\">\r" +
"\n" +
" <button type=\"button\" class=\"ngPagerButton\" ng-click=\"pageToFirst()\" ng-disabled=\"cantPageBackward()\" title=\"{{i18n.ngPagerFirstTitle}}\"><div class=\"ngPagerFirstTriangle\"><div class=\"ngPagerFirstBar\"></div></div></button>\r" +
"\n" +
" <button type=\"button\" class=\"ngPagerButton\" ng-click=\"pageBackward()\" ng-disabled=\"cantPageBackward()\" title=\"{{i18n.ngPagerPrevTitle}}\"><div class=\"ngPagerFirstTriangle ngPagerPrevTriangle\"></div></button>\r" +
"\n" +
" <input class=\"ngPagerCurrent\" min=\"1\" max=\"{{currentMaxPages}}\" type=\"number\" style=\"width:50px; height: 24px; margin-top: 1px; padding: 0 4px;\" ng-model=\"pagingOptions.currentPage\"/>\r" +
"\n" +
" <span class=\"ngGridMaxPagesNumber\" ng-show=\"maxPages() > 0\">/ {{maxPages()}}</span>\r" +
"\n" +
" <button type=\"button\" class=\"ngPagerButton\" ng-click=\"pageForward()\" ng-disabled=\"cantPageForward()\" title=\"{{i18n.ngPagerNextTitle}}\"><div class=\"ngPagerLastTriangle ngPagerNextTriangle\"></div></button>\r" +
"\n" +
" <button type=\"button\" class=\"ngPagerButton\" ng-click=\"pageToLast()\" ng-disabled=\"cantPageToLast()\" title=\"{{i18n.ngPagerLastTitle}}\"><div class=\"ngPagerLastTriangle\"><div class=\"ngPagerLastBar\"></div></div></button>\r" +
"\n" +
" </div>\r" +
"\n" +
" </div>\r" +
"\n" +
"</div>\r" +
"\n"
);
$templateCache.put('gridTemplate.html',
"<div class=\"ngTopPanel\" ng-class=\"{'ui-widget-header':jqueryUITheme, 'ui-corner-top': jqueryUITheme}\" ng-style=\"topPanelStyle()\">\r" +
"\n" +
" <div class=\"ngGroupPanel\" ng-show=\"showGroupPanel()\" ng-style=\"groupPanelStyle()\">\r" +
"\n" +
" <div class=\"ngGroupPanelDescription\" ng-show=\"configGroups.length == 0\">{{i18n.ngGroupPanelDescription}}</div>\r" +
"\n" +
" <ul ng-show=\"configGroups.length > 0\" class=\"ngGroupList\">\r" +
"\n" +
" <li class=\"ngGroupItem\" ng-repeat=\"group in configGroups\">\r" +
"\n" +
" <span class=\"ngGroupElement\">\r" +
"\n" +
" <span class=\"ngGroupName\">{{group.displayName}}\r" +
"\n" +
" <span ng-click=\"removeGroup($index)\" class=\"ngRemoveGroup\">x</span>\r" +
"\n" +
" </span>\r" +
"\n" +
" <span ng-hide=\"$last\" class=\"ngGroupArrow\"></span>\r" +
"\n" +
" </span>\r" +
"\n" +
" </li>\r" +
"\n" +
" </ul>\r" +
"\n" +
" </div>\r" +
"\n" +
" <div class=\"ngHeaderContainer\" ng-style=\"headerStyle()\">\r" +
"\n" +
" <div ng-header-row class=\"ngHeaderScroller\" ng-style=\"headerScrollerStyle()\"></div>\r" +
"\n" +
" </div>\r" +
"\n" +
" <div ng-grid-menu></div>\r" +
"\n" +
"</div>\r" +
"\n" +
"<div class=\"ngViewport\" unselectable=\"on\" ng-viewport ng-class=\"{'ui-widget-content': jqueryUITheme}\" ng-style=\"viewportStyle()\">\r" +
"\n" +
" <div class=\"ngCanvas\" ng-style=\"canvasStyle()\">\r" +
"\n" +
" <div ng-style=\"rowStyle(row)\" ng-repeat=\"row in renderedRows\" ng-click=\"row.toggleSelected($event)\" ng-class=\"row.alternatingRowClass()\" ng-row></div>\r" +
"\n" +
" </div>\r" +
"\n" +
"</div>\r" +
"\n" +
"<div ng-grid-footer></div>\r" +
"\n"
);
$templateCache.put('headerCellTemplate.html',
"<div class=\"ngHeaderSortColumn {{col.headerClass}}\" ng-style=\"{'cursor': col.cursor}\" ng-class=\"{ 'ngSorted': !col.noSortVisible() }\">\r" +
"\n" +
" <div ng-click=\"col.sort($event)\" ng-class=\"'colt' + col.index\" class=\"ngHeaderText\">{{col.displayName}}</div>\r" +
"\n" +
" <div class=\"ngSortButtonDown\" ng-click=\"col.sort($event)\" ng-show=\"col.showSortButtonDown()\"></div>\r" +
"\n" +
" <div class=\"ngSortButtonUp\" ng-click=\"col.sort($event)\" ng-show=\"col.showSortButtonUp()\"></div>\r" +
"\n" +
" <div class=\"ngSortPriority\">{{col.sortPriority}}</div>\r" +
"\n" +
" <div ng-class=\"{ ngPinnedIcon: col.pinned, ngUnPinnedIcon: !col.pinned }\" ng-click=\"togglePin(col)\" ng-show=\"col.pinnable\"></div>\r" +
"\n" +
"</div>\r" +
"\n" +
"<div ng-show=\"col.resizable\" class=\"ngHeaderGrip\" ng-click=\"col.gripClick($event)\" ng-mousedown=\"col.gripOnMouseDown($event)\"></div>\r" +
"\n"
);
$templateCache.put('headerRowTemplate.html',
"<div ng-style=\"{ height: col.headerRowHeight }\" ng-repeat=\"col in renderedColumns\" ng-class=\"col.colIndex()\" class=\"ngHeaderCell\">\r" +
"\n" +
"\t<div class=\"ngVerticalBar\" ng-style=\"{height: col.headerRowHeight}\" ng-class=\"{ ngVerticalBarVisible: !$last }\"> </div>\r" +
"\n" +
"\t<div ng-header-cell></div>\r" +
"\n" +
"</div>"
);
$templateCache.put('menuTemplate.html',
"<div ng-show=\"showColumnMenu || showFilter\" class=\"ngHeaderButton\" ng-click=\"toggleShowMenu()\">\r" +
"\n" +
" <div class=\"ngHeaderButtonArrow\"></div>\r" +
"\n" +
"</div>\r" +
"\n" +
"<div ng-show=\"showMenu\" class=\"ngColMenu\">\r" +
"\n" +
" <div ng-show=\"showFilter\">\r" +
"\n" +
" <input placeholder=\"{{i18n.ngSearchPlaceHolder}}\" type=\"text\" ng-model=\"filterOptions.filterText\"/>\r" +
"\n" +
" </div>\r" +
"\n" +
" <div ng-show=\"showColumnMenu\">\r" +
"\n" +
" <span class=\"ngMenuText\">{{i18n.ngMenuText}}</span>\r" +
"\n" +
" <ul class=\"ngColList\">\r" +
"\n" +
" <li class=\"ngColListItem\" ng-repeat=\"col in columns | ngColumns\">\r" +
"\n" +
" <label><input ng-disabled=\"col.pinned\" type=\"checkbox\" class=\"ngColListCheckbox\" ng-model=\"col.visible\"/>{{col.displayName}}</label>\r" +
"\n" +
"\t\t\t\t<a title=\"Group By\" ng-class=\"col.groupedByClass()\" ng-show=\"col.groupable && col.visible\" ng-click=\"groupBy(col)\"></a>\r" +
"\n" +
"\t\t\t\t<span class=\"ngGroupingNumber\" ng-show=\"col.groupIndex > 0\">{{col.groupIndex}}</span> \r" +
"\n" +
" </li>\r" +
"\n" +
" </ul>\r" +
"\n" +
" </div>\r" +
"\n" +
"</div>\r" +
"\n"
);
$templateCache.put('rowTemplate.html',
"<div ng-style=\"{ 'cursor': row.cursor }\" ng-repeat=\"col in renderedColumns\" ng-class=\"col.colIndex()\" class=\"ngCell {{col.cellClass}}\">\r" +
"\n" +
"\t<div class=\"ngVerticalBar\" ng-style=\"{height: rowHeight}\" ng-class=\"{ ngVerticalBarVisible: !$last }\"> </div>\r" +
"\n" +
"\t<div ng-cell></div>\r" +
"\n" +
"</div>"
);
}]);
}(window, jQuery));