dataTables.searchPanes.js
130 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
/*! SearchPanes 1.2.1
* 2019-2020 SpryMedia Ltd - datatables.net/license
*/
(function () {
'use strict';
var $;
var DataTable;
function setJQuery(jq) {
$ = jq;
DataTable = jq.fn.dataTable;
}
var SearchPane = /** @class */ (function () {
/**
* Creates the panes, sets up the search function
* @param paneSettings The settings for the searchPanes
* @param opts The options for the default features
* @param idx the index of the column for this pane
* @returns {object} the pane that has been created, including the table and the index of the pane
*/
function SearchPane(paneSettings, opts, idx, layout, panesContainer, panes) {
var _this = this;
if (panes === void 0) { panes = null; }
// Check that the required version of DataTables is included
if (!DataTable || !DataTable.versionCheck || !DataTable.versionCheck('1.10.0')) {
throw new Error('SearchPane requires DataTables 1.10 or newer');
}
// Check that Select is included
if (!DataTable.select) {
throw new Error('SearchPane requires Select');
}
var table = new DataTable.Api(paneSettings);
this.classes = $.extend(true, {}, SearchPane.classes);
// Get options from user
this.c = $.extend(true, {}, SearchPane.defaults, opts);
this.customPaneSettings = panes;
this.s = {
cascadeRegen: false,
clearing: false,
colOpts: [],
deselect: false,
displayed: false,
dt: table,
dtPane: undefined,
filteringActive: false,
index: idx,
indexes: [],
lastCascade: false,
lastSelect: false,
listSet: false,
name: undefined,
redraw: false,
rowData: {
arrayFilter: [],
arrayOriginal: [],
arrayTotals: [],
bins: {},
binsOriginal: {},
binsTotal: {},
filterMap: new Map(),
totalOptions: 0
},
scrollTop: 0,
searchFunction: undefined,
selectPresent: false,
serverSelect: [],
serverSelecting: false,
showFiltered: false,
tableLength: null,
updating: false
};
var rowLength = table.columns().eq(0).toArray().length;
this.colExists = this.s.index < rowLength;
// Add extra elements to DOM object including clear and hide buttons
this.c.layout = layout;
var layVal = parseInt(layout.split('-')[1], 10);
this.dom = {
buttonGroup: $('<div/>').addClass(this.classes.buttonGroup),
clear: $('<button type="button">×</button>')
.addClass(this.classes.dull)
.addClass(this.classes.paneButton)
.addClass(this.classes.clearButton),
container: $('<div/>').addClass(this.classes.container).addClass(this.classes.layout +
(layVal < 10 ? layout : layout.split('-')[0] + '-9')),
countButton: $('<button type="button"></button>')
.addClass(this.classes.paneButton)
.addClass(this.classes.countButton),
dtP: $('<table><thead><tr><th>' +
(this.colExists
? $(table.column(this.colExists ? this.s.index : 0).header()).text()
: this.customPaneSettings.header || 'Custom Pane') + '</th><th/></tr></thead></table>'),
lower: $('<div/>').addClass(this.classes.subRow2).addClass(this.classes.narrowButton),
nameButton: $('<button type="button"></button>').addClass(this.classes.paneButton).addClass(this.classes.nameButton),
panesContainer: panesContainer,
searchBox: $('<input/>').addClass(this.classes.paneInputButton).addClass(this.classes.search),
searchButton: $('<button type = "button" class="' + this.classes.searchIcon + '"></button>')
.addClass(this.classes.paneButton),
searchCont: $('<div/>').addClass(this.classes.searchCont),
searchLabelCont: $('<div/>').addClass(this.classes.searchLabelCont),
topRow: $('<div/>').addClass(this.classes.topRow),
upper: $('<div/>').addClass(this.classes.subRow1).addClass(this.classes.narrowSearch)
};
this.s.displayed = false;
table = this.s.dt;
this.selections = [];
this.s.colOpts = this.colExists ? this._getOptions() : this._getBonusOptions();
var colOpts = this.s.colOpts;
var clear = $('<button type="button">X</button>').addClass(this.classes.paneButton);
$(clear).text(table.i18n('searchPanes.clearPane', 'X'));
this.dom.container.addClass(colOpts.className);
this.dom.container.addClass((this.customPaneSettings !== null && this.customPaneSettings.className !== undefined)
? this.customPaneSettings.className
: '');
// Set the value of name incase ordering is desired
if (this.s.colOpts.name !== undefined) {
this.s.name = this.s.colOpts.name;
}
else if (this.customPaneSettings !== null && this.customPaneSettings.name !== undefined) {
this.s.name = this.customPaneSettings.name;
}
else {
this.s.name = this.colExists ?
$(table.column(this.s.index).header()).text() :
this.customPaneSettings.header || 'Custom Pane';
}
$(panesContainer).append(this.dom.container);
var tableNode = table.table(0).node();
// Custom search function for table
this.s.searchFunction = function (settings, searchData, dataIndex, origData) {
// If no data has been selected then show all
if (_this.selections.length === 0) {
return true;
}
if (settings.nTable !== tableNode) {
return true;
}
var filter = null;
if (_this.colExists) {
// Get the current filtered data
filter = searchData[_this.s.index];
if (colOpts.orthogonal.filter !== 'filter') {
// get the filter value from the map
filter = _this.s.rowData.filterMap.get(dataIndex);
if (filter instanceof $.fn.dataTable.Api) {
filter = filter.toArray();
}
}
}
return _this._search(filter, dataIndex);
};
$.fn.dataTable.ext.search.push(this.s.searchFunction);
// If the clear button for this pane is clicked clear the selections
if (this.c.clear) {
$(clear).on('click', function () {
var searches = _this.dom.container.find(_this.classes.search);
searches.each(function () {
$(this).val('');
$(this).trigger('input');
});
_this.clearPane();
});
}
// Sometimes the top row of the panes containing the search box and ordering buttons appears
// weird if the width of the panes is lower than expected, this fixes the design.
// Equally this may occur when the table is resized.
table.on('draw.dtsp', function () {
_this._adjustTopRow();
});
table.on('buttons-action', function () {
_this._adjustTopRow();
});
$(window).on('resize.dtsp', DataTable.util.throttle(function () {
_this._adjustTopRow();
}));
// When column-reorder is present and the columns are moved, it is necessary to
// reassign all of the panes indexes to the new index of the column.
table.on('column-reorder.dtsp', function (e, settings, details) {
_this.s.index = details.mapping[_this.s.index];
});
return this;
}
/**
* In the case of a rebuild there is potential for new data to have been included or removed
* so all of the rowData must be reset as a precaution.
*/
SearchPane.prototype.clearData = function () {
this.s.rowData = {
arrayFilter: [],
arrayOriginal: [],
arrayTotals: [],
bins: {},
binsOriginal: {},
binsTotal: {},
filterMap: new Map(),
totalOptions: 0
};
};
/**
* Clear the selections in the pane
*/
SearchPane.prototype.clearPane = function () {
// Deselect all rows which are selected and update the table and filter count.
this.s.dtPane.rows({ selected: true }).deselect();
this.updateTable();
return this;
};
/**
* Strips all of the SearchPanes elements from the document and turns all of the listeners for the buttons off
*/
SearchPane.prototype.destroy = function () {
$(this.s.dtPane).off('.dtsp');
$(this.s.dt).off('.dtsp');
$(this.dom.nameButton).off('.dtsp');
$(this.dom.countButton).off('.dtsp');
$(this.dom.clear).off('.dtsp');
$(this.dom.searchButton).off('.dtsp');
$(this.dom.container).remove();
var searchIdx = $.fn.dataTable.ext.search.indexOf(this.s.searchFunction);
while (searchIdx !== -1) {
$.fn.dataTable.ext.search.splice(searchIdx, 1);
searchIdx = $.fn.dataTable.ext.search.indexOf(this.s.searchFunction);
}
// If the datatables have been defined for the panes then also destroy these
if (this.s.dtPane !== undefined) {
this.s.dtPane.destroy();
}
this.s.listSet = false;
};
/**
* Updates the number of filters that have been applied in the title
*/
SearchPane.prototype.getPaneCount = function () {
return this.s.dtPane !== undefined ?
this.s.dtPane.rows({ selected: true }).data().toArray().length :
0;
};
/**
* Rebuilds the panes from the start having deleted the old ones
* @param? last boolean to indicate if this is the last pane a selection was made in
* @param? dataIn data to be used in buildPane
* @param? init Whether this is the initial draw or not
* @param? maintainSelection Whether the current selections are to be maintained over rebuild
*/
SearchPane.prototype.rebuildPane = function (last, dataIn, init, maintainSelection) {
if (last === void 0) { last = false; }
if (dataIn === void 0) { dataIn = null; }
if (init === void 0) { init = null; }
if (maintainSelection === void 0) { maintainSelection = false; }
this.clearData();
var selectedRows = [];
this.s.serverSelect = [];
var prevEl = null;
// When rebuilding strip all of the HTML Elements out of the container and start from scratch
if (this.s.dtPane !== undefined) {
if (maintainSelection) {
if (!this.s.dt.page.info().serverSide) {
selectedRows = this.s.dtPane.rows({ selected: true }).data().toArray();
}
else {
this.s.serverSelect = this.s.dtPane.rows({ selected: true }).data().toArray();
}
}
this.s.dtPane.clear().destroy();
prevEl = $(this.dom.container).prev();
this.destroy();
this.s.dtPane = undefined;
$.fn.dataTable.ext.search.push(this.s.searchFunction);
}
this.dom.container.removeClass(this.classes.hidden);
this.s.displayed = false;
this._buildPane(!this.s.dt.page.info().serverSide ?
selectedRows :
this.s.serverSelect, last, dataIn, init, prevEl);
return this;
};
/**
* removes the pane from the page and sets the displayed property to false.
*/
SearchPane.prototype.removePane = function () {
this.s.displayed = false;
$(this.dom.container).hide();
};
/**
* Sets the cascadeRegen property of the pane. Accessible from above because as SearchPanes.ts deals with the rebuilds.
* @param val the boolean value that the cascadeRegen property is to be set to
*/
SearchPane.prototype.setCascadeRegen = function (val) {
this.s.cascadeRegen = val;
};
/**
* This function allows the clearing property to be assigned. This is used when implementing cascadePane.
* In setting this to true for the clearing of the panes selection on the deselects it forces the pane to
* repopulate from the entire dataset not just the displayed values.
* @param val the boolean value which the clearing property is to be assigned
*/
SearchPane.prototype.setClear = function (val) {
this.s.clearing = val;
};
/**
* Updates the values of all of the panes
* @param draw whether this has been triggered by a draw event or not
*/
SearchPane.prototype.updatePane = function (draw) {
if (draw === void 0) { draw = false; }
this.s.updating = true;
this._updateCommon(draw);
this.s.updating = false;
};
/**
* Updates the panes if one of the options to do so has been set to true
* rather than the filtered message when using viewTotal.
*/
SearchPane.prototype.updateTable = function () {
var selectedRows = this.s.dtPane.rows({ selected: true }).data().toArray();
this.selections = selectedRows;
this._searchExtras();
// If either of the options that effect how the panes are displayed are selected then update the Panes
if (this.c.cascadePanes || this.c.viewTotal) {
this.updatePane();
}
};
/**
* Sets the listeners for the pane.
*
* Having it in it's own function makes it easier to only set them once
*/
SearchPane.prototype._setListeners = function () {
var _this = this;
var rowData = this.s.rowData;
var t0;
// When an item is selected on the pane, add these to the array which holds selected items.
// Custom search will perform.
this.s.dtPane.on('select.dtsp', function () {
clearTimeout(t0);
if (_this.s.dt.page.info().serverSide && !_this.s.updating) {
if (!_this.s.serverSelecting) {
_this.s.serverSelect = _this.s.dtPane.rows({ selected: true }).data().toArray();
_this.s.scrollTop = $(_this.s.dtPane.table().node()).parent()[0].scrollTop;
_this.s.selectPresent = true;
_this.s.dt.draw(false);
}
}
else {
$(_this.dom.clear).removeClass(_this.classes.dull);
_this.s.selectPresent = true;
if (!_this.s.updating) {
_this._makeSelection();
}
_this.s.selectPresent = false;
}
});
// When an item is deselected on the pane, re add the currently selected items to the array
// which holds selected items. Custom search will be performed.
this.s.dtPane.on('deselect.dtsp', function () {
t0 = setTimeout(function () {
if (_this.s.dt.page.info().serverSide && !_this.s.updating) {
if (!_this.s.serverSelecting) {
_this.s.serverSelect = _this.s.dtPane.rows({ selected: true }).data().toArray();
_this.s.deselect = true;
_this.s.dt.draw(false);
}
}
else {
_this.s.deselect = true;
if (_this.s.dtPane.rows({ selected: true }).data().toArray().length === 0) {
$(_this.dom.clear).addClass(_this.classes.dull);
}
_this._makeSelection();
_this.s.deselect = false;
_this.s.dt.state.save();
}
}, 50);
});
// When saving the state store all of the selected rows for preselection next time around
this.s.dt.on('stateSaveParams.dtsp', function (e, settings, data) {
// If the data being passed in is empty then a state clear must have occured so clear the panes state as well
if ($.isEmptyObject(data)) {
_this.s.dtPane.state.clear();
return;
}
var selected = [];
var searchTerm;
var order;
var bins;
var arrayFilter;
// Get all of the data needed for the state save from the pane
if (_this.s.dtPane !== undefined) {
selected = _this.s.dtPane.rows({ selected: true }).data().map(function (item) { return item.filter.toString(); }).toArray();
searchTerm = $(_this.dom.searchBox).val();
order = _this.s.dtPane.order();
bins = rowData.binsOriginal;
arrayFilter = rowData.arrayOriginal;
}
if (data.searchPanes === undefined) {
data.searchPanes = {};
}
if (data.searchPanes.panes === undefined) {
data.searchPanes.panes = [];
}
for (var i = 0; i < data.searchPanes.panes.length; i++) {
if (data.searchPanes.panes[i].id === _this.s.index) {
data.searchPanes.panes.splice(i, 1);
i--;
}
}
// Add the panes data to the state object
data.searchPanes.panes.push({
arrayFilter: arrayFilter,
bins: bins,
id: _this.s.index,
order: order,
searchTerm: searchTerm,
selected: selected
});
});
this.s.dtPane.on('user-select.dtsp', function (e, _dt, type, cell, originalEvent) {
originalEvent.stopPropagation();
});
this.s.dtPane.on('draw.dtsp', function () {
_this._adjustTopRow();
});
// When the button to order by the name of the options is clicked then
// change the ordering to whatever it isn't currently
$(this.dom.nameButton).on('click.dtsp', function () {
var currentOrder = _this.s.dtPane.order()[0][1];
_this.s.dtPane.order([0, currentOrder === 'asc' ? 'desc' : 'asc']).draw();
_this.s.dt.state.save();
});
// When the button to order by the number of entries in the column is clicked then
// change the ordering to whatever it isn't currently
$(this.dom.countButton).on('click.dtsp', function () {
var currentOrder = _this.s.dtPane.order()[0][1];
_this.s.dtPane.order([1, currentOrder === 'asc' ? 'desc' : 'asc']).draw();
_this.s.dt.state.save();
});
// When the clear button is clicked reset the pane
$(this.dom.clear).on('click.dtsp', function () {
var searches = _this.dom.container.find('.' + _this.classes.search);
searches.each(function () {
// set the value of the search box to be an empty string and then search on that, effectively reseting
$(this).val('');
$(this).trigger('input');
});
_this.clearPane();
});
// When the search button is clicked then draw focus to the search box
$(this.dom.searchButton).on('click.dtsp', function () {
$(_this.dom.searchBox).focus();
});
// When a character is inputted into the searchbox search the pane for matching values.
// Doing it this way means that no button has to be clicked to trigger a search, it is done asynchronously
$(this.dom.searchBox).on('input.dtsp', function () {
_this.s.dtPane.search($(_this.dom.searchBox).val()).draw();
_this.s.dt.state.save();
});
// Make sure to save the state once the pane has been built
this.s.dt.state.save();
return true;
};
/**
* Takes in potentially undetected rows and adds them to the array if they are not yet featured
* @param filter the filter value of the potential row
* @param display the display value of the potential row
* @param sort the sort value of the potential row
* @param type the type value of the potential row
* @param arrayFilter the array to be populated
* @param bins the bins to be populated
*/
SearchPane.prototype._addOption = function (filter, display, sort, type, arrayFilter, bins) {
// If the filter is an array then take a note of this, and add the elements to the arrayFilter array
if (Array.isArray(filter) || filter instanceof DataTable.Api) {
// Convert to an array so that we can work with it
if (filter instanceof DataTable.Api) {
filter = filter.toArray();
display = display.toArray();
}
if (filter.length === display.length) {
for (var i = 0; i < filter.length; i++) {
// If we haven't seen this row before add it
if (!bins[filter[i]]) {
bins[filter[i]] = 1;
arrayFilter.push({
display: display[i],
filter: filter[i],
sort: sort[i],
type: type[i]
});
}
// Otherwise just increment the count
else {
bins[filter[i]]++;
}
this.s.rowData.totalOptions++;
}
return;
}
else {
throw new Error('display and filter not the same length');
}
}
// If the values were affected by othogonal data and are not an array then check if it is already present
else if (typeof this.s.colOpts.orthogonal === 'string') {
if (!bins[filter]) {
bins[filter] = 1;
arrayFilter.push({
display: display,
filter: filter,
sort: sort,
type: type
});
this.s.rowData.totalOptions++;
}
else {
bins[filter]++;
this.s.rowData.totalOptions++;
return;
}
}
// Otherwise we must just be adding an option
else {
arrayFilter.push({
display: display,
filter: filter,
sort: sort,
type: type
});
}
};
/**
* Adds a row to the panes table
* @param display the value to be displayed to the user
* @param filter the value to be filtered on when searchpanes is implemented
* @param shown the number of rows in the table that are currently visible matching this criteria
* @param total the total number of rows in the table that match this criteria
* @param sort the value to be sorted in the pane table
* @param type the value of which the type is to be derived from
*/
SearchPane.prototype._addRow = function (display, filter, shown, total, sort, type, className) {
var index;
for (var _i = 0, _a = this.s.indexes; _i < _a.length; _i++) {
var entry = _a[_i];
if (entry.filter === filter) {
index = entry.index;
}
}
if (index === undefined) {
index = this.s.indexes.length;
this.s.indexes.push({ filter: filter, index: index });
}
return this.s.dtPane.row.add({
className: className,
display: display !== '' ?
display :
this.s.colOpts.emptyMessage !== false ?
this.s.colOpts.emptyMessage :
this.c.emptyMessage,
filter: filter,
index: index,
shown: shown,
sort: sort !== '' ?
sort :
this.s.colOpts.emptyMessage !== false ?
this.s.colOpts.emptyMessage :
this.c.emptyMessage,
total: total,
type: type
});
};
/**
* Adjusts the layout of the top row when the screen is resized
*/
SearchPane.prototype._adjustTopRow = function () {
var subContainers = this.dom.container.find('.' + this.classes.subRowsContainer);
var subRow1 = this.dom.container.find('.dtsp-subRow1');
var subRow2 = this.dom.container.find('.dtsp-subRow2');
var topRow = this.dom.container.find('.' + this.classes.topRow);
// If the width is 0 then it is safe to assume that the pane has not yet been displayed.
// Even if it has, if the width is 0 it won't make a difference if it has the narrow class or not
if (($(subContainers[0]).width() < 252 || $(topRow[0]).width() < 252) && $(subContainers[0]).width() !== 0) {
$(subContainers[0]).addClass(this.classes.narrow);
$(subRow1[0]).addClass(this.classes.narrowSub).removeClass(this.classes.narrowSearch);
$(subRow2[0]).addClass(this.classes.narrowSub).removeClass(this.classes.narrowButton);
}
else {
$(subContainers[0]).removeClass(this.classes.narrow);
$(subRow1[0]).removeClass(this.classes.narrowSub).addClass(this.classes.narrowSearch);
$(subRow2[0]).removeClass(this.classes.narrowSub).addClass(this.classes.narrowButton);
}
};
/**
* Method to construct the actual pane.
* @param selectedRows previously selected Rows to be reselected
* @last boolean to indicate whether this pane was the last one to have a selection made
*/
SearchPane.prototype._buildPane = function (selectedRows, last, dataIn, init, prevEl) {
var _this = this;
if (selectedRows === void 0) { selectedRows = []; }
if (last === void 0) { last = false; }
if (dataIn === void 0) { dataIn = null; }
if (init === void 0) { init = null; }
if (prevEl === void 0) { prevEl = null; }
// Aliases
this.selections = [];
var table = this.s.dt;
var column = table.column(this.colExists ? this.s.index : 0);
var colOpts = this.s.colOpts;
var rowData = this.s.rowData;
// Other Variables
var countMessage = table.i18n('searchPanes.count', '{total}');
var filteredMessage = table.i18n('searchPanes.countFiltered', '{shown} ({total})');
var loadedFilter = table.state.loaded();
// If the listeners have not been set yet then using the latest state may result in funny errors
if (this.s.listSet) {
loadedFilter = table.state();
}
// If it is not a custom pane in place
if (this.colExists) {
var idx = -1;
if (loadedFilter && loadedFilter.searchPanes && loadedFilter.searchPanes.panes) {
for (var i = 0; i < loadedFilter.searchPanes.panes.length; i++) {
if (loadedFilter.searchPanes.panes[i].id === this.s.index) {
idx = i;
break;
}
}
}
// Perform checks that do not require populate pane to run
if ((colOpts.show === false
|| (colOpts.show !== undefined && colOpts.show !== true)) &&
idx === -1) {
this.dom.container.addClass(this.classes.hidden);
this.s.displayed = false;
return false;
}
else if (colOpts.show === true || idx !== -1) {
this.s.displayed = true;
}
if (!this.s.dt.page.info().serverSide &&
(dataIn === null ||
dataIn.searchPanes === null ||
dataIn.searchPanes.options === null)) {
// Only run populatePane if the data has not been collected yet
if (rowData.arrayFilter.length === 0) {
this._populatePane(last);
this.s.rowData.totalOptions = 0;
this._detailsPane();
// If the index is not found then no data has been added to the state for this pane,
// which will only occur if it has previously failed to meet the criteria to be
// displayed, therefore we can just hide it again here
if (loadedFilter && loadedFilter.searchPanes && loadedFilter.searchPanes.panes && idx === -1) {
this.dom.container.addClass(this.classes.hidden);
this.s.displayed = false;
return;
}
rowData.arrayOriginal = rowData.arrayTotals;
rowData.binsOriginal = rowData.binsTotal;
}
var binLength = Object.keys(rowData.binsOriginal).length;
var uniqueRatio = this._uniqueRatio(binLength, table.rows()[0].length);
// Don't show the pane if there isn't enough variance in the data, or there is only 1 entry for that pane
if (this.s.displayed === false && ((colOpts.show === undefined && colOpts.threshold === null ?
uniqueRatio > this.c.threshold :
uniqueRatio > colOpts.threshold)
|| (colOpts.show !== true && binLength <= 1))) {
this.dom.container.addClass(this.classes.hidden);
this.s.displayed = false;
return;
}
// If the option viewTotal is true then find
// the total count for the whole table to display alongside the displayed count
if (this.c.viewTotal && rowData.arrayTotals.length === 0) {
this.s.rowData.totalOptions = 0;
this._detailsPane();
}
else {
rowData.binsTotal = rowData.bins;
}
this.dom.container.addClass(this.classes.show);
this.s.displayed = true;
}
else if (dataIn !== null && dataIn.searchPanes !== null && dataIn.searchPanes.options !== null) {
if (dataIn.tableLength !== undefined) {
this.s.tableLength = dataIn.tableLength;
this.s.rowData.totalOptions = this.s.tableLength;
}
else if (this.s.tableLength === null || table.rows()[0].length > this.s.tableLength) {
this.s.tableLength = table.rows()[0].length;
this.s.rowData.totalOptions = this.s.tableLength;
}
var colTitle = table.column(this.s.index).dataSrc();
if (dataIn.searchPanes.options[colTitle] !== undefined) {
for (var _i = 0, _a = dataIn.searchPanes.options[colTitle]; _i < _a.length; _i++) {
var dataPoint = _a[_i];
this.s.rowData.arrayFilter.push({
display: dataPoint.label,
filter: dataPoint.value,
sort: dataPoint.label,
type: dataPoint.label
});
this.s.rowData.bins[dataPoint.value] = this.c.viewTotal || this.c.cascadePanes ?
dataPoint.count :
dataPoint.total;
this.s.rowData.binsTotal[dataPoint.value] = dataPoint.total;
}
}
var binLength = Object.keys(rowData.binsTotal).length;
var uniqueRatio = this._uniqueRatio(binLength, this.s.tableLength);
// Don't show the pane if there isn't enough variance in the data, or there is only 1 entry for that pane
if (this.s.displayed === false && ((colOpts.show === undefined && colOpts.threshold === null ?
uniqueRatio > this.c.threshold :
uniqueRatio > colOpts.threshold)
|| (colOpts.show !== true && binLength <= 1))) {
this.dom.container.addClass(this.classes.hidden);
this.s.displayed = false;
return;
}
this.s.rowData.arrayOriginal = this.s.rowData.arrayFilter;
this.s.rowData.binsOriginal = this.s.rowData.bins;
this.s.displayed = true;
}
}
else {
this.s.displayed = true;
}
// If the variance is accceptable then display the search pane
this._displayPane();
if (!this.s.listSet) {
// Here, when the state is loaded if the data object on the original table is empty,
// then a state.clear() must have occurred, so delete all of the panes tables state objects too.
this.dom.dtP.on('stateLoadParams.dt', function (e, settings, data) {
if ($.isEmptyObject(table.state.loaded())) {
$.each(data, function (index, value) {
delete data[index];
});
}
});
}
// Add the container to the document in its original location
if (prevEl !== null && $(this.dom.panesContainer).has(prevEl).length > 0) {
$(this.dom.container).insertAfter(prevEl);
}
else {
$(this.dom.panesContainer).prepend(this.dom.container);
}
// Declare the datatable for the pane
var errMode = $.fn.dataTable.ext.errMode;
$.fn.dataTable.ext.errMode = 'none';
var haveScroller = DataTable.Scroller;
this.s.dtPane = $(this.dom.dtP).DataTable($.extend(true, {
columnDefs: [
{
className: 'dtsp-nameColumn',
data: 'display',
render: function (data, type, row) {
if (type === 'sort') {
return row.sort;
}
else if (type === 'type') {
return row.type;
}
var message;
(_this.s.filteringActive || _this.s.showFiltered) && _this.c.viewTotal
? message = filteredMessage.replace(/{total}/, row.total)
: message = countMessage.replace(/{total}/, row.total);
message = message.replace(/{shown}/, row.shown);
while (message.indexOf('{total}') !== -1) {
message = message.replace(/{total}/, row.total);
}
while (message.indexOf('{shown}') !== -1) {
message = message.replace(/{shown}/, row.shown);
}
// We are displaying the count in the same columne as the name of the search option.
// This is so that there is not need to call columns.adjust(), which in turn speeds up the code
var pill = '<span class="' + _this.classes.pill + '">' + message + '</span>';
if (_this.c.hideCount || colOpts.hideCount) {
pill = '';
}
return '<div class="' + _this.classes.nameCont + '"><span title="' +
(typeof data === 'string' && data.match(/<[^>]*>/) !== null ? data.replace(/<[^>]*>/g, '') : data) +
'" class="' + _this.classes.name + '">' +
data + '</span>' +
pill + '</div>';
},
targets: 0,
// Accessing the private datatables property to set type based on the original table.
// This is null if not defined by the user, meaning that automatic type detection would take place
type: table.settings()[0].aoColumns[this.s.index] !== undefined ?
table.settings()[0].aoColumns[this.s.index]._sManualType :
null
},
{
className: 'dtsp-countColumn ' + this.classes.badgePill,
data: 'shown',
orderData: [1, 2],
targets: 1,
visible: false
},
{
data: 'total',
targets: 2,
visible: false
}
],
deferRender: true,
dom: 't',
info: false,
language: this.s.dt.settings()[0].oLanguage,
paging: haveScroller ? true : false,
scrollX: false,
scrollY: '200px',
scroller: haveScroller ? true : false,
select: true,
stateSave: table.settings()[0].oFeatures.bStateSave ? true : false
}, this.c.dtOpts, colOpts !== undefined ? colOpts.dtOpts : {}, (this.s.colOpts.options !== undefined || !this.colExists)
? {
createdRow: function (row, data, dataIndex) {
$(row).addClass(data.className);
}
}
: undefined, (this.customPaneSettings !== null && this.customPaneSettings.dtOpts !== undefined)
? this.customPaneSettings.dtOpts
: {}));
$(this.dom.dtP).addClass(this.classes.table);
// This is hacky but necessary for when datatables is generating the column titles automatically
$(this.dom.searchBox).attr('placeholder', colOpts.header !== undefined
? colOpts.header
: this.colExists
? table.settings()[0].aoColumns[this.s.index].sTitle
: this.customPaneSettings.header || 'Custom Pane');
// As the pane table is not in the document yet we must initialise select ourselves
$.fn.dataTable.select.init(this.s.dtPane);
$.fn.dataTable.ext.errMode = errMode;
// If it is not a custom pane
if (this.colExists) {
// On initialisation, do we need to set a filtering value from a
// saved state or init option?
var search = column.search();
search = search ? search.substr(1, search.length - 2).split('|') : [];
// Count the number of empty cells
var count_1 = 0;
rowData.arrayFilter.forEach(function (element) {
if (element.filter === '') {
count_1++;
}
});
// Add all of the search options to the pane
for (var i = 0, ien = rowData.arrayFilter.length; i < ien; i++) {
var selected = false;
for (var _b = 0, _c = this.s.serverSelect; _b < _c.length; _b++) {
var option = _c[_b];
if (option.filter === rowData.arrayFilter[i].filter) {
selected = true;
}
}
if (this.s.dt.page.info().serverSide &&
(!this.c.cascadePanes ||
(this.c.cascadePanes && rowData.bins[rowData.arrayFilter[i].filter] !== 0) ||
(this.c.cascadePanes && init !== null) ||
selected)) {
var row = this._addRow(rowData.arrayFilter[i].display, rowData.arrayFilter[i].filter, init ?
rowData.binsTotal[rowData.arrayFilter[i].filter] :
rowData.bins[rowData.arrayFilter[i].filter], this.c.viewTotal || init
? String(rowData.binsTotal[rowData.arrayFilter[i].filter])
: rowData.bins[rowData.arrayFilter[i].filter], rowData.arrayFilter[i].sort, rowData.arrayFilter[i].type);
for (var _d = 0, _e = this.s.serverSelect; _d < _e.length; _d++) {
var option = _e[_d];
if (option.filter === rowData.arrayFilter[i].filter) {
this.s.serverSelecting = true;
row.select();
this.s.serverSelecting = false;
}
}
}
else if (!this.s.dt.page.info().serverSide &&
rowData.arrayFilter[i] &&
(rowData.bins[rowData.arrayFilter[i].filter] !== undefined || !this.c.cascadePanes)) {
this._addRow(rowData.arrayFilter[i].display, rowData.arrayFilter[i].filter, rowData.bins[rowData.arrayFilter[i].filter], rowData.binsTotal[rowData.arrayFilter[i].filter], rowData.arrayFilter[i].sort, rowData.arrayFilter[i].type);
}
else if (!this.s.dt.page.info().serverSide) {
// Just pass an empty string as the message will be calculated based on that in _addRow()
this._addRow('', count_1, count_1, '', '', '');
}
}
}
DataTable.select.init(this.s.dtPane);
// If there are custom options set or it is a custom pane then get them
if (colOpts.options !== undefined ||
(this.customPaneSettings !== null && this.customPaneSettings.options !== undefined)) {
this._getComparisonRows();
}
// Display the pane
this.s.dtPane.draw();
this._adjustTopRow();
if (!this.s.listSet) {
this._setListeners();
this.s.listSet = true;
}
for (var _f = 0, selectedRows_1 = selectedRows; _f < selectedRows_1.length; _f++) {
var selection = selectedRows_1[_f];
if (selection !== undefined) {
for (var _g = 0, _h = this.s.dtPane.rows().indexes().toArray(); _g < _h.length; _g++) {
var row = _h[_g];
if (this.s.dtPane.row(row).data() !== undefined && selection.filter === this.s.dtPane.row(row).data().filter) {
// If this is happening when serverSide processing is happening then different behaviour is needed
if (this.s.dt.page.info().serverSide) {
this.s.serverSelecting = true;
this.s.dtPane.row(row).select();
this.s.serverSelecting = false;
}
else {
this.s.dtPane.row(row).select();
}
}
}
}
}
// If SSP and the table is ready, apply the search for the pane
if (this.s.dt.page.info().serverSide) {
this.s.dtPane.search($(this.dom.searchBox).val()).draw();
}
// Reload the selection, searchbox entry and ordering from the previous state
// Need to check here if SSP that this is the first draw, otherwise it will infinite loop
if (loadedFilter &&
loadedFilter.searchPanes &&
loadedFilter.searchPanes.panes &&
(dataIn === null ||
dataIn.draw === 1)) {
if (!this.c.cascadePanes) {
this._reloadSelect(loadedFilter);
}
for (var _j = 0, _k = loadedFilter.searchPanes.panes; _j < _k.length; _j++) {
var pane = _k[_j];
if (pane.id === this.s.index) {
$(this.dom.searchBox).val(pane.searchTerm);
$(this.dom.searchBox).trigger('input');
this.s.dtPane.order(pane.order).draw();
}
}
}
// Make sure to save the state once the pane has been built
this.s.dt.state.save();
return true;
};
/**
* Update the array which holds the display and filter values for the table
*/
SearchPane.prototype._detailsPane = function () {
var table = this.s.dt;
this.s.rowData.arrayTotals = [];
this.s.rowData.binsTotal = {};
var settings = this.s.dt.settings()[0];
var indexArray = table.rows().indexes();
if (!this.s.dt.page.info().serverSide) {
for (var _i = 0, indexArray_1 = indexArray; _i < indexArray_1.length; _i++) {
var rowIdx = indexArray_1[_i];
this._populatePaneArray(rowIdx, this.s.rowData.arrayTotals, settings, this.s.rowData.binsTotal);
}
}
};
/**
* Appends all of the HTML elements to their relevant parent Elements
*/
SearchPane.prototype._displayPane = function () {
var container = this.dom.container;
var colOpts = this.s.colOpts;
var layVal = parseInt(this.c.layout.split('-')[1], 10);
// Empty everything to start again
$(this.dom.topRow).empty();
$(this.dom.dtP).empty();
$(this.dom.topRow).addClass(this.classes.topRow);
// If there are more than 3 columns defined then make there be a smaller gap between the panes
if (layVal > 3) {
$(this.dom.container).addClass(this.classes.smallGap);
}
$(this.dom.topRow).addClass(this.classes.subRowsContainer);
$(this.dom.upper).appendTo(this.dom.topRow);
$(this.dom.lower).appendTo(this.dom.topRow);
$(this.dom.searchCont).appendTo(this.dom.upper);
$(this.dom.buttonGroup).appendTo(this.dom.lower);
// If no selections have been made in the pane then disable the clear button
if (this.c.dtOpts.searching === false ||
(colOpts.dtOpts !== undefined &&
colOpts.dtOpts.searching === false) ||
(!this.c.controls || !colOpts.controls) ||
(this.customPaneSettings !== null &&
this.customPaneSettings.dtOpts !== undefined &&
this.customPaneSettings.dtOpts.searching !== undefined &&
!this.customPaneSettings.dtOpts.searching)) {
$(this.dom.searchBox).attr('disabled', 'disabled')
.removeClass(this.classes.paneInputButton)
.addClass(this.classes.disabledButton);
}
$(this.dom.searchBox).appendTo(this.dom.searchCont);
// Create the contents of the searchCont div. Worth noting that this function will change when using semantic ui
this._searchContSetup();
// If the clear button is allowed to show then display it
if (this.c.clear && this.c.controls && colOpts.controls) {
$(this.dom.clear).appendTo(this.dom.buttonGroup);
}
if (this.c.orderable && colOpts.orderable && this.c.controls && colOpts.controls) {
$(this.dom.nameButton).appendTo(this.dom.buttonGroup);
}
// If the count column is hidden then don't display the ordering button for it
if (!this.c.hideCount &&
!colOpts.hideCount &&
this.c.orderable &&
colOpts.orderable &&
this.c.controls &&
colOpts.controls) {
$(this.dom.countButton).appendTo(this.dom.buttonGroup);
}
$(this.dom.topRow).prependTo(this.dom.container);
$(container).append(this.dom.dtP);
$(container).show();
};
/**
* Gets the options for the row for the customPanes
* @returns {object} The options for the row extended to include the options from the user.
*/
SearchPane.prototype._getBonusOptions = function () {
// We need to reset the thresholds as if they have a value in colOpts then that value will be used
var defaultMutator = {
orthogonal: {
threshold: null
},
threshold: null
};
return $.extend(true, {}, SearchPane.defaults, defaultMutator, this.c !== undefined ? this.c : {});
};
/**
* Adds the custom options to the pane
* @returns {Array} Returns the array of rows which have been added to the pane
*/
SearchPane.prototype._getComparisonRows = function () {
var colOpts = this.s.colOpts;
// Find the appropriate options depending on whether this is a pane for a specific column or a custom pane
var options = colOpts.options !== undefined
? colOpts.options
: this.customPaneSettings !== null && this.customPaneSettings.options !== undefined
? this.customPaneSettings.options
: undefined;
if (options === undefined) {
return;
}
var tableVals = this.s.dt.rows({ search: 'applied' }).data().toArray();
var appRows = this.s.dt.rows({ search: 'applied' });
var tableValsTotal = this.s.dt.rows().data().toArray();
var allRows = this.s.dt.rows();
var rows = [];
// Clear all of the other rows from the pane, only custom options are to be displayed when they are defined
this.s.dtPane.clear();
for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
var comp = options_1[_i];
// Initialise the object which is to be placed in the row
var insert = comp.label !== '' ? comp.label : this.c.emptyMessage;
var comparisonObj = {
className: comp.className,
display: insert,
filter: typeof comp.value === 'function' ? comp.value : [],
shown: 0,
sort: insert,
total: 0,
type: insert
};
// If a custom function is in place
if (typeof comp.value === 'function') {
// Count the number of times the function evaluates to true for the data currently being displayed
for (var tVal = 0; tVal < tableVals.length; tVal++) {
if (comp.value.call(this.s.dt, tableVals[tVal], appRows[0][tVal])) {
comparisonObj.shown++;
}
}
// Count the number of times the function evaluates to true for the original data in the Table
for (var i = 0; i < tableValsTotal.length; i++) {
if (comp.value.call(this.s.dt, tableValsTotal[i], allRows[0][i])) {
comparisonObj.total++;
}
}
// Update the comparisonObj
if (typeof comparisonObj.filter !== 'function') {
comparisonObj.filter.push(comp.filter);
}
}
// If cascadePanes is not active or if it is and the comparisonObj should be shown then add it to the pane
if (!this.c.cascadePanes || (this.c.cascadePanes && comparisonObj.shown !== 0)) {
rows.push(this._addRow(comparisonObj.display, comparisonObj.filter, comparisonObj.shown, comparisonObj.total, comparisonObj.sort, comparisonObj.type, comparisonObj.className));
}
}
return rows;
};
/**
* Gets the options for the row for the customPanes
* @returns {object} The options for the row extended to include the options from the user.
*/
SearchPane.prototype._getOptions = function () {
var table = this.s.dt;
// We need to reset the thresholds as if they have a value in colOpts then that value will be used
var defaultMutator = {
emptyMessage: false,
orthogonal: {
threshold: null
},
threshold: null
};
return $.extend(true, {}, SearchPane.defaults, defaultMutator, table.settings()[0].aoColumns[this.s.index].searchPanes);
};
/**
* This method allows for changes to the panes and table to be made when a selection or a deselection occurs
* @param select Denotes whether a selection has been made or not
*/
SearchPane.prototype._makeSelection = function () {
this.updateTable();
this.s.updating = true;
this.s.dt.draw();
this.s.updating = false;
};
/**
* Fill the array with the values that are currently being displayed in the table
* @param last boolean to indicate whether this was the last pane a selection was made in
*/
SearchPane.prototype._populatePane = function (last) {
if (last === void 0) { last = false; }
var table = this.s.dt;
this.s.rowData.arrayFilter = [];
this.s.rowData.bins = {};
var settings = this.s.dt.settings()[0];
// If cascadePanes or viewTotal are active it is necessary to get the data which is currently
// being displayed for their functionality. Also make sure that this was not the last pane to have a selection made
if (!this.s.dt.page.info().serverSide) {
var indexArray = (this.c.cascadePanes || this.c.viewTotal) && (!this.s.clearing && !last) ?
table.rows({ search: 'applied' }).indexes() :
table.rows().indexes();
for (var _i = 0, _a = indexArray.toArray(); _i < _a.length; _i++) {
var index = _a[_i];
this._populatePaneArray(index, this.s.rowData.arrayFilter, settings);
}
}
};
/**
* Populates an array with all of the data for the table
* @param rowIdx The current row index to be compared
* @param arrayFilter The array that is to be populated with row Details
* @param bins The bins object that is to be populated with the row counts
*/
SearchPane.prototype._populatePaneArray = function (rowIdx, arrayFilter, settings, bins) {
if (bins === void 0) { bins = this.s.rowData.bins; }
var colOpts = this.s.colOpts;
// Retrieve the rendered data from the cell using the fnGetCellData function
// rather than the cell().render API method for optimisation
if (typeof colOpts.orthogonal === 'string') {
var rendered = settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal);
this.s.rowData.filterMap.set(rowIdx, rendered);
this._addOption(rendered, rendered, rendered, rendered, arrayFilter, bins);
}
else {
var filter = settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.search);
// Null and empty string are to be considered the same value
if (filter === null) {
filter = '';
}
if (typeof filter === 'string') {
filter = filter.replace(/<[^>]*>/g, '');
}
this.s.rowData.filterMap.set(rowIdx, filter);
if (!bins[filter]) {
bins[filter] = 1;
this._addOption(filter, settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.display), settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.sort), settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.type), arrayFilter, bins);
this.s.rowData.totalOptions++;
}
else {
bins[filter]++;
this.s.rowData.totalOptions++;
return;
}
}
};
/**
* Reloads all of the previous selects into the panes
* @param loadedFilter The loaded filters from a previous state
*/
SearchPane.prototype._reloadSelect = function (loadedFilter) {
// If the state was not saved don't selected any
if (loadedFilter === undefined) {
return;
}
var idx;
// For each pane, check that the loadedFilter list exists and is not null,
// find the id of each search item and set it to be selected.
for (var i = 0; i < loadedFilter.searchPanes.panes.length; i++) {
if (loadedFilter.searchPanes.panes[i].id === this.s.index) {
idx = i;
break;
}
}
if (idx !== undefined) {
var table = this.s.dtPane;
var rows = table.rows({ order: 'index' }).data().map(function (item) { return item.filter !== null ?
item.filter.toString() :
null; }).toArray();
for (var _i = 0, _a = loadedFilter.searchPanes.panes[idx].selected; _i < _a.length; _i++) {
var filter = _a[_i];
var id = -1;
if (filter !== null) {
id = rows.indexOf(filter.toString());
}
if (id > -1) {
this.s.serverSelecting = true;
table.row(id).select();
this.s.serverSelecting = false;
}
}
}
};
/**
* This method decides whether a row should contribute to the pane or not
* @param filter the value that the row is to be filtered on
* @param dataIndex the row index
*/
SearchPane.prototype._search = function (filter, dataIndex) {
var colOpts = this.s.colOpts;
var table = this.s.dt;
// For each item selected in the pane, check if it is available in the cell
for (var _i = 0, _a = this.selections; _i < _a.length; _i++) {
var colSelect = _a[_i];
if (typeof colSelect.filter === 'string') {
// The filter value will not have the & in place but a &,
// so we need to do a replace to make sure that they will match
colSelect.filter = colSelect.filter.replaceAll('&', '&');
}
// if the filter is an array then is the column present in it
if (Array.isArray(filter)) {
if (filter.indexOf(colSelect.filter) !== -1) {
return true;
}
}
// if the filter is a function then does it meet the criteria of that function or not
else if (typeof colSelect.filter === 'function') {
if (colSelect.filter.call(table, table.row(dataIndex).data(), dataIndex)) {
if (colOpts.combiner === 'or') {
return true;
}
}
// If the combiner is an "and" then we need to check against all possible selections
// so if it fails here then the and is not met and return false
else if (colOpts.combiner === 'and') {
return false;
}
}
// otherwise if the two filter values are equal then return true
// Loose type checking incase number type in column comparing to a string
else if ((filter === colSelect.filter) ||
(!(typeof filter === 'string' && filter.length === 0) && filter == colSelect.filter) ||
(colSelect.filter === null && typeof filter === 'string' && filter === '')) {
return true;
}
}
// If the combiner is an and then we need to check against all possible selections
// so return true here if so because it would have returned false earlier if it had failed
if (colOpts.combiner === 'and') {
return true;
}
// Otherwise it hasn't matched with anything by this point so it must be false
else {
return false;
}
};
/**
* Creates the contents of the searchCont div
*
* NOTE This is overridden when semantic ui styling in order to integrate the search button into the text box.
*/
SearchPane.prototype._searchContSetup = function () {
if (this.c.controls && this.s.colOpts.controls) {
$(this.dom.searchButton).appendTo(this.dom.searchLabelCont);
}
if (!(this.c.dtOpts.searching === false ||
this.s.colOpts.dtOpts.searching === false ||
(this.customPaneSettings !== null &&
this.customPaneSettings.dtOpts !== undefined &&
this.customPaneSettings.dtOpts.searching !== undefined &&
!this.customPaneSettings.dtOpts.searching))) {
$(this.dom.searchLabelCont).appendTo(this.dom.searchCont);
}
};
/**
* Adds outline to the pane when a selection has been made
*/
SearchPane.prototype._searchExtras = function () {
var updating = this.s.updating;
this.s.updating = true;
var filters = this.s.dtPane.rows({ selected: true }).data().pluck('filter').toArray();
var nullIndex = filters.indexOf(this.s.colOpts.emptyMessage !== false ?
this.s.colOpts.emptyMessage :
this.c.emptyMessage);
var container = $(this.s.dtPane.table().container());
// If null index is found then search for empty cells as a filter.
if (nullIndex > -1) {
filters[nullIndex] = '';
}
// If a filter has been applied then outline the respective pane, remove it when it no longer is.
if (filters.length > 0) {
container.addClass(this.classes.selected);
}
else if (filters.length === 0) {
container.removeClass(this.classes.selected);
}
this.s.updating = updating;
};
/**
* Finds the ratio of the number of different options in the table to the number of rows
* @param bins the number of different options in the table
* @param rowCount the total number of rows in the table
* @returns {number} returns the ratio
*/
SearchPane.prototype._uniqueRatio = function (bins, rowCount) {
if (rowCount > 0 &&
((this.s.rowData.totalOptions > 0 && !this.s.dt.page.info().serverSide) ||
(this.s.dt.page.info().serverSide && this.s.tableLength > 0))) {
return bins / this.s.rowData.totalOptions;
}
else {
return 1;
}
};
/**
* updates the options within the pane
* @param draw a flag to define whether this has been called due to a draw event or not
*/
SearchPane.prototype._updateCommon = function (draw) {
if (draw === void 0) { draw = false; }
// Update the panes if doing a deselect. if doing a select then
// update all of the panes except for the one causing the change
if (!this.s.dt.page.info().serverSide &&
this.s.dtPane !== undefined &&
(!this.s.filteringActive || this.c.cascadePanes || draw === true) &&
(this.c.cascadePanes !== true || this.s.selectPresent !== true) && (!this.s.lastSelect || !this.s.lastCascade)) {
var colOpts = this.s.colOpts;
var selected = this.s.dtPane.rows({ selected: true }).data().toArray();
var scrollTop = $(this.s.dtPane.table().node()).parent()[0].scrollTop;
var rowData = this.s.rowData;
// Clear the pane in preparation for adding the updated search options
this.s.dtPane.clear();
// If it is not a custom pane
if (this.colExists) {
// Only run populatePane if the data has not been collected yet
if (rowData.arrayFilter.length === 0) {
this._populatePane();
}
// If cascadePanes is active and the table has returned to its default state then
// there is a need to update certain parts ofthe rowData.
else if (this.c.cascadePanes
&& this.s.dt.rows().data().toArray().length === this.s.dt.rows({ search: 'applied' }).data().toArray().length) {
rowData.arrayFilter = rowData.arrayOriginal;
rowData.bins = rowData.binsOriginal;
}
// Otherwise if viewTotal or cascadePanes is active then the data from the table must be read.
else if (this.c.viewTotal || this.c.cascadePanes) {
this._populatePane();
}
// If the viewTotal option is selected then find the totals for the table
if (this.c.viewTotal) {
this._detailsPane();
}
else {
rowData.binsTotal = rowData.bins;
}
if (this.c.viewTotal && !this.c.cascadePanes) {
rowData.arrayFilter = rowData.arrayTotals;
}
var _loop_1 = function (dataP) {
// If both view Total and cascadePanes have been selected and the count of the row is not 0 then add it to pane
// Do this also if the viewTotal option has been selected and cascadePanes has not
if (dataP && ((rowData.bins[dataP.filter] !== undefined && rowData.bins[dataP.filter] !== 0 && this_1.c.cascadePanes)
|| !this_1.c.cascadePanes
|| this_1.s.clearing)) {
var row = this_1._addRow(dataP.display, dataP.filter, !this_1.c.viewTotal
? rowData.bins[dataP.filter]
: rowData.bins[dataP.filter] !== undefined
? rowData.bins[dataP.filter]
: 0, this_1.c.viewTotal
? String(rowData.binsTotal[dataP.filter])
: rowData.bins[dataP.filter], dataP.sort, dataP.type);
// Find out if the filter was selected in the previous search, if so select it and remove from array.
var selectIndex = selected.findIndex(function (element) {
return element.filter === dataP.filter;
});
if (selectIndex !== -1) {
row.select();
selected.splice(selectIndex, 1);
}
}
};
var this_1 = this;
for (var _i = 0, _a = rowData.arrayFilter; _i < _a.length; _i++) {
var dataP = _a[_i];
_loop_1(dataP);
}
}
if ((colOpts.searchPanes !== undefined && colOpts.searchPanes.options !== undefined) ||
colOpts.options !== undefined ||
(this.customPaneSettings !== null && this.customPaneSettings.options !== undefined)) {
var rows = this._getComparisonRows();
var _loop_2 = function (row) {
var selectIndex = selected.findIndex(function (element) {
if (element.display === row.data().display) {
return true;
}
});
if (selectIndex !== -1) {
row.select();
selected.splice(selectIndex, 1);
}
};
for (var _b = 0, rows_1 = rows; _b < rows_1.length; _b++) {
var row = rows_1[_b];
_loop_2(row);
}
}
// Add search options which were previously selected but whos results are no
// longer present in the resulting data set.
for (var _c = 0, selected_1 = selected; _c < selected_1.length; _c++) {
var selectedEl = selected_1[_c];
var row = this._addRow(selectedEl.display, selectedEl.filter, 0, this.c.viewTotal
? selectedEl.total
: 0, selectedEl.display, selectedEl.display);
this.s.updating = true;
row.select();
this.s.updating = false;
}
this.s.dtPane.draw();
this.s.dtPane.table().node().parentNode.scrollTop = scrollTop;
}
};
SearchPane.version = '1.1.0';
SearchPane.classes = {
buttonGroup: 'dtsp-buttonGroup',
buttonSub: 'dtsp-buttonSub',
clear: 'dtsp-clear',
clearAll: 'dtsp-clearAll',
clearButton: 'clearButton',
container: 'dtsp-searchPane',
countButton: 'dtsp-countButton',
disabledButton: 'dtsp-disabledButton',
dull: 'dtsp-dull',
hidden: 'dtsp-hidden',
hide: 'dtsp-hide',
layout: 'dtsp-',
name: 'dtsp-name',
nameButton: 'dtsp-nameButton',
nameCont: 'dtsp-nameCont',
narrow: 'dtsp-narrow',
paneButton: 'dtsp-paneButton',
paneInputButton: 'dtsp-paneInputButton',
pill: 'dtsp-pill',
search: 'dtsp-search',
searchCont: 'dtsp-searchCont',
searchIcon: 'dtsp-searchIcon',
searchLabelCont: 'dtsp-searchButtonCont',
selected: 'dtsp-selected',
smallGap: 'dtsp-smallGap',
subRow1: 'dtsp-subRow1',
subRow2: 'dtsp-subRow2',
subRowsContainer: 'dtsp-subRowsContainer',
title: 'dtsp-title',
topRow: 'dtsp-topRow'
};
// Define SearchPanes default options
SearchPane.defaults = {
cascadePanes: false,
clear: true,
combiner: 'or',
controls: true,
container: function (dt) {
return dt.table().container();
},
dtOpts: {},
emptyMessage: '<i>No Data</i>',
hideCount: false,
layout: 'columns-3',
name: undefined,
orderable: true,
orthogonal: {
display: 'display',
filter: 'filter',
hideCount: false,
search: 'filter',
show: undefined,
sort: 'sort',
threshold: 0.6,
type: 'type'
},
preSelect: [],
threshold: 0.6,
viewTotal: false
};
return SearchPane;
}());
var $$1;
var DataTable$1;
function setJQuery$1(jq) {
$$1 = jq;
DataTable$1 = jq.fn.dataTable;
}
var SearchPanes = /** @class */ (function () {
function SearchPanes(paneSettings, opts, fromInit) {
var _this = this;
if (fromInit === void 0) { fromInit = false; }
this.regenerating = false;
// Check that the required version of DataTables is included
if (!DataTable$1 || !DataTable$1.versionCheck || !DataTable$1.versionCheck('1.10.0')) {
throw new Error('SearchPane requires DataTables 1.10 or newer');
}
// Check that Select is included
if (!DataTable$1.select) {
throw new Error('SearchPane requires Select');
}
var table = new DataTable$1.Api(paneSettings);
this.classes = $$1.extend(true, {}, SearchPanes.classes);
// Get options from user
this.c = $$1.extend(true, {}, SearchPanes.defaults, opts);
// Add extra elements to DOM object including clear
this.dom = {
clearAll: $$1('<button type="button">Clear All</button>').addClass(this.classes.clearAll),
container: $$1('<div/>').addClass(this.classes.panes).text(table.i18n('searchPanes.loadMessage', 'Loading Search Panes...')),
emptyMessage: $$1('<div/>').addClass(this.classes.emptyMessage),
options: $$1('<div/>').addClass(this.classes.container),
panes: $$1('<div/>').addClass(this.classes.container),
title: $$1('<div/>').addClass(this.classes.title),
titleRow: $$1('<div/>').addClass(this.classes.titleRow),
wrapper: $$1('<div/>')
};
this.s = {
colOpts: [],
dt: table,
filterCount: 0,
filterPane: -1,
page: 0,
panes: [],
selectionList: [],
serverData: {},
stateRead: false,
updating: false
};
if (table.settings()[0]._searchPanes !== undefined) {
return;
}
this._getState();
if (this.s.dt.page.info().serverSide) {
table.on('preXhr.dt', function (e, settings, data) {
if (data.searchPanes === undefined) {
data.searchPanes = {};
}
for (var _i = 0, _a = _this.s.selectionList; _i < _a.length; _i++) {
var selection = _a[_i];
var src = _this.s.dt.column(selection.index).dataSrc();
if (data.searchPanes[src] === undefined) {
data.searchPanes[src] = {};
}
for (var i = 0; i < selection.rows.length; i++) {
data.searchPanes[src][i] = selection.rows[i].filter;
}
}
});
}
// We are using the xhr event to rebuild the panes if required due to viewTotal being enabled
// If viewTotal is not enabled then we simply update the data from the server
table.on('xhr', function (e, settings, json, xhr) {
if (json && json.searchPanes && json.searchPanes.options) {
_this.s.serverData = json;
_this.s.serverData.tableLength = json.recordsTotal;
_this._serverTotals();
}
});
table.settings()[0]._searchPanes = this;
this.dom.clearAll.text(table.i18n('searchPanes.clearMessage', 'Clear All'));
if (this.s.dt.settings()[0]._bInitComplete || fromInit) {
this._paneDeclare(table, paneSettings, opts);
}
else {
table.one('preInit.dt', function (settings) {
_this._paneDeclare(table, paneSettings, opts);
});
}
return this;
}
/**
* Clear the selections of all of the panes
*/
SearchPanes.prototype.clearSelections = function () {
// Load in all of the searchBoxes in the documents
var searches = this.dom.container.find(this.classes.search);
// For each searchBox set the input text to be empty and then trigger
// an input on them so that they no longer filter the panes
searches.each(function () {
$$1(this).val('');
$$1(this).trigger('input');
});
var returnArray = [];
// For every pane, clear the selections in the pane
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.dtPane !== undefined) {
returnArray.push(pane.clearPane());
}
}
this.s.dt.draw();
return returnArray;
};
/**
* returns the container node for the searchPanes
*/
SearchPanes.prototype.getNode = function () {
return this.dom.container;
};
/**
* rebuilds all of the panes
*/
SearchPanes.prototype.rebuild = function (targetIdx, maintainSelection) {
if (targetIdx === void 0) { targetIdx = false; }
if (maintainSelection === void 0) { maintainSelection = false; }
$$1(this.dom.emptyMessage).remove();
// As a rebuild from scratch is required, empty the searchpanes container.
var returnArray = [];
// Rebuild each pane individually, if a specific pane has been selected then only rebuild that one
if (targetIdx === false) {
$$1(this.dom.panes).empty();
}
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (targetIdx !== false && pane.s.index !== targetIdx) {
continue;
}
pane.clearData();
returnArray.push(
// Pass a boolean to say whether this is the last choice made for maintaining selections when rebuilding
pane.rebuildPane(this.s.selectionList[this.s.selectionList.length - 1] !== undefined ?
pane.s.index === this.s.selectionList[this.s.selectionList.length - 1].index :
false, this.s.dt.page.info().serverSide ?
this.s.serverData :
undefined, null, maintainSelection));
$$1(this.dom.panes).append(pane.dom.container);
}
// Only need to trigger a search if it is not server side processing
if (!this.s.dt.page.info().serverSide) {
this.s.dt.draw();
}
if (this.c.cascadePanes || this.c.viewTotal) {
this.redrawPanes(true);
}
else {
this._updateSelection();
}
// Attach panes, clear buttons, and title bar to the document
this._updateFilterCount();
this._attachPaneContainer();
this.s.dt.draw();
// If a single pane has been rebuilt then return only that pane
if (returnArray.length === 1) {
return returnArray[0];
}
// Otherwise return all of the panes that have been rebuilt
else {
return returnArray;
}
};
/**
* Redraws all of the panes
*/
SearchPanes.prototype.redrawPanes = function (rebuild) {
if (rebuild === void 0) { rebuild = false; }
var table = this.s.dt;
// Only do this if the redraw isn't being triggered by the panes updating themselves
if (!this.s.updating && !this.s.dt.page.info().serverSide) {
var filterActive = true;
var filterPane = this.s.filterPane;
// If the number of rows currently visible is equal to the number of rows in the table
// then there can't be any filtering taking place
if (table.rows({ search: 'applied' }).data().toArray().length === table.rows().data().toArray().length) {
filterActive = false;
}
// Otherwise if viewTotal is active then it is necessary to determine which panes a select is present in.
// If there is only one pane with a selection present then it should not show the filtered message as
// more selections may be made in that pane.
else if (this.c.viewTotal) {
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.dtPane !== undefined) {
var selectLength = pane.s.dtPane.rows({ selected: true }).data().toArray().length;
if (selectLength === 0) {
for (var _b = 0, _c = this.s.selectionList; _b < _c.length; _b++) {
var selection = _c[_b];
if (selection.index === pane.s.index && selection.rows.length !== 0) {
selectLength = selection.rows.length;
}
}
}
// If filterPane === -1 then a pane with a selection has not been found yet, so set filterPane to that panes index
if (selectLength > 0 && filterPane === -1) {
filterPane = pane.s.index;
}
// Then if another pane is found with a selection then set filterPane to null to
// show that multiple panes have selections present
else if (selectLength > 0) {
filterPane = null;
}
}
}
}
var deselectIdx = void 0;
var newSelectionList = [];
// Don't run this if it is due to the panes regenerating
if (!this.regenerating) {
for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
var pane = _e[_d];
// Identify the pane where a selection or deselection has been made and add it to the list.
if (pane.s.selectPresent) {
this.s.selectionList.push({ index: pane.s.index, rows: pane.s.dtPane.rows({ selected: true }).data().toArray(), protect: false });
table.state.save();
break;
}
else if (pane.s.deselect) {
deselectIdx = pane.s.index;
var selectedData = pane.s.dtPane.rows({ selected: true }).data().toArray();
if (selectedData.length > 0) {
this.s.selectionList.push({ index: pane.s.index, rows: selectedData, protect: true });
}
}
}
if (this.s.selectionList.length > 0) {
var last = this.s.selectionList[this.s.selectionList.length - 1].index;
for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
var pane = _g[_f];
pane.s.lastSelect = (pane.s.index === last);
}
}
// Remove selections from the list from the pane where a deselect has taken place
for (var i = 0; i < this.s.selectionList.length; i++) {
if (this.s.selectionList[i].index !== deselectIdx || this.s.selectionList[i].protect === true) {
var further = false;
// Find out if this selection is the last one in the list for that pane
for (var j = i + 1; j < this.s.selectionList.length; j++) {
if (this.s.selectionList[j].index === this.s.selectionList[i].index) {
further = true;
}
}
// If there are no selections for this pane in the list then just push this one
if (!further) {
newSelectionList.push(this.s.selectionList[i]);
this.s.selectionList[i].protect = false;
}
}
}
var solePane = -1;
if (newSelectionList.length === 1) {
solePane = newSelectionList[0].index;
}
// Update all of the panes to reflect the current state of the filters
for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
var pane = _j[_h];
if (pane.s.dtPane !== undefined) {
var tempFilter = true;
pane.s.filteringActive = true;
if ((filterPane !== -1 && filterPane !== null && filterPane === pane.s.index) ||
filterActive === false ||
pane.s.index === solePane) {
tempFilter = false;
pane.s.filteringActive = false;
}
pane.updatePane(!tempFilter ? false : filterActive);
}
}
// Update the label that shows how many filters are in place
this._updateFilterCount();
// If the length of the selections are different then some of them have been removed and a deselect has occured
if (newSelectionList.length > 0 && (newSelectionList.length < this.s.selectionList.length || rebuild)) {
this._cascadeRegen(newSelectionList);
var last = newSelectionList[newSelectionList.length - 1].index;
for (var _k = 0, _l = this.s.panes; _k < _l.length; _k++) {
var pane = _l[_k];
pane.s.lastSelect = (pane.s.index === last);
}
}
else if (newSelectionList.length > 0) {
// Update all of the other panes as you would just making a normal selection
for (var _m = 0, _o = this.s.panes; _m < _o.length; _m++) {
var paneUpdate = _o[_m];
if (paneUpdate.s.dtPane !== undefined) {
var tempFilter = true;
paneUpdate.s.filteringActive = true;
if ((filterPane !== -1 && filterPane !== null && filterPane === paneUpdate.s.index) || filterActive === false) {
tempFilter = false;
paneUpdate.s.filteringActive = false;
}
paneUpdate.updatePane(!tempFilter ? tempFilter : filterActive);
}
}
}
}
else {
var solePane = -1;
if (newSelectionList.length === 1) {
solePane = newSelectionList[0].index;
}
for (var _p = 0, _q = this.s.panes; _p < _q.length; _p++) {
var pane = _q[_p];
if (pane.s.dtPane !== undefined) {
var tempFilter = true;
pane.s.filteringActive = true;
if ((filterPane !== -1 && filterPane !== null && filterPane === pane.s.index) ||
filterActive === false ||
pane.s.index === solePane) {
tempFilter = false;
pane.s.filteringActive = false;
}
pane.updatePane(!tempFilter ? tempFilter : filterActive);
}
}
// Update the label that shows how many filters are in place
this._updateFilterCount();
}
if (!filterActive) {
this.s.selectionList = [];
}
}
};
/**
* Attach the panes, buttons and title to the document
*/
SearchPanes.prototype._attach = function () {
var _this = this;
$$1(this.dom.container).removeClass(this.classes.hide);
$$1(this.dom.titleRow).removeClass(this.classes.hide);
$$1(this.dom.titleRow).remove();
$$1(this.dom.title).appendTo(this.dom.titleRow);
// If the clear button is permitted attach it
if (this.c.clear) {
$$1(this.dom.clearAll).appendTo(this.dom.titleRow);
$$1(this.dom.clearAll).on('click.dtsps', function () {
_this.clearSelections();
});
}
$$1(this.dom.titleRow).appendTo(this.dom.container);
// Attach the container for each individual pane to the overall container
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
$$1(pane.dom.container).appendTo(this.dom.panes);
}
// Attach everything to the document
$$1(this.dom.panes).appendTo(this.dom.container);
if ($$1('div.' + this.classes.container).length === 0) {
$$1(this.dom.container).prependTo(this.s.dt);
}
return this.dom.container;
};
/**
* Attach the top row containing the filter count and clear all button
*/
SearchPanes.prototype._attachExtras = function () {
$$1(this.dom.container).removeClass(this.classes.hide);
$$1(this.dom.titleRow).removeClass(this.classes.hide);
$$1(this.dom.titleRow).remove();
$$1(this.dom.title).appendTo(this.dom.titleRow);
// If the clear button is permitted attach it
if (this.c.clear) {
$$1(this.dom.clearAll).appendTo(this.dom.titleRow);
}
$$1(this.dom.titleRow).appendTo(this.dom.container);
return this.dom.container;
};
/**
* If there are no panes to display then this method is called to either
* display a message in their place or hide them completely.
*/
SearchPanes.prototype._attachMessage = function () {
// Create a message to display on the screen
var message;
try {
message = this.s.dt.i18n('searchPanes.emptyPanes', 'No SearchPanes');
}
catch (error) {
message = null;
}
// If the message is an empty string then searchPanes.emptyPanes is undefined,
// therefore the pane container should be removed from the display
if (message === null) {
$$1(this.dom.container).addClass(this.classes.hide);
$$1(this.dom.titleRow).removeClass(this.classes.hide);
return;
}
else {
$$1(this.dom.container).removeClass(this.classes.hide);
$$1(this.dom.titleRow).addClass(this.classes.hide);
}
// Otherwise display the message
$$1(this.dom.emptyMessage).text(message);
this.dom.emptyMessage.appendTo(this.dom.container);
return this.dom.container;
};
/**
* Attaches the panes to the document and displays a message or hides if there are none
*/
SearchPanes.prototype._attachPaneContainer = function () {
// If a pane is to be displayed then attach the normal pane output
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.displayed === true) {
return this._attach();
}
}
// Otherwise attach the custom message or remove the container from the display
return this._attachMessage();
};
/**
* Prepares the panes for selections to be made when cascade is active and a deselect has occured
* @param newSelectionList the list of selections which are to be made
*/
SearchPanes.prototype._cascadeRegen = function (newSelectionList) {
// Set this to true so that the actions taken do not cause this to run until it is finished
this.regenerating = true;
// If only one pane has been selected then take note of its index
var solePane = -1;
if (newSelectionList.length === 1) {
solePane = newSelectionList[0].index;
}
// Let the pane know that a cascadeRegen is taking place to avoid unexpected behaviour
// and clear all of the previous selections in the pane
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
pane.setCascadeRegen(true);
pane.setClear(true);
// If this is the same as the pane with the only selection then pass it as a parameter into clearPane
if ((pane.s.dtPane !== undefined && pane.s.index === solePane) || pane.s.dtPane !== undefined) {
pane.clearPane();
}
pane.setClear(false);
}
// Remake Selections
this._makeCascadeSelections(newSelectionList);
// Set the selection list property to be the list without the selections from the deselect pane
this.s.selectionList = newSelectionList;
// The regeneration of selections is over so set it back to false
for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
var pane = _c[_b];
pane.setCascadeRegen(false);
}
this.regenerating = false;
};
/**
* Attaches the message to the document but does not add any panes
*/
SearchPanes.prototype._checkMessage = function () {
// If a pane is to be displayed then attach the normal pane output
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.displayed === true) {
return;
}
}
// Otherwise attach the custom message or remove the container from the display
return this._attachMessage();
};
/**
* Gets the selection list from the previous state and stores it in the selectionList Property
*/
SearchPanes.prototype._getState = function () {
var loadedFilter = this.s.dt.state.loaded();
if (loadedFilter && loadedFilter.searchPanes && loadedFilter.searchPanes.selectionList !== undefined) {
this.s.selectionList = loadedFilter.searchPanes.selectionList;
}
};
/**
* Makes all of the selections when cascade is active
* @param newSelectionList the list of selections to be made, in the order they were originally selected
*/
SearchPanes.prototype._makeCascadeSelections = function (newSelectionList) {
// make selections in the order they were made previously, excluding those from the pane where a deselect was made
for (var i = 0; i < newSelectionList.length; i++) {
var _loop_1 = function (pane) {
if (pane.s.index === newSelectionList[i].index && pane.s.dtPane !== undefined) {
// When regenerating the cascade selections we need this flag so that the panes are only ignored if it
// is the last selection and the pane for that selection
if (i === newSelectionList.length - 1) {
pane.s.lastCascade = true;
}
// if there are any selections currently in the pane then deselect them as we are about to make our new selections
if (pane.s.dtPane.rows({ selected: true }).data().toArray().length > 0 && pane.s.dtPane !== undefined) {
pane.setClear(true);
pane.clearPane();
pane.setClear(false);
}
var _loop_2 = function (row) {
pane.s.dtPane.rows().every(function (rowIdx) {
if (pane.s.dtPane.row(rowIdx).data() !== undefined &&
row !== undefined &&
pane.s.dtPane.row(rowIdx).data().filter === row.filter) {
pane.s.dtPane.row(rowIdx).select();
}
});
};
// select every row in the pane that was selected previously
for (var _i = 0, _a = newSelectionList[i].rows; _i < _a.length; _i++) {
var row = _a[_i];
_loop_2(row);
}
// Update the label that shows how many filters are in place
this_1._updateFilterCount();
pane.s.lastCascade = false;
}
};
var this_1 = this;
// As the selections may have been made across the panes in a different order to the pane index we must identify
// which pane has the index of the selection. This is also important for colreorder etc
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
_loop_1(pane);
}
}
// Make sure that the state is saved after all of these selections
this.s.dt.state.save();
};
/**
* Declares the instances of individual searchpanes dependant on the number of columns.
* It is necessary to run this once preInit has completed otherwise no panes will be
* created as the column count will be 0.
* @param table the DataTable api for the parent table
* @param paneSettings the settings passed into the constructor
* @param opts the options passed into the constructor
*/
SearchPanes.prototype._paneDeclare = function (table, paneSettings, opts) {
var _this = this;
// Create Panes
table
.columns(this.c.columns.length > 0 ? this.c.columns : undefined)
.eq(0)
.each(function (idx) {
_this.s.panes.push(new SearchPane(paneSettings, opts, idx, _this.c.layout, _this.dom.panes));
});
// If there is any extra custom panes defined then create panes for them too
var rowLength = table.columns().eq(0).toArray().length;
var paneLength = this.c.panes.length;
for (var i = 0; i < paneLength; i++) {
var id = rowLength + i;
this.s.panes.push(new SearchPane(paneSettings, opts, id, this.c.layout, this.dom.panes, this.c.panes[i]));
}
// If a custom ordering is being used
if (this.c.order.length > 0) {
// Make a new Array of panes based upon the order
var newPanes = this.c.order.map(function (name, index, values) {
return _this._findPane(name);
});
// Remove the old panes from the dom
this.dom.panes.empty();
this.s.panes = newPanes;
// Append the panes in the correct order
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
this.dom.panes.append(pane.dom.container);
}
}
// If this internal property is true then the DataTable has been initialised already
if (this.s.dt.settings()[0]._bInitComplete) {
this._startup(table);
}
else {
// Otherwise add the paneStartup function to the list of functions that are to be run when the table is initialised
// This will garauntee that the panes are initialised before the init event and init Complete callback is fired
this.s.dt.settings()[0].aoInitComplete.push({ fn: function () {
_this._startup(table);
} });
}
};
/**
* Finds a pane based upon the name of that pane
* @param name string representing the name of the pane
* @returns SearchPane The pane which has that name
*/
SearchPanes.prototype._findPane = function (name) {
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (name === pane.s.name) {
return pane;
}
}
};
/**
* Works out which panes to update when data is recieved from the server and viewTotal is active
*/
SearchPanes.prototype._serverTotals = function () {
var selectPresent = false;
var deselectPresent = false;
var table = this.s.dt;
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
// Identify the pane where a selection or deselection has been made and add it to the list.
if (pane.s.selectPresent) {
this.s.selectionList.push({ index: pane.s.index, rows: pane.s.dtPane.rows({ selected: true }).data().toArray(), protect: false });
table.state.save();
pane.s.selectPresent = false;
selectPresent = true;
break;
}
else if (pane.s.deselect) {
var selectedData = pane.s.dtPane.rows({ selected: true }).data().toArray();
if (selectedData.length > 0) {
this.s.selectionList.push({ index: pane.s.index, rows: selectedData, protect: true });
}
selectPresent = true;
deselectPresent = true;
}
}
// Build an updated list based on any selections or deselections added
if (!selectPresent) {
this.s.selectionList = [];
}
else {
var newSelectionList = [];
for (var i = 0; i < this.s.selectionList.length; i++) {
var further = false;
// Find out if this selection is the last one in the list for that pane
for (var j = i + 1; j < this.s.selectionList.length; j++) {
if (this.s.selectionList[j].index === this.s.selectionList[i].index) {
further = true;
}
}
// If there are no selections for this pane in the list then just push this one
if (!further) {
var push = false;
for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
var pane = _c[_b];
if (pane.s.index === this.s.selectionList[i].index &&
pane.s.dtPane.rows({ selected: true }).data().toArray().length > 0) {
push = true;
}
}
if (push) {
newSelectionList.push(this.s.selectionList[i]);
}
}
}
this.s.selectionList = newSelectionList;
}
var initIdx = -1;
// If there has been a deselect and only one pane has a selection then update everything
if (deselectPresent && this.s.selectionList.length === 1) {
for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
var pane = _e[_d];
pane.s.lastSelect = false;
pane.s.deselect = false;
if (pane.s.dtPane !== undefined && pane.s.dtPane.rows({ selected: true }).data().toArray().length > 0) {
initIdx = pane.s.index;
}
}
}
// Otherwise if there are more 1 selections then find the last one and set it to not update that pane
else if (this.s.selectionList.length > 0) {
var last = this.s.selectionList[this.s.selectionList.length - 1].index;
for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
var pane = _g[_f];
pane.s.lastSelect = (pane.s.index === last);
pane.s.deselect = false;
}
}
// Otherwise if there are no selections then find where that took place and do not update to maintain scrolling
else if (this.s.selectionList.length === 0) {
for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
var pane = _j[_h];
// pane.s.lastSelect = (pane.s.deselect === true);
pane.s.lastSelect = false;
pane.s.deselect = false;
}
}
$$1(this.dom.panes).empty();
// Rebuild the desired panes
for (var _k = 0, _l = this.s.panes; _k < _l.length; _k++) {
var pane = _l[_k];
if (!pane.s.lastSelect) {
pane.rebuildPane(undefined, this.s.dt.page.info().serverSide ? this.s.serverData : undefined, pane.s.index === initIdx ? true : null, true);
}
else {
pane._setListeners();
}
// append all of the panes and enable select
$$1(this.dom.panes).append(pane.dom.container);
if (pane.s.dtPane !== undefined) {
$$1(pane.s.dtPane.table().node()).parent()[0].scrollTop = pane.s.scrollTop;
$$1.fn.dataTable.select.init(pane.s.dtPane);
}
}
// Only need to trigger a search if it is not server side processing
if (!this.s.dt.page.info().serverSide) {
this.s.dt.draw();
}
};
/**
* Initialises the tables previous/preset selections and initialises callbacks for events
* @param table the parent table for which the searchPanes are being created
*/
SearchPanes.prototype._startup = function (table) {
var _this = this;
$$1(this.dom.container).text('');
// Attach clear button and title bar to the document
this._attachExtras();
$$1(this.dom.container).append(this.dom.panes);
$$1(this.dom.panes).empty();
var loadedFilter = this.s.dt.state.loaded();
if (this.c.viewTotal && !this.c.cascadePanes) {
if (loadedFilter !== null &&
loadedFilter !== undefined &&
loadedFilter.searchPanes !== undefined &&
loadedFilter.searchPanes.panes !== undefined) {
var filterActive = false;
for (var _i = 0, _a = loadedFilter.searchPanes.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.selected.length > 0) {
filterActive = true;
break;
}
}
if (filterActive) {
for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
var pane = _c[_b];
pane.s.showFiltered = true;
}
}
}
}
for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
var pane = _e[_d];
pane.rebuildPane(undefined, Object.keys(this.s.serverData).length > 0 ? this.s.serverData : undefined);
$$1(this.dom.panes).append(pane.dom.container);
}
// Only need to trigger a search if it is not server side processing
if (!this.s.dt.page.info().serverSide) {
this.s.dt.draw();
}
// Reset the paging if that has been saved in the state
if (!this.s.stateRead && loadedFilter !== null && loadedFilter !== undefined) {
this.s.dt.page((loadedFilter.start / this.s.dt.page.len()));
this.s.dt.draw('page');
}
this.s.stateRead = true;
if (this.c.viewTotal && !this.c.cascadePanes) {
for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
var pane = _g[_f];
pane.updatePane();
}
}
this._updateFilterCount();
this._checkMessage();
// When a draw is called on the DataTable, update all of the panes incase the data in the DataTable has changed
table.on('preDraw.dtsps', function () {
_this._updateFilterCount();
if ((_this.c.cascadePanes || _this.c.viewTotal) && !_this.s.dt.page.info().serverSide) {
_this.redrawPanes();
}
else {
_this._updateSelection();
}
_this.s.filterPane = -1;
});
// Whenever a state save occurs store the selection list in the state object
this.s.dt.on('stateSaveParams.dtsp', function (e, settings, data) {
if (data.searchPanes === undefined) {
data.searchPanes = {};
}
data.searchPanes.selectionList = _this.s.selectionList;
});
if (this.s.dt.page.info().serverSide) {
table.off('page');
table.on('page', function () {
_this.s.page = _this.s.dt.page();
});
table.off('preXhr.dt');
table.on('preXhr.dt', function (e, settings, data) {
if (data.searchPanes === undefined) {
data.searchPanes = {};
}
// Count how many filters are being applied
var filterCount = 0;
for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
var src = _this.s.dt.column(pane.s.index).dataSrc();
if (data.searchPanes[src] === undefined) {
data.searchPanes[src] = {};
}
if (pane.s.dtPane !== undefined) {
var rowData = pane.s.dtPane.rows({ selected: true }).data().toArray();
for (var i = 0; i < rowData.length; i++) {
data.searchPanes[src][i] = rowData[i].filter;
filterCount++;
}
}
}
if (_this.c.viewTotal) {
_this._prepViewTotal();
}
// If there is a filter to be applied, then we need to read from the start of the result set
// and set the paging to 0. This matches the behaviour of client side processing
if (filterCount > 0) {
// If the number of filters has changed we need to read from the start of the result set and reset the paging
if (filterCount !== _this.s.filterCount) {
data.start = 0;
_this.s.page = 0;
}
// Otherwise it is a paging request and we need to read from whatever the paging has been set to
else {
data.start = _this.s.page * _this.s.dt.page.len();
}
_this.s.dt.page(_this.s.page);
_this.s.filterCount = filterCount;
}
});
}
else {
table.on('preXhr.dt', function (e, settings, data) {
for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
pane.clearData();
}
});
}
// If the data is reloaded from the server then it is possible that it has changed completely,
// so we need to rebuild the panes
this.s.dt.on('xhr', function (e, settings, json, xhr) {
var processing = false;
if (!_this.s.dt.page.info().serverSide) {
_this.s.dt.one('preDraw', function () {
if (processing) {
return;
}
var page = _this.s.dt.page();
processing = true;
$$1(_this.dom.panes).empty();
for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
pane.clearData(); // Clears all of the bins and will mean that the data has to be re-read
// Pass a boolean to say whether this is the last choice made for maintaining selections when rebuilding
pane.rebuildPane(_this.s.selectionList[_this.s.selectionList.length - 1] !== undefined ?
pane.s.index === _this.s.selectionList[_this.s.selectionList.length - 1].index :
false, undefined, undefined, true);
$$1(_this.dom.panes).append(pane.dom.container);
}
if (!_this.s.dt.page.info().serverSide) {
_this.s.dt.draw();
}
if (_this.c.cascadePanes || _this.c.viewTotal) {
_this.redrawPanes(_this.c.cascadePanes);
}
else {
_this._updateSelection();
}
_this._checkMessage();
_this.s.dt.one('draw', function () {
_this.s.dt.page(page).draw(false);
});
});
}
});
// PreSelect any selections which have been defined using the preSelect option
for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
var pane = _j[_h];
if (pane !== undefined &&
pane.s.dtPane !== undefined &&
((pane.s.colOpts.preSelect !== undefined && pane.s.colOpts.preSelect.length > 0) ||
(pane.customPaneSettings !== null &&
pane.customPaneSettings.preSelect !== undefined &&
pane.customPaneSettings.preSelect.length > 0))) {
var tableLength = pane.s.dtPane.rows().data().toArray().length;
for (var i = 0; i < tableLength; i++) {
if (pane.s.colOpts.preSelect.indexOf(pane.s.dtPane.cell(i, 0).data()) !== -1 ||
(pane.customPaneSettings !== null &&
pane.customPaneSettings.preSelect !== undefined &&
pane.customPaneSettings.preSelect.indexOf(pane.s.dtPane.cell(i, 0).data()) !== -1)) {
pane.s.dtPane.row(i).select();
}
}
pane.updateTable();
}
}
if (this.s.selectionList !== undefined && this.s.selectionList.length > 0) {
var last = this.s.selectionList[this.s.selectionList.length - 1].index;
for (var _k = 0, _l = this.s.panes; _k < _l.length; _k++) {
var pane = _l[_k];
pane.s.lastSelect = (pane.s.index === last);
}
}
// If cascadePanes is active then make the previous selections in the order they were previously
if (this.s.selectionList.length > 0 && this.c.cascadePanes) {
this._cascadeRegen(this.s.selectionList);
}
// Update the title bar to show how many filters have been selected
this._updateFilterCount();
// If the table is destroyed and restarted then clear the selections so that they do not persist.
table.on('destroy.dtsps', function () {
for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
pane.destroy();
}
table.off('.dtsps');
$$1(_this.dom.clearAll).off('.dtsps');
$$1(_this.dom.container).remove();
_this.clearSelections();
});
// When the clear All button has been pressed clear all of the selections in the panes
if (this.c.clear) {
$$1(this.dom.clearAll).on('click.dtsps', function () {
_this.clearSelections();
});
}
table.settings()[0]._searchPanes = this;
};
SearchPanes.prototype._prepViewTotal = function () {
var filterPane = this.s.filterPane;
var filterActive = false;
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.dtPane !== undefined) {
var selectLength = pane.s.dtPane.rows({ selected: true }).data().toArray().length;
// If filterPane === -1 then a pane with a selection has not been found yet, so set filterPane to that panes index
if (selectLength > 0 && filterPane === -1) {
filterPane = pane.s.index;
filterActive = true;
}
// Then if another pane is found with a selection then set filterPane to null to
// show that multiple panes have selections present
else if (selectLength > 0) {
filterPane = null;
}
}
}
// Update all of the panes to reflect the current state of the filters
for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
var pane = _c[_b];
if (pane.s.dtPane !== undefined) {
pane.s.filteringActive = true;
if ((filterPane !== -1 && filterPane !== null && filterPane === pane.s.index) || filterActive === false) {
pane.s.filteringActive = false;
}
}
}
};
/**
* Updates the number of filters that have been applied in the title
*/
SearchPanes.prototype._updateFilterCount = function () {
var filterCount = 0;
// Add the number of all of the filters throughout the panes
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.dtPane !== undefined) {
filterCount += pane.getPaneCount();
}
}
// Run the message through the internationalisation method to improve readability
var message = this.s.dt.i18n('searchPanes.title', 'Filters Active - %d', filterCount);
$$1(this.dom.title).text(message);
if (this.c.filterChanged !== undefined && typeof this.c.filterChanged === 'function') {
this.c.filterChanged.call(this.s.dt, filterCount);
}
};
/**
* Updates the selectionList when cascade is not in place
*/
SearchPanes.prototype._updateSelection = function () {
this.s.selectionList = [];
for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
var pane = _a[_i];
if (pane.s.dtPane !== undefined) {
this.s.selectionList.push({ index: pane.s.index, rows: pane.s.dtPane.rows({ selected: true }).data().toArray(), protect: false });
}
}
this.s.dt.state.save();
};
SearchPanes.version = '1.2.1';
SearchPanes.classes = {
clear: 'dtsp-clear',
clearAll: 'dtsp-clearAll',
container: 'dtsp-searchPanes',
emptyMessage: 'dtsp-emptyMessage',
hide: 'dtsp-hidden',
panes: 'dtsp-panesContainer',
search: 'dtsp-search',
title: 'dtsp-title',
titleRow: 'dtsp-titleRow'
};
// Define SearchPanes default options
SearchPanes.defaults = {
cascadePanes: false,
clear: true,
container: function (dt) {
return dt.table().container();
},
columns: [],
filterChanged: undefined,
layout: 'columns-3',
order: [],
panes: [],
viewTotal: false
};
return SearchPanes;
}());
/*! SearchPanes 1.2.1
* 2019-2020 SpryMedia Ltd - datatables.net/license
*/
// DataTables extensions common UMD. Note that this allows for AMD, CommonJS
// (with window and jQuery being allowed as parameters to the returned
// function) or just default browser loading.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery', 'datatables.net'], function ($) {
return factory($, window, document);
});
}
else if (typeof exports === 'object') {
// CommonJS
module.exports = function (root, $) {
if (!root) {
root = window;
}
if (!$ || !$.fn.dataTable) {
$ = require('datatables.net')(root, $).$;
}
return factory($, root, root.document);
};
}
else {
// Browser - assume jQuery has already been loaded
factory(window.jQuery, window, document);
}
}(function ($, window, document) {
setJQuery($);
setJQuery$1($);
var DataTable = $.fn.dataTable;
$.fn.dataTable.SearchPanes = SearchPanes;
$.fn.DataTable.SearchPanes = SearchPanes;
$.fn.dataTable.SearchPane = SearchPane;
$.fn.DataTable.SearchPane = SearchPane;
var apiRegister = $.fn.dataTable.Api.register;
apiRegister('searchPanes()', function () {
return this;
});
apiRegister('searchPanes.clearSelections()', function () {
return this.iterator('table', function (ctx) {
if (ctx._searchPanes) {
ctx._searchPanes.clearSelections();
}
});
});
apiRegister('searchPanes.rebuildPane()', function (targetIdx, maintainSelections) {
return this.iterator('table', function (ctx) {
if (ctx._searchPanes) {
ctx._searchPanes.rebuild(targetIdx, maintainSelections);
}
});
});
apiRegister('searchPanes.container()', function () {
var ctx = this.context[0];
return ctx._searchPanes
? ctx._searchPanes.getNode()
: null;
});
$.fn.dataTable.ext.buttons.searchPanesClear = {
text: 'Clear Panes',
action: function (e, dt, node, config) {
dt.searchPanes.clearSelections();
}
};
$.fn.dataTable.ext.buttons.searchPanes = {
action: function (e, dt, node, config) {
e.stopPropagation();
this.popover(config._panes.getNode(), {
align: 'dt-container'
});
config._panes.rebuild(undefined, true);
},
config: {},
init: function (dt, node, config) {
var panes = new $.fn.dataTable.SearchPanes(dt, $.extend({
filterChanged: function (count) {
dt.button(node).text(dt.i18n('searchPanes.collapse', { 0: 'SearchPanes', _: 'SearchPanes (%d)' }, count));
}
}, config.config));
var message = dt.i18n('searchPanes.collapse', 'SearchPanes', 0);
dt.button(node).text(message);
config._panes = panes;
},
text: 'Search Panes'
};
function _init(settings, fromPre) {
if (fromPre === void 0) { fromPre = false; }
var api = new DataTable.Api(settings);
var opts = api.init().searchPanes || DataTable.defaults.searchPanes;
var searchPanes = new SearchPanes(api, opts, fromPre);
var node = searchPanes.getNode();
return node;
}
// Attach a listener to the document which listens for DataTables initialisation
// events so we can automatically initialise
$(document).on('preInit.dt.dtsp', function (e, settings, json) {
if (e.namespace !== 'dt') {
return;
}
if (settings.oInit.searchPanes ||
DataTable.defaults.searchPanes) {
if (!settings._searchPanes) {
_init(settings, true);
}
}
});
// DataTables `dom` feature option
DataTable.ext.feature.push({
cFeature: 'P',
fnInit: _init
});
// DataTables 2 layout feature
if (DataTable.ext.features) {
DataTable.ext.features.register('searchPanes', _init);
}
}));
}());