@syncfusion/ej2-dropdowns 24.1.43 → 24.1.45-12082

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/CHANGELOG.md +2101 -2058
  2. package/{README.md → ReadMe.md} +217 -217
  3. package/dist/ej2-dropdowns.min.js +1 -10
  4. package/dist/ej2-dropdowns.umd.min.js +1 -10
  5. package/dist/ej2-dropdowns.umd.min.js.map +1 -1
  6. package/dist/es6/ej2-dropdowns.es2015.js +94 -74
  7. package/dist/es6/ej2-dropdowns.es2015.js.map +1 -1
  8. package/dist/es6/ej2-dropdowns.es5.js +236 -216
  9. package/dist/es6/ej2-dropdowns.es5.js.map +1 -1
  10. package/dist/global/ej2-dropdowns.min.js +1 -10
  11. package/dist/global/ej2-dropdowns.min.js.map +1 -1
  12. package/dist/global/index.d.ts +0 -9
  13. package/dist/ts/auto-complete/auto-complete.ts +623 -0
  14. package/dist/ts/combo-box/combo-box.ts +1099 -0
  15. package/dist/ts/common/highlight-search.ts +57 -0
  16. package/dist/ts/common/incremental-search.ts +172 -0
  17. package/dist/ts/common/interface.ts +74 -0
  18. package/dist/ts/common/virtual-scroll.ts +388 -0
  19. package/dist/ts/drop-down-base/drop-down-base.ts +1986 -0
  20. package/dist/ts/drop-down-list/drop-down-list.ts +4261 -0
  21. package/dist/ts/drop-down-tree/drop-down-tree.ts +3747 -0
  22. package/dist/ts/list-box/list-box.ts +2772 -0
  23. package/dist/ts/mention/mention.ts +1875 -0
  24. package/dist/ts/multi-select/checkbox-selection.ts +550 -0
  25. package/dist/ts/multi-select/float-label.ts +176 -0
  26. package/dist/ts/multi-select/interface.ts +70 -0
  27. package/dist/ts/multi-select/multi-select.ts +4882 -0
  28. package/helpers/e2e/autocomplete.js +13 -13
  29. package/helpers/e2e/combobox.js +13 -13
  30. package/helpers/e2e/dropdownlist.js +13 -13
  31. package/helpers/e2e/index.js +3 -3
  32. package/helpers/e2e/listboxHelper.js +13 -13
  33. package/helpers/e2e/multiselect.js +13 -13
  34. package/license +2 -2
  35. package/package.json +80 -80
  36. package/src/auto-complete/auto-complete-model.d.ts +188 -188
  37. package/src/auto-complete/auto-complete.d.ts +12 -12
  38. package/src/auto-complete/auto-complete.js +21 -21
  39. package/src/combo-box/combo-box-model.d.ts +224 -224
  40. package/src/combo-box/combo-box.d.ts +27 -27
  41. package/src/combo-box/combo-box.js +29 -29
  42. package/src/common/virtual-scroll.js +46 -46
  43. package/src/drop-down-base/drop-down-base-model.d.ts +200 -200
  44. package/src/drop-down-base/drop-down-base.d.ts +16 -16
  45. package/src/drop-down-base/drop-down-base.js +20 -20
  46. package/src/drop-down-list/drop-down-list-model.d.ts +202 -202
  47. package/src/drop-down-list/drop-down-list.d.ts +5 -4
  48. package/src/drop-down-list/drop-down-list.js +31 -22
  49. package/src/drop-down-tree/drop-down-tree-model.d.ts +468 -468
  50. package/src/drop-down-tree/drop-down-tree.d.ts +0 -1
  51. package/src/drop-down-tree/drop-down-tree.js +20 -28
  52. package/src/list-box/list-box-model.d.ts +193 -193
  53. package/src/list-box/list-box.d.ts +2 -2
  54. package/src/list-box/list-box.js +34 -22
  55. package/src/mention/mention-model.d.ts +261 -261
  56. package/src/mention/mention.js +29 -22
  57. package/src/multi-select/multi-select-model.d.ts +512 -512
  58. package/src/multi-select/multi-select.js +20 -20
  59. package/styles/auto-complete/_all.scss +1 -1
  60. package/styles/auto-complete/_bds-definition.scss +2 -0
  61. package/styles/auto-complete/_bootstrap-dark-definition.scss +3 -3
  62. package/styles/auto-complete/_bootstrap-definition.scss +2 -2
  63. package/styles/auto-complete/_bootstrap4-definition.scss +11 -11
  64. package/styles/auto-complete/_bootstrap5-definition.scss +2 -2
  65. package/styles/auto-complete/_fabric-dark-definition.scss +2 -2
  66. package/styles/auto-complete/_fabric-definition.scss +2 -2
  67. package/styles/auto-complete/_fluent-definition.scss +2 -2
  68. package/styles/auto-complete/_fusionnew-definition.scss +2 -2
  69. package/styles/auto-complete/_highcontrast-definition.scss +2 -2
  70. package/styles/auto-complete/_highcontrast-light-definition.scss +2 -2
  71. package/styles/auto-complete/_material-dark-definition.scss +2 -2
  72. package/styles/auto-complete/_material-definition.scss +2 -2
  73. package/styles/auto-complete/_material3-definition.scss +2 -2
  74. package/styles/auto-complete/_tailwind-definition.scss +2 -2
  75. package/styles/auto-complete/material3-dark.scss +1 -1
  76. package/styles/auto-complete/material3.scss +1 -1
  77. package/styles/bootstrap-dark.css +9 -0
  78. package/styles/bootstrap.css +9 -0
  79. package/styles/bootstrap4.css +9 -0
  80. package/styles/bootstrap5-dark.css +9 -0
  81. package/styles/bootstrap5.css +9 -0
  82. package/styles/combo-box/_all.scss +1 -1
  83. package/styles/combo-box/_bds-definition.scss +2 -0
  84. package/styles/combo-box/_bootstrap-dark-definition.scss +2 -2
  85. package/styles/combo-box/_bootstrap-definition.scss +2 -2
  86. package/styles/combo-box/_bootstrap4-definition.scss +11 -11
  87. package/styles/combo-box/_bootstrap5-definition.scss +2 -2
  88. package/styles/combo-box/_fabric-dark-definition.scss +2 -2
  89. package/styles/combo-box/_fabric-definition.scss +2 -2
  90. package/styles/combo-box/_fluent-definition.scss +2 -2
  91. package/styles/combo-box/_fusionnew-definition.scss +2 -2
  92. package/styles/combo-box/_highcontrast-definition.scss +2 -2
  93. package/styles/combo-box/_highcontrast-light-definition.scss +3 -3
  94. package/styles/combo-box/_material-dark-definition.scss +2 -2
  95. package/styles/combo-box/_material-definition.scss +2 -2
  96. package/styles/combo-box/_material3-definition.scss +2 -2
  97. package/styles/combo-box/_tailwind-definition.scss +2 -2
  98. package/styles/combo-box/material3-dark.scss +1 -1
  99. package/styles/combo-box/material3.scss +1 -1
  100. package/styles/drop-down-base/_all.scss +2 -2
  101. package/styles/drop-down-base/_bds-definition.scss +129 -0
  102. package/styles/drop-down-base/_bootstrap-dark-definition.scss +83 -83
  103. package/styles/drop-down-base/_bootstrap-definition.scss +83 -83
  104. package/styles/drop-down-base/_bootstrap4-definition.scss +90 -90
  105. package/styles/drop-down-base/_bootstrap5-definition.scss +117 -117
  106. package/styles/drop-down-base/_definition.scss +23 -23
  107. package/styles/drop-down-base/_fabric-dark-definition.scss +86 -86
  108. package/styles/drop-down-base/_fabric-definition.scss +84 -84
  109. package/styles/drop-down-base/_fluent-definition.scss +121 -121
  110. package/styles/drop-down-base/_fusionnew-definition.scss +117 -117
  111. package/styles/drop-down-base/_highcontrast-definition.scss +105 -105
  112. package/styles/drop-down-base/_highcontrast-light-definition.scss +105 -105
  113. package/styles/drop-down-base/_layout.scss +192 -192
  114. package/styles/drop-down-base/_material-dark-definition.scss +86 -86
  115. package/styles/drop-down-base/_material-definition.scss +85 -85
  116. package/styles/drop-down-base/_material3-definition.scss +87 -87
  117. package/styles/drop-down-base/_tailwind-definition.scss +129 -129
  118. package/styles/drop-down-base/_theme.scss +391 -391
  119. package/styles/drop-down-base/material3-dark.scss +1 -1
  120. package/styles/drop-down-base/material3.scss +1 -1
  121. package/styles/drop-down-list/_all.scss +3 -3
  122. package/styles/drop-down-list/_bds-definition.scss +134 -0
  123. package/styles/drop-down-list/_bootstrap-dark-definition.scss +157 -157
  124. package/styles/drop-down-list/_bootstrap-definition.scss +156 -156
  125. package/styles/drop-down-list/_bootstrap4-definition.scss +202 -202
  126. package/styles/drop-down-list/_bootstrap5-definition.scss +201 -201
  127. package/styles/drop-down-list/_fabric-dark-definition.scss +128 -128
  128. package/styles/drop-down-list/_fabric-definition.scss +124 -124
  129. package/styles/drop-down-list/_fluent-definition.scss +185 -185
  130. package/styles/drop-down-list/_fusionnew-definition.scss +201 -201
  131. package/styles/drop-down-list/_highcontrast-definition.scss +142 -142
  132. package/styles/drop-down-list/_highcontrast-light-definition.scss +144 -144
  133. package/styles/drop-down-list/_layout.scss +315 -310
  134. package/styles/drop-down-list/_material-dark-definition.scss +143 -143
  135. package/styles/drop-down-list/_material-definition.scss +167 -167
  136. package/styles/drop-down-list/_material3-definition.scss +180 -180
  137. package/styles/drop-down-list/_tailwind-definition.scss +134 -134
  138. package/styles/drop-down-list/_theme.scss +10 -10
  139. package/styles/drop-down-list/bootstrap-dark.css +5 -0
  140. package/styles/drop-down-list/bootstrap.css +5 -0
  141. package/styles/drop-down-list/bootstrap4.css +5 -0
  142. package/styles/drop-down-list/bootstrap5-dark.css +5 -0
  143. package/styles/drop-down-list/bootstrap5.css +5 -0
  144. package/styles/drop-down-list/fabric-dark.css +5 -0
  145. package/styles/drop-down-list/fabric.css +5 -0
  146. package/styles/drop-down-list/fluent-dark.css +5 -0
  147. package/styles/drop-down-list/fluent.css +5 -0
  148. package/styles/drop-down-list/highcontrast-light.css +5 -0
  149. package/styles/drop-down-list/highcontrast.css +5 -0
  150. package/styles/drop-down-list/icons/_bootstrap-dark.scss +14 -14
  151. package/styles/drop-down-list/icons/_bootstrap.scss +14 -14
  152. package/styles/drop-down-list/icons/_bootstrap4.scss +14 -14
  153. package/styles/drop-down-list/icons/_bootstrap5.scss +14 -14
  154. package/styles/drop-down-list/icons/_fabric-dark.scss +14 -14
  155. package/styles/drop-down-list/icons/_fabric.scss +14 -14
  156. package/styles/drop-down-list/icons/_fluent.scss +14 -14
  157. package/styles/drop-down-list/icons/_fusionnew.scss +14 -14
  158. package/styles/drop-down-list/icons/_highcontrast-light.scss +14 -14
  159. package/styles/drop-down-list/icons/_highcontrast.scss +14 -14
  160. package/styles/drop-down-list/icons/_material-dark.scss +14 -14
  161. package/styles/drop-down-list/icons/_material.scss +14 -14
  162. package/styles/drop-down-list/icons/_material3.scss +14 -14
  163. package/styles/drop-down-list/icons/_tailwind.scss +14 -14
  164. package/styles/drop-down-list/material-dark.css +5 -0
  165. package/styles/drop-down-list/material.css +5 -0
  166. package/styles/drop-down-list/material3-dark.css +5 -0
  167. package/styles/drop-down-list/material3-dark.scss +1 -1
  168. package/styles/drop-down-list/material3.css +5 -0
  169. package/styles/drop-down-list/material3.scss +1 -1
  170. package/styles/drop-down-list/tailwind-dark.css +5 -0
  171. package/styles/drop-down-list/tailwind.css +5 -0
  172. package/styles/drop-down-tree/_all.scss +2 -2
  173. package/styles/drop-down-tree/_bds-definition.scss +61 -0
  174. package/styles/drop-down-tree/_bootstrap-dark-definition.scss +71 -71
  175. package/styles/drop-down-tree/_bootstrap-definition.scss +70 -70
  176. package/styles/drop-down-tree/_bootstrap4-definition.scss +71 -71
  177. package/styles/drop-down-tree/_bootstrap5-definition.scss +59 -59
  178. package/styles/drop-down-tree/_fabric-dark-definition.scss +71 -71
  179. package/styles/drop-down-tree/_fabric-definition.scss +71 -71
  180. package/styles/drop-down-tree/_fluent-definition.scss +65 -65
  181. package/styles/drop-down-tree/_fusionnew-definition.scss +59 -59
  182. package/styles/drop-down-tree/_highcontrast-definition.scss +71 -71
  183. package/styles/drop-down-tree/_highcontrast-light-definition.scss +71 -71
  184. package/styles/drop-down-tree/_layout.scss +1423 -1418
  185. package/styles/drop-down-tree/_material-dark-definition.scss +72 -72
  186. package/styles/drop-down-tree/_material-definition.scss +72 -72
  187. package/styles/drop-down-tree/_material3-definition.scss +76 -76
  188. package/styles/drop-down-tree/_tailwind-definition.scss +61 -61
  189. package/styles/drop-down-tree/_theme.scss +132 -132
  190. package/styles/drop-down-tree/bootstrap-dark.css +4 -0
  191. package/styles/drop-down-tree/bootstrap.css +4 -0
  192. package/styles/drop-down-tree/bootstrap4.css +4 -0
  193. package/styles/drop-down-tree/bootstrap5-dark.css +4 -0
  194. package/styles/drop-down-tree/bootstrap5.css +4 -0
  195. package/styles/drop-down-tree/fabric-dark.css +4 -0
  196. package/styles/drop-down-tree/fabric.css +4 -0
  197. package/styles/drop-down-tree/fluent-dark.css +4 -0
  198. package/styles/drop-down-tree/fluent.css +4 -0
  199. package/styles/drop-down-tree/highcontrast-light.css +4 -0
  200. package/styles/drop-down-tree/highcontrast.css +4 -0
  201. package/styles/drop-down-tree/icons/_bootstrap-dark.scss +11 -11
  202. package/styles/drop-down-tree/icons/_bootstrap.scss +11 -11
  203. package/styles/drop-down-tree/icons/_bootstrap4.scss +11 -11
  204. package/styles/drop-down-tree/icons/_bootstrap5.scss +11 -11
  205. package/styles/drop-down-tree/icons/_fabric-dark.scss +11 -11
  206. package/styles/drop-down-tree/icons/_fabric.scss +11 -11
  207. package/styles/drop-down-tree/icons/_fluent.scss +11 -11
  208. package/styles/drop-down-tree/icons/_fusionnew.scss +11 -11
  209. package/styles/drop-down-tree/icons/_highcontrast-light.scss +11 -11
  210. package/styles/drop-down-tree/icons/_highcontrast.scss +11 -11
  211. package/styles/drop-down-tree/icons/_material-dark.scss +11 -11
  212. package/styles/drop-down-tree/icons/_material.scss +11 -11
  213. package/styles/drop-down-tree/icons/_material3.scss +11 -11
  214. package/styles/drop-down-tree/icons/_tailwind-dark.scss +11 -11
  215. package/styles/drop-down-tree/icons/_tailwind.scss +11 -11
  216. package/styles/drop-down-tree/material-dark.css +4 -0
  217. package/styles/drop-down-tree/material.css +4 -0
  218. package/styles/drop-down-tree/material3-dark.css +4 -0
  219. package/styles/drop-down-tree/material3-dark.scss +1 -1
  220. package/styles/drop-down-tree/material3.css +4 -0
  221. package/styles/drop-down-tree/material3.scss +1 -1
  222. package/styles/drop-down-tree/tailwind-dark.css +4 -0
  223. package/styles/drop-down-tree/tailwind.css +4 -0
  224. package/styles/fabric-dark.css +9 -0
  225. package/styles/fabric.css +9 -0
  226. package/styles/fluent-dark.css +9 -0
  227. package/styles/fluent.css +9 -0
  228. package/styles/highcontrast-light.css +9 -0
  229. package/styles/highcontrast.css +9 -0
  230. package/styles/list-box/_all.scss +2 -2
  231. package/styles/list-box/_bds-definition.scss +119 -0
  232. package/styles/list-box/_bootstrap-dark-definition.scss +126 -126
  233. package/styles/list-box/_bootstrap-definition.scss +119 -119
  234. package/styles/list-box/_bootstrap4-definition.scss +124 -124
  235. package/styles/list-box/_bootstrap5-definition.scss +120 -120
  236. package/styles/list-box/_fabric-dark-definition.scss +126 -126
  237. package/styles/list-box/_fabric-definition.scss +119 -119
  238. package/styles/list-box/_fluent-definition.scss +120 -120
  239. package/styles/list-box/_fusionnew-definition.scss +111 -111
  240. package/styles/list-box/_highcontrast-definition.scss +119 -119
  241. package/styles/list-box/_highcontrast-light-definition.scss +126 -126
  242. package/styles/list-box/_layout.scss +542 -542
  243. package/styles/list-box/_material-dark-definition.scss +126 -126
  244. package/styles/list-box/_material-definition.scss +119 -119
  245. package/styles/list-box/_material3-definition.scss +119 -119
  246. package/styles/list-box/_tailwind-definition.scss +119 -119
  247. package/styles/list-box/_theme.scss +382 -382
  248. package/styles/list-box/icons/_bootstrap-dark.scss +25 -25
  249. package/styles/list-box/icons/_bootstrap.scss +25 -25
  250. package/styles/list-box/icons/_bootstrap4.scss +25 -25
  251. package/styles/list-box/icons/_bootstrap5.scss +25 -25
  252. package/styles/list-box/icons/_fabric-dark.scss +25 -25
  253. package/styles/list-box/icons/_fabric.scss +25 -25
  254. package/styles/list-box/icons/_fluent.scss +25 -25
  255. package/styles/list-box/icons/_fusionnew.scss +25 -25
  256. package/styles/list-box/icons/_highcontrast-light.scss +25 -25
  257. package/styles/list-box/icons/_highcontrast.scss +25 -25
  258. package/styles/list-box/icons/_material-dark.scss +25 -25
  259. package/styles/list-box/icons/_material.scss +25 -25
  260. package/styles/list-box/icons/_material3.scss +25 -25
  261. package/styles/list-box/icons/_tailwind-dark.scss +25 -25
  262. package/styles/list-box/icons/_tailwind.scss +25 -25
  263. package/styles/list-box/material3-dark.scss +1 -1
  264. package/styles/list-box/material3.scss +1 -1
  265. package/styles/material-dark.css +9 -0
  266. package/styles/material.css +9 -0
  267. package/styles/material3-dark.css +9 -0
  268. package/styles/material3-dark.scss +1 -1
  269. package/styles/material3.css +9 -0
  270. package/styles/material3.scss +1 -1
  271. package/styles/mention/_all.scss +1 -1
  272. package/styles/mention/_bds-definition.scss +1 -0
  273. package/styles/mention/_bootstrap-dark-definition.scss +3 -3
  274. package/styles/mention/_bootstrap-definition.scss +3 -3
  275. package/styles/mention/_bootstrap4-definition.scss +3 -3
  276. package/styles/mention/_bootstrap5-definition.scss +1 -1
  277. package/styles/mention/_fabric-dark-definition.scss +2 -2
  278. package/styles/mention/_fabric-definition.scss +3 -3
  279. package/styles/mention/_fluent-definition.scss +1 -1
  280. package/styles/mention/_fusionnew-definition.scss +1 -1
  281. package/styles/mention/_highcontrast-definition.scss +3 -3
  282. package/styles/mention/_highcontrast-light-definition.scss +3 -3
  283. package/styles/mention/_layout.scss +6 -6
  284. package/styles/mention/_material-dark-definition.scss +3 -3
  285. package/styles/mention/_material-definition.scss +3 -3
  286. package/styles/mention/_material3-definition.scss +1 -1
  287. package/styles/mention/_tailwind-definition.scss +1 -1
  288. package/styles/mention/material3-dark.scss +1 -1
  289. package/styles/mention/material3.scss +1 -1
  290. package/styles/multi-select/_all.scss +2 -2
  291. package/styles/multi-select/_bds-definition.scss +235 -0
  292. package/styles/multi-select/_bootstrap-dark-definition.scss +203 -203
  293. package/styles/multi-select/_bootstrap-definition.scss +192 -192
  294. package/styles/multi-select/_bootstrap4-definition.scss +278 -278
  295. package/styles/multi-select/_bootstrap5-definition.scss +230 -230
  296. package/styles/multi-select/_fabric-dark-definition.scss +192 -192
  297. package/styles/multi-select/_fabric-definition.scss +183 -183
  298. package/styles/multi-select/_fluent-definition.scss +241 -241
  299. package/styles/multi-select/_fusionnew-definition.scss +227 -227
  300. package/styles/multi-select/_highcontrast-definition.scss +303 -303
  301. package/styles/multi-select/_highcontrast-light-definition.scss +297 -297
  302. package/styles/multi-select/_layout.scss +2199 -2199
  303. package/styles/multi-select/_material-dark-definition.scss +230 -230
  304. package/styles/multi-select/_material-definition.scss +223 -223
  305. package/styles/multi-select/_material3-definition.scss +246 -246
  306. package/styles/multi-select/_tailwind-definition.scss +235 -235
  307. package/styles/multi-select/_theme.scss +586 -586
  308. package/styles/multi-select/icons/_bootstrap-dark.scss +26 -26
  309. package/styles/multi-select/icons/_bootstrap.scss +26 -26
  310. package/styles/multi-select/icons/_bootstrap4.scss +37 -37
  311. package/styles/multi-select/icons/_bootstrap5.scss +26 -26
  312. package/styles/multi-select/icons/_fabric-dark.scss +26 -26
  313. package/styles/multi-select/icons/_fabric.scss +26 -26
  314. package/styles/multi-select/icons/_fluent.scss +55 -55
  315. package/styles/multi-select/icons/_fusionnew.scss +26 -26
  316. package/styles/multi-select/icons/_highcontrast-light.scss +26 -26
  317. package/styles/multi-select/icons/_highcontrast.scss +26 -26
  318. package/styles/multi-select/icons/_material-dark.scss +693 -693
  319. package/styles/multi-select/icons/_material.scss +693 -693
  320. package/styles/multi-select/icons/_material3.scss +692 -692
  321. package/styles/multi-select/icons/_tailwind.scss +26 -26
  322. package/styles/multi-select/material3-dark.scss +1 -1
  323. package/styles/multi-select/material3.scss +1 -1
  324. package/styles/tailwind-dark.css +9 -0
  325. package/styles/tailwind.css +9 -0
  326. package/.eslintrc.json +0 -260
  327. package/tslint.json +0 -111
@@ -0,0 +1,1986 @@
1
+ import { Component, EventHandler, addClass, append, Property, Event, KeyboardEvents, EmitType, L10n, compile, KeyboardEventArgs } from '@syncfusion/ej2-base';
2
+ import { setStyleAttribute, extend, removeClass, prepend, isNullOrUndefined, detach, getValue, AnimationModel } from '@syncfusion/ej2-base';
3
+ import { NotifyPropertyChanges, INotifyPropertyChanged, rippleEffect, RippleOptions, ChildProperty, Complex } from '@syncfusion/ej2-base';
4
+ import { DataManager, Query, DataOptions, DataUtil } from '@syncfusion/ej2-data';
5
+ import { ListBase, SortOrder } from '@syncfusion/ej2-lists';
6
+ import { DropDownBaseModel, FieldSettingsModel } from './drop-down-base-model';
7
+ import { Popup } from '@syncfusion/ej2-popups';
8
+ import { remove, select, selectAll } from '@syncfusion/ej2-base';
9
+
10
+ export type FilterType = 'StartsWith' | 'EndsWith' | 'Contains';
11
+
12
+ export class FieldSettings extends ChildProperty<FieldSettings> {
13
+ /**
14
+ * Maps the text column from data table for each list item
15
+ *
16
+ * @default null
17
+ */
18
+ @Property()
19
+ public text: string;
20
+ /**
21
+ * Maps the value column from data table for each list item
22
+ *
23
+ * @default null
24
+ */
25
+ @Property()
26
+ public value: string;
27
+ /**
28
+ * Maps the icon class column from data table for each list item.
29
+ *
30
+ * @default null
31
+ */
32
+ @Property()
33
+ public iconCss: string;
34
+ /**
35
+ * Group the list items with it's related items by mapping groupBy field.
36
+ *
37
+ * @default null
38
+ */
39
+ @Property()
40
+ public groupBy: string;
41
+
42
+ /**
43
+ * Allows additional attributes such as title, disabled, etc., to configure the elements
44
+ * in various ways to meet the criteria.
45
+ *
46
+ * @default null
47
+ */
48
+ @Property()
49
+ public htmlAttributes: string;
50
+ }
51
+
52
+ export const dropDownBaseClasses: DropDownBaseClassList = {
53
+ root: 'e-dropdownbase',
54
+ rtl: 'e-rtl',
55
+ content: 'e-content',
56
+ selected: 'e-active',
57
+ hover: 'e-hover',
58
+ noData: 'e-nodata',
59
+ fixedHead: 'e-fixed-head',
60
+ focus: 'e-item-focus',
61
+ li: 'e-list-item',
62
+ group: 'e-list-group-item',
63
+ disabled: 'e-disabled',
64
+ grouping: 'e-dd-group'
65
+ };
66
+
67
+ const ITEMTEMPLATE_PROPERTY: string = 'ItemTemplate';
68
+ const DISPLAYTEMPLATE_PROPERTY: string = 'DisplayTemplate';
69
+ const SPINNERTEMPLATE_PROPERTY: string = 'SpinnerTemplate';
70
+ const VALUETEMPLATE_PROPERTY: string = 'ValueTemplate';
71
+ const GROUPTEMPLATE_PROPERTY: string = 'GroupTemplate';
72
+ const HEADERTEMPLATE_PROPERTY: string = 'HeaderTemplate';
73
+ const FOOTERTEMPLATE_PROPERTY: string = 'FooterTemplate';
74
+ const NORECORDSTEMPLATE_PROPERTY: string = 'NoRecordsTemplate';
75
+ const ACTIONFAILURETEMPLATE_PROPERTY: string = 'ActionFailureTemplate';
76
+ const HIDE_GROUPLIST: string = 'e-hide-group-header';
77
+
78
+ export interface DropDownBaseClassList {
79
+ root: string
80
+ rtl: string
81
+ content: string
82
+ selected: string
83
+ hover: string
84
+ noData: string
85
+ fixedHead: string
86
+ focus: string
87
+ li: string
88
+ disabled: string
89
+ group: string
90
+ grouping: string
91
+ }
92
+
93
+ export interface SelectEventArgs {
94
+ /**
95
+ * If the event is triggered by interaction, it returns true. Otherwise, it returns false.
96
+ */
97
+ isInteracted: boolean
98
+ /**
99
+ * Returns the selected list item
100
+ */
101
+ item: HTMLLIElement
102
+ /**
103
+ * Returns the selected item as JSON Object from the data source.
104
+ *
105
+ */
106
+ itemData: FieldSettingsModel
107
+ /**
108
+ * Specifies the original event arguments.
109
+ */
110
+ e: MouseEvent | KeyboardEvent | TouchEvent
111
+ /**
112
+ * Illustrates whether the current action needs to be prevented or not.
113
+ */
114
+ cancel?: boolean
115
+
116
+ }
117
+
118
+ export interface BeforeOpenEventArgs {
119
+ /**
120
+ * Illustrates whether the current action needs to be prevented or not.
121
+ */
122
+ cancel?: boolean
123
+ }
124
+
125
+ export interface ActionBeginEventArgs {
126
+ /**
127
+ * Specify the query to begin the data
128
+ *
129
+ */
130
+ query: Query
131
+ /**
132
+ * Set the data source to action begin
133
+ *
134
+ */
135
+ data: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[]
136
+ /**
137
+ * Illustrates whether the current action needs to be prevented or not.
138
+ */
139
+ cancel?: boolean
140
+ /**
141
+ * Specify the Event Name
142
+ */
143
+ eventName?: string
144
+ /**
145
+ * Return Items
146
+ */
147
+ items?: Object[]
148
+ }
149
+
150
+ export interface ActionCompleteEventArgs {
151
+ /**
152
+ * Illustrates whether the current action needs to be prevented or not.
153
+ */
154
+ cancel?: boolean
155
+ /**
156
+ * Returns the selected items as JSON Object from the data source.
157
+ *
158
+ */
159
+ result?: ResultData
160
+ /**
161
+ * Return the actual records.
162
+ */
163
+ actual?: object
164
+ /**
165
+ * Return the aggregates
166
+ */
167
+ aggregates?: object
168
+ /**
169
+ * Return the total number for records.
170
+ */
171
+ count?: number
172
+ /**
173
+ * Specify the query to complete the data
174
+ *
175
+ */
176
+ query?: Query
177
+ /**
178
+ * Return the request type
179
+ */
180
+ request?: string
181
+ /**
182
+ * Return the virtualSelectRecords
183
+ */
184
+ virtualSelectRecords?: object
185
+ /**
186
+ * Return XMLHttpRequest
187
+ */
188
+ xhr: XMLHttpRequest
189
+ /**
190
+ * Specify the Event Name
191
+ */
192
+ eventName?: string
193
+ /**
194
+ * Return Items
195
+ */
196
+ items?: Object[]
197
+ }
198
+
199
+ export interface DataBoundEventArgs {
200
+ /**
201
+ * Returns the selected items as JSON Object from the data source.
202
+ *
203
+ */
204
+ items: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[]
205
+ /**
206
+ * Return the bounded objects
207
+ */
208
+ e?: object
209
+ }
210
+
211
+ /**
212
+ * DropDownBase component will generate the list items based on given data and act as base class to drop-down related components
213
+ */
214
+ @NotifyPropertyChanges
215
+ export class DropDownBase extends Component<HTMLElement> implements INotifyPropertyChanged {
216
+ protected listData: { [key: string]: Object }[] | string[] | boolean[] | number[];
217
+ protected ulElement: HTMLElement;
218
+ protected incrementalLiCollections: HTMLElement[];
219
+ protected incrementalListData: { [key: string]: Object }[] | string[] | boolean[] | number[];
220
+ protected incrementalUlElement: HTMLElement;
221
+ protected liCollections: HTMLElement[];
222
+ private bindEvent: boolean;
223
+ private scrollTimer: number;
224
+ protected list: HTMLElement;
225
+ protected fixedHeaderElement: HTMLElement;
226
+ protected keyboardModule: KeyboardEvents;
227
+ protected enableRtlElements: HTMLElement[];
228
+ protected rippleFun: Function;
229
+ protected l10n: L10n;
230
+ protected item: HTMLLIElement;
231
+ protected itemData: { [key: string]: Object } | string | number | boolean;
232
+ protected isActive: boolean;
233
+ protected isRequested: boolean;
234
+ protected isDataFetched: boolean;
235
+ protected selectData: { [key: string]: Object }[] | string[] | boolean[] | number[];
236
+ protected queryString: string;
237
+ protected sortedData: { [key: string]: Object }[] | string[] | boolean[] | number[];
238
+ protected isGroupChecking: boolean;
239
+ protected itemTemplateId: string;
240
+ protected displayTemplateId: string;
241
+ protected spinnerTemplateId: string;
242
+ protected valueTemplateId: string;
243
+ protected groupTemplateId: string;
244
+ protected headerTemplateId: string;
245
+ protected footerTemplateId: string;
246
+ protected noRecordsTemplateId: string;
247
+ protected actionFailureTemplateId: string;
248
+ protected preventChange: boolean = false;
249
+ protected isAngular: boolean = false;
250
+ protected isPreventChange: boolean = false;
251
+ protected isDynamicDataChange: boolean = false;
252
+ protected addedNewItem: boolean = false;
253
+ protected isAddNewItemTemplate: boolean = false;
254
+ private isRequesting: boolean = false;
255
+ private isVirtualizationEnabled: boolean = false;
256
+ private isAllowFiltering: boolean = false;
257
+ private virtualizedItemsCount: number = 0;
258
+ protected totalItemCount: number = 0;
259
+ protected dataCount: number = 0;
260
+ protected isRemoteDataUpdated: boolean = false;
261
+ protected virtualGroupDataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[];
262
+ protected isIncrementalRequest: boolean = false;
263
+ protected itemCount: number = 10;
264
+ /**
265
+
266
+ /**
267
+ * The `fields` property maps the columns of the data table and binds the data to the component.
268
+ * * text - Maps the text column from data table for each list item.
269
+ * * value - Maps the value column from data table for each list item.
270
+ * * iconCss - Maps the icon class column from data table for each list item.
271
+ * * groupBy - Group the list items with it's related items by mapping groupBy field.
272
+ * ```html
273
+ * <input type="text" tabindex="1" id="list"> </input>
274
+ * ```
275
+ * ```typescript
276
+ * let customers: DropDownList = new DropDownList({
277
+ * dataSource:new DataManager({ url:'http://js.syncfusion.com/demos/ejServices/Wcf/Northwind.svc/' }),
278
+ * query: new Query().from('Customers').select(['ContactName', 'CustomerID']).take(5),
279
+ * fields: { text: 'ContactName', value: 'CustomerID' },
280
+ * placeholder: 'Select a customer'
281
+ * });
282
+ * customers.appendTo("#list");
283
+ * ```
284
+ *
285
+ * @default {text: null, value: null, iconCss: null, groupBy: null}
286
+ * @deprecated
287
+ */
288
+ @Complex<FieldSettingsModel>({ text: null, value: null, iconCss: null, groupBy: null }, FieldSettings)
289
+ public fields: FieldSettingsModel;
290
+ /**
291
+ * Accepts the template design and assigns it to each list item present in the popup.
292
+ * We have built-in `template engine`
293
+ *
294
+ * which provides options to compile template string into a executable function.
295
+ * For EX: We have expression evolution as like ES6 expression string literals.
296
+ *
297
+ * @default null
298
+ * @aspType string
299
+ * @deprecated
300
+ */
301
+ @Property(null)
302
+ public itemTemplate: string | Function;
303
+ /**
304
+ * Accepts the template design and assigns it to the group headers present in the popup list.
305
+ *
306
+ * @default null
307
+ * @aspType string
308
+ * @deprecated
309
+ */
310
+ @Property(null)
311
+ public groupTemplate: string | Function;
312
+ /**
313
+ * Accepts the template design and assigns it to popup list of component
314
+ * when no data is available on the component.
315
+ *
316
+ * @default 'No records found'
317
+ * @aspType string
318
+ * @deprecated
319
+ */
320
+ @Property('No records found')
321
+ public noRecordsTemplate: string | Function;
322
+ /**
323
+ * Accepts the template and assigns it to the popup list content of the component
324
+ * when the data fetch request from the remote server fails.
325
+ *
326
+ * @default 'Request failed'
327
+ * @aspType string
328
+ * @deprecated
329
+ */
330
+ @Property('Request failed')
331
+ public actionFailureTemplate: string | Function;
332
+ /**
333
+ * Specifies the `sortOrder` to sort the data source. The available type of sort orders are
334
+ * * `None` - The data source is not sorting.
335
+ * * `Ascending` - The data source is sorting with ascending order.
336
+ * * `Descending` - The data source is sorting with descending order.
337
+ *
338
+ * @default null
339
+ * @asptype object
340
+ * @aspjsonconverterignore
341
+ * @deprecated
342
+ */
343
+ @Property<SortOrder>('None')
344
+ public sortOrder: SortOrder;
345
+ /**
346
+ * Accepts the list items either through local or remote service and binds it to the component.
347
+ * It can be an array of JSON Objects or an instance of
348
+ * `DataManager`.
349
+ *
350
+ * @default []
351
+ * @deprecated
352
+ */
353
+ @Property([])
354
+ public dataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[];
355
+ /**
356
+ * Accepts the external `Query`
357
+ * which will execute along with the data processing.
358
+ *
359
+ * @default null
360
+ * @deprecated
361
+ */
362
+ @Property(null)
363
+ public query: Query;
364
+ /**
365
+ * Determines on which filter type, the component needs to be considered on search action.
366
+ * The `FilterType` and its supported data types are
367
+ *
368
+ * <table>
369
+ * <tr>
370
+ * <td colSpan=1 rowSpan=1>
371
+ * FilterType<br/></td><td colSpan=1 rowSpan=1>
372
+ * Description<br/></td><td colSpan=1 rowSpan=1>
373
+ * Supported Types<br/></td></tr>
374
+ * <tr>
375
+ * <td colSpan=1 rowSpan=1>
376
+ * StartsWith<br/></td><td colSpan=1 rowSpan=1>
377
+ * Checks whether a value begins with the specified value.<br/></td><td colSpan=1 rowSpan=1>
378
+ * String<br/></td></tr>
379
+ * <tr>
380
+ * <td colSpan=1 rowSpan=1>
381
+ * EndsWith<br/></td><td colSpan=1 rowSpan=1>
382
+ * Checks whether a value ends with specified value.<br/><br/></td><td colSpan=1 rowSpan=1>
383
+ * <br/>String<br/></td></tr>
384
+ * <tr>
385
+ * <td colSpan=1 rowSpan=1>
386
+ * Contains<br/></td><td colSpan=1 rowSpan=1>
387
+ * Checks whether a value contains with specified value.<br/><br/></td><td colSpan=1 rowSpan=1>
388
+ * <br/>String<br/></td></tr>
389
+ * </table>
390
+ *
391
+ * The default value set to `StartsWith`, all the suggestion items which contain typed characters to listed in the suggestion popup.
392
+ *
393
+ * @default 'StartsWith'
394
+ * @deprecated
395
+ */
396
+ @Property('StartsWith')
397
+ public filterType: FilterType;
398
+ /**
399
+ * When set to ‘false’, consider the `case-sensitive` on performing the search to find suggestions.
400
+ * By default consider the casing.
401
+ *
402
+ * @default true
403
+ * @deprecated
404
+ */
405
+ @Property(true)
406
+ public ignoreCase: boolean;
407
+ /**
408
+ * specifies the z-index value of the component popup element.
409
+ *
410
+ * @default 1000
411
+ * @deprecated
412
+ */
413
+ @Property(1000)
414
+ public zIndex: number;
415
+ /**
416
+ * ignoreAccent set to true, then ignores the diacritic characters or accents when filtering.
417
+ *
418
+ * @deprecated
419
+ */
420
+ @Property(false)
421
+ public ignoreAccent: boolean;
422
+ /**
423
+ * Overrides the global culture and localization value for this component. Default global culture is 'en-US'.
424
+ *
425
+ * @default 'en-US'
426
+ * @deprecated
427
+ */
428
+ @Property()
429
+ public locale: string;
430
+ /**
431
+ * Triggers before fetching data from the remote server.
432
+ *
433
+ * @event actionBegin
434
+ */
435
+ @Event()
436
+ public actionBegin: EmitType<Object>;
437
+ /**
438
+ * Triggers after data is fetched successfully from the remote server.
439
+ *
440
+ * @event actionComplete
441
+ */
442
+ @Event()
443
+ public actionComplete: EmitType<Object>;
444
+ /**
445
+ * Triggers when the data fetch request from the remote server fails.
446
+ *
447
+ * @event actionFailure
448
+ */
449
+ @Event()
450
+ public actionFailure: EmitType<Object>;
451
+ /**
452
+ * Triggers when an item in the popup is selected by the user either with mouse/tap or with keyboard navigation.
453
+ *
454
+ * @event select
455
+ */
456
+ @Event()
457
+ public select: EmitType<SelectEventArgs>;
458
+ /**
459
+ * Triggers when data source is populated in the popup list..
460
+ *
461
+ * @event dataBound
462
+ */
463
+ @Event()
464
+ public dataBound: EmitType<Object>;
465
+ /**
466
+ * Triggers when the component is created.
467
+ *
468
+ * @event created
469
+ */
470
+ @Event()
471
+ public created: EmitType<Object>;
472
+ /**
473
+      * Triggers when the component is destroyed.
474
+ *
475
+      * @event destroyed
476
+      */
477
+ @Event()
478
+ public destroyed: EmitType<Object>;
479
+ /**
480
+ * * Constructor for DropDownBase class
481
+ *
482
+ * @param {DropDownBaseModel} options - Specifies the DropDownBase model.
483
+ * @param {string | HTMLElement} element - Specifies the element to render as component.
484
+ * @private
485
+ */
486
+ public constructor(options?: DropDownBaseModel, element?: string | HTMLElement) {
487
+ super(options, element);
488
+ }
489
+ protected getPropObject(
490
+ prop: string, newProp: { [key: string]: string }, oldProp: { [key: string]: string }): { [key: string]: Object } {
491
+ const newProperty: { [key: string]: string } = <{ [key: string]: string }>new Object();
492
+ const oldProperty: { [key: string]: string } = <{ [key: string]: string }>new Object();
493
+ const propName: Function = (prop: string) => {
494
+ return prop;
495
+ };
496
+ newProperty[propName(prop)] = (newProp as { [key: string]: string })[propName(prop)];
497
+ oldProperty[propName(prop)] = (oldProp as { [key: string]: string })[propName(prop)];
498
+ const data: { [key: string]: Object } = <{ [key: string]: Object }>new Object();
499
+ data.newProperty = newProperty;
500
+ data.oldProperty = oldProperty;
501
+ return data;
502
+ }
503
+
504
+ protected getValueByText(text: string, ignoreCase?: boolean, ignoreAccent?: boolean): string | number | boolean {
505
+ let value: string | number | boolean = null;
506
+ if (!isNullOrUndefined(this.listData)) {
507
+ if (ignoreCase) {
508
+ value = this.checkValueCase(text, true, ignoreAccent);
509
+ } else {
510
+ value = this.checkValueCase(text, false, ignoreAccent);
511
+ }
512
+ }
513
+ return value;
514
+ }
515
+ private checkValueCase(text: string, ignoreCase: boolean, ignoreAccent: boolean, isTextByValue?: boolean): string | number {
516
+ let value: string | number = null;
517
+ if (isTextByValue) {
518
+ value = text;
519
+ }
520
+ const dataSource: { [key: string]: Object }[] = this.listData as { [key: string]: Object }[];
521
+ const fields: FieldSettingsModel = this.fields;
522
+ const type: string = this.typeOfData(dataSource).typeof as string;
523
+ if (type === 'string' || type === 'number' || type === 'boolean') {
524
+ for (const item of dataSource) {
525
+ if (!isNullOrUndefined(item)) {
526
+ if (ignoreAccent) {
527
+ value = this.checkingAccent(String(item), text, ignoreCase);
528
+ } else {
529
+ if (ignoreCase) {
530
+ if (this.checkIgnoreCase(String(item), text)) {
531
+ value = this.getItemValue(String(item), text, ignoreCase);
532
+ }
533
+ } else {
534
+ if (this.checkNonIgnoreCase(String(item), text)) {
535
+ value = this.getItemValue(String(item), text, ignoreCase, isTextByValue);
536
+ }
537
+ }
538
+ }
539
+ }
540
+ }
541
+ } else {
542
+ if (ignoreCase) {
543
+ (dataSource as { [key: string]: Object }[]).filter((item: { [key: string]: Object }) => {
544
+ const itemValue: string | number = getValue(fields.value, item);
545
+ if (!isNullOrUndefined(itemValue) && this.checkIgnoreCase(getValue(fields.text, item).toString(), text)) {
546
+ value = <string>getValue(fields.value, item);
547
+ }
548
+ });
549
+ } else {
550
+ if (isTextByValue) {
551
+ let compareValue: string | number = null;
552
+ compareValue = value;
553
+ dataSource.filter((item: { [key: string]: Object }) => {
554
+ const itemValue: string | number = getValue(fields.value, item);
555
+ if (!isNullOrUndefined(itemValue) && !isNullOrUndefined(value) && itemValue.toString() === compareValue.toString()) {
556
+ value = getValue(fields.text, item) as string;
557
+ }
558
+ });
559
+ } else {
560
+ dataSource.filter((item: { [key: string]: Object }) => {
561
+ if (this.checkNonIgnoreCase(getValue(fields.text, item), text)) {
562
+ value = <string>getValue(fields.value, item);
563
+ }
564
+ });
565
+ }
566
+ }
567
+ }
568
+ return value;
569
+ }
570
+ private checkingAccent(item: string, text: string, ignoreCase: boolean): string {
571
+ const dataItem: string | object = DataUtil.ignoreDiacritics(String(item));
572
+ const textItem: string | object = DataUtil.ignoreDiacritics(text.toString());
573
+ let value: string | number = null;
574
+ if (ignoreCase) {
575
+ if (this.checkIgnoreCase(dataItem as string, textItem as string)) {
576
+ value = this.getItemValue(String(item), text, ignoreCase);
577
+ }
578
+ } else {
579
+ if (this.checkNonIgnoreCase(String(item), text)) {
580
+ value = this.getItemValue(String(item), text, ignoreCase);
581
+ }
582
+ }
583
+ return (value as string);
584
+ }
585
+ private checkIgnoreCase(item: string, text: string): boolean {
586
+ return String(item).toLowerCase() === text.toString().toLowerCase() ? true : false;
587
+ }
588
+ private checkNonIgnoreCase(item: string, text: string): boolean {
589
+ return String(item) === text.toString() ? true : false;
590
+ }
591
+ private getItemValue(dataItem: string, typedText: string, ignoreCase: boolean, isTextByValue?: boolean): string {
592
+ let value: string | number | boolean = null;
593
+ const dataSource: { [key: string]: Object }[] = this.listData as { [key: string]: Object }[];
594
+ const type: string = this.typeOfData(dataSource).typeof as string;
595
+ if (isTextByValue) {
596
+ value = dataItem.toString();
597
+ } else {
598
+ if (ignoreCase) {
599
+ value = type === 'string' ? String(dataItem) : this.getFormattedValue(String(dataItem));
600
+ } else {
601
+ value = type === 'string' ? typedText : this.getFormattedValue(typedText);
602
+ }
603
+ }
604
+ return value as string;
605
+ }
606
+ private templateCompiler(baseTemplate: string | Function): boolean {
607
+ let checkTemplate: boolean = false;
608
+ if (typeof baseTemplate !== 'function' && baseTemplate) {
609
+ try {
610
+ checkTemplate = (selectAll(baseTemplate, document).length) ? true : false;
611
+ } catch (exception) {
612
+ checkTemplate = false;
613
+ }
614
+ }
615
+ return checkTemplate;
616
+ }
617
+ protected l10nUpdate(actionFailure?: boolean): void {
618
+ const ele: Element = this.getModuleName() === 'listbox' ? this.ulElement : this.list;
619
+ if (this.noRecordsTemplate !== 'No records found' || this.actionFailureTemplate !== 'Request failed') {
620
+ const template: string | Function = actionFailure ? this.actionFailureTemplate : this.noRecordsTemplate;
621
+ let compiledString: Function;
622
+ const templateId: string = actionFailure ? this.actionFailureTemplateId : this.noRecordsTemplateId;
623
+ ele.innerHTML = '';
624
+ const tempaltecheck: boolean = this.templateCompiler(template);
625
+ if (typeof template !== 'function' && tempaltecheck) {
626
+ compiledString = compile(select(template, document).innerHTML.trim());
627
+ } else {
628
+ compiledString = compile(template);
629
+ }
630
+ const templateName: string = actionFailure ? 'actionFailureTemplate' : 'noRecordsTemplate';
631
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
632
+ let noDataElement: any;
633
+ if (((this as any).isReact) && typeof template === 'function') {
634
+ noDataElement = compiledString({}, this, templateName, templateId, this.isStringTemplate, null);
635
+ }
636
+ else {
637
+ noDataElement = compiledString({}, this, templateName, templateId, this.isStringTemplate, null, ele);
638
+ }
639
+ if (noDataElement && noDataElement.length > 0) {
640
+ for (let i: number = 0; i < noDataElement.length; i++) {
641
+ if (this.getModuleName() === 'listbox' && templateName === 'noRecordsTemplate') {
642
+ if (noDataElement[i as number].nodeName === '#text') {
643
+ const liElem: HTMLElement = this.createElement('li');
644
+ liElem.textContent = noDataElement[i as number].textContent;
645
+ liElem.classList.add('e-list-nrt');
646
+ liElem.setAttribute('role','option')
647
+ ele.appendChild(liElem);
648
+ } else {
649
+ noDataElement[i as number].classList.add('e-list-nr-template');
650
+ ele.appendChild(noDataElement[i as number]);
651
+ }
652
+ } else {
653
+ if(noDataElement[i as number] instanceof HTMLElement)
654
+ {
655
+ ele.appendChild(noDataElement[i as number]);
656
+ }
657
+ }
658
+ }
659
+ }
660
+ this.renderReactTemplates();
661
+ } else {
662
+ const l10nLocale: Object = { noRecordsTemplate: 'No records found', actionFailureTemplate: 'Request failed'};
663
+ const componentLocale: L10n = new L10n(this.getLocaleName(), {}, this.locale);
664
+ if (componentLocale.getConstant('actionFailureTemplate') !== '' || componentLocale.getConstant('noRecordsTemplate') !== '') {
665
+ this.l10n = componentLocale;
666
+ } else {
667
+ this.l10n = new L10n(this.getModuleName() === 'listbox' ? 'listbox' :
668
+ this.getModuleName() === 'mention' ? 'mention' : 'dropdowns', l10nLocale, this.locale);
669
+ }
670
+ const content: string = actionFailure ?
671
+ this.l10n.getConstant('actionFailureTemplate') : this.l10n.getConstant('noRecordsTemplate');
672
+ if (this.getModuleName() === 'listbox') {
673
+ const liElem: Element = this.createElement('li');
674
+ liElem.textContent = content;
675
+ ele.appendChild(liElem);
676
+ liElem.classList.add('e-list-nrt');
677
+ liElem.setAttribute('role','option')
678
+ } else {
679
+ if (!isNullOrUndefined(ele)) {
680
+ ele.innerHTML = content;
681
+ }
682
+ }
683
+ }
684
+ }
685
+
686
+ protected getLocaleName(): string {
687
+ return 'drop-down-base';
688
+ }
689
+
690
+ protected getTextByValue(value: string | number | boolean): string {
691
+ const text: string = this.checkValueCase(value as string, false, false, true) as string;
692
+ return text;
693
+ }
694
+ protected getFormattedValue(value: string): string | number | boolean {
695
+ if (this.listData && this.listData.length) {
696
+ let item: { [key: string]: Object };
697
+ if(this.properties.allowCustomValue && this.properties.value && this.properties.value instanceof Array && this.properties.value.length > 0) {
698
+ item = this.typeOfData(this.properties.value);
699
+ }else{
700
+ item = this.typeOfData(this.listData);
701
+ }
702
+ if (typeof getValue((this.fields.value ? this.fields.value : 'value'), item.item as { [key: string]: Object }) === 'number'
703
+ || item.typeof === 'number') {
704
+ return parseFloat(value);
705
+ }
706
+ if (typeof getValue((this.fields.value ? this.fields.value : 'value'), item.item as { [key: string]: Object }) === 'boolean'
707
+ || item.typeof === 'boolean') {
708
+ return ((value === 'true') || ('' + value === 'true'));
709
+ }
710
+ }
711
+ return value;
712
+ }
713
+ /**
714
+ * Sets RTL to dropdownbase wrapper
715
+ *
716
+ * @returns {void}
717
+ */
718
+ protected setEnableRtl(): void {
719
+ if (!isNullOrUndefined(this.enableRtlElements)) {
720
+ if (this.list) {
721
+ this.enableRtlElements.push(this.list);
722
+ }
723
+ if (this.enableRtl) {
724
+ addClass(this.enableRtlElements, dropDownBaseClasses.rtl);
725
+ } else {
726
+ removeClass(this.enableRtlElements, dropDownBaseClasses.rtl);
727
+ }
728
+ }
729
+ }
730
+ /**
731
+ * Initialize the Component.
732
+ *
733
+ * @returns {void}
734
+ */
735
+ private initialize(e?: MouseEvent | KeyboardEventArgs | TouchEvent): void {
736
+ this.bindEvent = true;
737
+ this.actionFailureTemplateId = `${this.element.id}${ACTIONFAILURETEMPLATE_PROPERTY}`;
738
+ if (this.element.tagName === 'UL') {
739
+ const jsonElement: { [key: string]: Object }[] = ListBase.createJsonFromElement(this.element);
740
+ this.setProperties({ fields: { text: 'text', value: 'text' } }, true);
741
+ this.resetList(jsonElement, this.fields);
742
+ } else if (this.element.tagName === 'SELECT') {
743
+ const dataSource: boolean = this.dataSource instanceof Array ? (this.dataSource.length > 0 ? true : false)
744
+ : !isNullOrUndefined(this.dataSource) ? true : false;
745
+ if (!dataSource) {
746
+ this.renderItemsBySelect();
747
+ } else if (this.isDynamicDataChange) {
748
+ this.setListData(this.dataSource, this.fields, this.query);
749
+ }
750
+ } else {
751
+ this.setListData(this.dataSource, this.fields, this.query, e);
752
+ }
753
+ }
754
+ /**
755
+ * Get the properties to be maintained in persisted state.
756
+ *
757
+ * @returns {string} Returns the persisted data of the component.
758
+ */
759
+ protected getPersistData(): string {
760
+ return this.addOnPersist([]);
761
+ }
762
+ /**
763
+ * Sets the enabled state to DropDownBase.
764
+ *
765
+ * @param {string} value - Specifies the attribute values to add on the input element.
766
+ * @returns {void}
767
+ */
768
+ protected updateDataAttribute(value: { [key: string]: string }) : void {
769
+ const invalidAttr: string[] = ['class', 'style', 'id', 'type','aria-expanded','aria-autocomplete','aria-readonly'];
770
+ const attr: { [key: string]: string } = {};
771
+ for (let a: number = 0; a < this.element.attributes.length; a++) {
772
+ if (invalidAttr.indexOf(this.element.attributes[a as number].name) === -1 &&
773
+ !( this.getModuleName() === 'dropdownlist' && this.element.attributes[a as number].name === 'readonly')) {
774
+ attr[this.element.attributes[a as number].name] = this.element.getAttribute(this.element.attributes[a as number].name);
775
+ }
776
+ }
777
+ extend(attr, value, attr);
778
+ this.setProperties({ htmlAttributes: attr }, true);
779
+ }
780
+
781
+ private renderItemsBySelect(): void {
782
+ const element: Element = this.element;
783
+ const fields: FieldSettingsModel = { value: 'value', text: 'text' };
784
+ const jsonElement: { [key: string]: Object }[] = [];
785
+ const group: HTMLElement[] = <HTMLElement[] & NodeListOf<HTMLElement>>element.querySelectorAll('select>optgroup');
786
+ const option: HTMLOptionElement[] = <HTMLOptionElement[] & NodeListOf<HTMLOptionElement>>element.querySelectorAll('select>option');
787
+ this.getJSONfromOption(jsonElement, option, fields);
788
+ if (group.length) {
789
+ for (let i: number = 0; i < group.length; i++) {
790
+ const item: HTMLOptGroupElement = group[i as number] as HTMLOptGroupElement;
791
+ const optionGroup: { [key: string]: {} } = {};
792
+ optionGroup[fields.text] = item.label;
793
+ optionGroup.isHeader = true;
794
+ const child: HTMLOptionElement[] = <HTMLOptionElement[] & NodeListOf<HTMLOptionElement>>item.querySelectorAll('option');
795
+ jsonElement.push(optionGroup);
796
+ this.getJSONfromOption(jsonElement, child, fields);
797
+ }
798
+ element.querySelectorAll('select>option');
799
+ }
800
+ this.updateFields(fields.text, fields.value, this.fields.groupBy, this.fields.htmlAttributes, this.fields.iconCss);
801
+ this.resetList(jsonElement, fields);
802
+ }
803
+
804
+ private updateFields(text?: string, value?: string, groupBy?: string, htmlAttributes?: string, iconCss?: string): void {
805
+ const field: Object = {
806
+ 'fields': {
807
+ text: text,
808
+ value: value,
809
+ groupBy: !isNullOrUndefined(groupBy) ? groupBy : this.fields && this.fields.groupBy,
810
+ htmlAttributes: !isNullOrUndefined(htmlAttributes) ? htmlAttributes : this.fields && this.fields.htmlAttributes,
811
+ iconCss: !isNullOrUndefined(iconCss) ? iconCss : this.fields && this.fields.iconCss
812
+ }
813
+ };
814
+ this.setProperties(field, true);
815
+ }
816
+
817
+ private getJSONfromOption(
818
+ items: { [key: string]: Object }[],
819
+ options: HTMLOptionElement[],
820
+ fields: FieldSettingsModel): void {
821
+ for (const option of options) {
822
+ const json: { [key: string]: {} } = {};
823
+ json[fields.text] = option.innerText;
824
+ json[fields.value] = !isNullOrUndefined(option.getAttribute(fields.value)) ?
825
+ option.getAttribute(fields.value) : option.innerText;
826
+ items.push(json);
827
+ }
828
+ }
829
+ /**
830
+ * Execute before render the list items
831
+ *
832
+ * @private
833
+ * @returns {void}
834
+ */
835
+ protected preRender(): void {
836
+ // there is no event handler
837
+ this.scrollTimer = -1;
838
+ this.enableRtlElements = [];
839
+ this.isRequested = false;
840
+ this.isDataFetched = false;
841
+ this.itemTemplateId = `${this.element.id}${ITEMTEMPLATE_PROPERTY}`;
842
+ this.displayTemplateId = `${this.element.id}${DISPLAYTEMPLATE_PROPERTY}`;
843
+ this.spinnerTemplateId = `${this.element.id}${SPINNERTEMPLATE_PROPERTY}`;
844
+ this.valueTemplateId = `${this.element.id}${VALUETEMPLATE_PROPERTY}`;
845
+ this.groupTemplateId = `${this.element.id}${GROUPTEMPLATE_PROPERTY}`;
846
+ this.headerTemplateId = `${this.element.id}${HEADERTEMPLATE_PROPERTY}`;
847
+ this.footerTemplateId = `${this.element.id}${FOOTERTEMPLATE_PROPERTY}`;
848
+ this.noRecordsTemplateId = `${this.element.id}${NORECORDSTEMPLATE_PROPERTY}`;
849
+ }
850
+ /**
851
+ * Creates the list items of DropDownBase component.
852
+ *
853
+ * @param {Object[] | string[] | number[] | DataManager | boolean[]} dataSource - Specifies the data to generate the list.
854
+ * @param {FieldSettingsModel} fields - Maps the columns of the data table and binds the data to the component.
855
+ * @param {Query} query - Accepts the external Query that execute along with data processing.
856
+ * @returns {void}
857
+ */
858
+ private setListData(
859
+ dataSource: { [key: string]: Object }[] | string[] | number[] | DataManager | boolean[],
860
+ fields: FieldSettingsModel, query: Query, event?: MouseEvent | KeyboardEventArgs | TouchEvent): void {
861
+ fields = fields ? fields : this.fields;
862
+ let ulElement: HTMLElement;
863
+ this.isActive = true;
864
+ const eventArgs: ActionBeginEventArgs = { cancel: false, data: dataSource, query: query };
865
+ this.isPreventChange = this.isAngular && this.preventChange ? true : this.isPreventChange;
866
+ if (!this.isRequesting) {
867
+ this.trigger('actionBegin', eventArgs, (eventArgs: ActionBeginEventArgs) => {
868
+ if (!eventArgs.cancel) {
869
+ this.isRequesting = true;
870
+ this.showSpinner();
871
+ if (dataSource instanceof DataManager && !this.virtualGroupDataSource) {
872
+ this.isRequested = true;
873
+ if (this.isDataFetched) {
874
+ this.emptyDataRequest(fields);
875
+ return;
876
+ }
877
+ (eventArgs.data as DataManager).executeQuery(this.getQuery(eventArgs.query as Query)).then((e: Object) => {
878
+ this.isPreventChange = this.isAngular && this.preventChange ? true : this.isPreventChange;
879
+ this.trigger('actionComplete', e, (e: Object) => {
880
+ if(!this.virtualGroupDataSource && this.isVirtualizationEnabled) {
881
+ this.isRemoteDataUpdated = true;
882
+ if((this.getModuleName() === 'combobox' && this.isAllowFiltering && this.isVirtualizationEnabled && (e as ResultData).result)) {
883
+ (e as ResultData).result = ((e as ResultData).result as any).result;
884
+ }
885
+ if ((e as ResultData).result.length > 0) {
886
+ let dataSource = (e as ResultData).result;
887
+ if(this.isVirtualizationEnabled && this.fields.groupBy) {
888
+ let data = <{ [key: string]: Object }[]>new DataManager(<any[]>dataSource).executeLocal(new Query().group(this.fields.groupBy));
889
+ this.virtualGroupDataSource = (data as any).records;
890
+ }
891
+ else{
892
+ this.virtualGroupDataSource = dataSource;
893
+ this.hideSpinner();
894
+ this.isRequested = false;
895
+ this.isRequesting = false;
896
+ this.setListData(dataSource, fields, query, event);
897
+ return;
898
+ }
899
+ }
900
+ this.hideSpinner();
901
+ this.isRequested = false;
902
+ this.isRequesting = false;
903
+ this.updatePopupState();
904
+ return;
905
+ }
906
+ if (!(e as { [key: string]: object }).cancel) {
907
+ this.isRequesting = false;
908
+ const listItems: { [key: string]: Object }[] = (e as ResultData).result;
909
+ if(this.isIncrementalRequest){
910
+ ulElement = this.renderItems(listItems, fields);
911
+ return;
912
+ }
913
+ if (listItems.length === 0) {
914
+ this.isDataFetched = true;
915
+ }
916
+ this.dataCount = (e as any).count;
917
+ this.totalItemCount = (e as any).count;
918
+ ulElement = this.renderItems(listItems, fields);
919
+ this.onActionComplete(ulElement, listItems, e);
920
+ if (this.groupTemplate) {
921
+ this.renderGroupTemplate(ulElement);
922
+ }
923
+ this.isRequested = false;
924
+ this.bindChildItems(listItems, ulElement, fields, e);
925
+ }
926
+ });
927
+ }).catch((e: Object) => {
928
+ this.isRequested = false;
929
+ this.isRequesting = false;
930
+ this.onActionFailure(e);
931
+ this.hideSpinner();
932
+ });
933
+ } else {
934
+ this.isRequesting = false;
935
+ let listItems: { [key: string]: Object }[];
936
+ if (this.isVirtualizationEnabled && !this.virtualGroupDataSource && this.fields.groupBy) {
937
+ let data = <{ [key: string]: Object }[]>new DataManager(<any[]>this.dataSource).executeLocal(new Query().group(this.fields.groupBy));
938
+ this.virtualGroupDataSource = (data as any).records;
939
+ }
940
+ let dataManager: DataManager = this.isVirtualizationEnabled && (this.virtualGroupDataSource as DataOptions | JSON[]) ? new DataManager(this.virtualGroupDataSource as DataOptions | JSON[]) : new DataManager(eventArgs.data as DataOptions | JSON[]);
941
+ listItems= <{ [key: string]: Object }[]>(
942
+ this.getQuery(eventArgs.query as Query)).executeLocal(dataManager);
943
+ if(this.isVirtualizationEnabled && this.getModuleName() ==='autocomplete' && ((listItems as any).count != 0 && (listItems as any).count < (this.itemCount * 2))){
944
+ let newQuery : Query = this.getQuery(eventArgs.query as Query);
945
+ if (newQuery) {
946
+ for (let queryElements: number = 0; queryElements < newQuery.queries.length; queryElements++) {
947
+ if (newQuery.queries[queryElements as number].fn === 'onTake') {
948
+ newQuery.queries[queryElements as number].e.nos = (listItems as any).count;
949
+ listItems = <{ [key: string]: Object }[]>(newQuery).executeLocal(dataManager);
950
+ break;
951
+ }
952
+ }
953
+ }
954
+ }
955
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
956
+ this.dataCount = (listItems as any).count;
957
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
958
+ this.totalItemCount = (listItems as any).count;
959
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
960
+ listItems = this.isVirtualizationEnabled ? (listItems as any).result : listItems;
961
+ const localDataArgs: { [key: string]: Object } = { cancel: false, result: listItems };
962
+ this.isPreventChange = this.isAngular && this.preventChange ? true : this.isPreventChange;
963
+ this.trigger('actionComplete', localDataArgs, (localDataArgs: { [key: string]: object }) => {
964
+ if(this.isIncrementalRequest){
965
+ ulElement = this.renderItems(localDataArgs.result as { [key: string]: Object }[], fields);
966
+ return;
967
+ }
968
+ if (!localDataArgs.cancel) {
969
+ ulElement = this.renderItems(localDataArgs.result as { [key: string]: Object }[], fields);
970
+ this.onActionComplete(ulElement, localDataArgs.result as { [key: string]: Object }[], event);
971
+ if (this.groupTemplate) {
972
+ this.renderGroupTemplate(ulElement);
973
+ }
974
+ this.bindChildItems(localDataArgs.result as { [key: string]: Object }[], ulElement, fields);
975
+ setTimeout(() => {
976
+ if (this.getModuleName() === 'multiselect' && this.itemTemplate != null && (ulElement.childElementCount > 0 && (ulElement.children[0].childElementCount > 0 || (this.fields.groupBy && ulElement.children[1] && ulElement.children[1].childElementCount > 0)))) {
977
+ this.updateDataList();
978
+ }
979
+ });
980
+ }
981
+ });
982
+ }
983
+ }
984
+ });
985
+ }
986
+ }
987
+ protected updatePopupState(): void {
988
+ // Used this method in component side.
989
+ }
990
+ protected updateRemoteData(): void {
991
+ this.setListData(this.dataSource, this.fields, this.query);
992
+ }
993
+ private bindChildItems(
994
+ listItems: { [key: string]: Object }[],
995
+ ulElement: HTMLElement,
996
+ fields: FieldSettingsModel,
997
+ e?: object): void {
998
+ if (listItems.length >= 100 && this.getModuleName() === 'autocomplete') {
999
+ setTimeout(
1000
+ () => {
1001
+ const childNode: HTMLElement[] = this.remainingItems(this.sortedData, fields);
1002
+ append(childNode, ulElement);
1003
+ this.liCollections = <HTMLElement[] & NodeListOf<Element>>this.list.querySelectorAll('.' + dropDownBaseClasses.li);
1004
+ this.updateListValues();
1005
+ this.raiseDataBound(listItems, e);
1006
+ },
1007
+ 0);
1008
+ } else {
1009
+ this.raiseDataBound(listItems, e);
1010
+ }
1011
+ }
1012
+ protected updateListValues(): void {
1013
+ // Used this method in component side.
1014
+ }
1015
+ protected findListElement(list: HTMLElement, findNode: string, attribute: string, value: string | boolean | number ): HTMLElement {
1016
+ let liElement: HTMLElement = null;
1017
+ if (list) {
1018
+ const listArr: HTMLElement[] = [].slice.call(list.querySelectorAll(findNode));
1019
+ for (let index: number = 0; index < listArr.length; index++) {
1020
+ if (listArr[index as number].getAttribute(attribute) === (value + '')) {
1021
+ liElement = listArr[index as number];
1022
+ break;
1023
+ }
1024
+ }
1025
+ }
1026
+ return liElement;
1027
+ }
1028
+ private raiseDataBound(
1029
+ listItems: { [key: string]: Object }[] | string[] | boolean[] | number[],
1030
+ e?: object): void {
1031
+ this.hideSpinner();
1032
+ const dataBoundEventArgs: DataBoundEventArgs = {
1033
+ items: listItems,
1034
+ e: e
1035
+ };
1036
+ this.trigger('dataBound', dataBoundEventArgs);
1037
+ }
1038
+ private remainingItems(
1039
+ dataSource: { [key: string]: Object }[] | string[] | number[] | boolean[],
1040
+ fields: FieldSettingsModel): HTMLElement[] {
1041
+ const spliceData: { [key: string]: Object }[] | string[] | number[] | boolean[] =
1042
+ <{ [key: string]: Object }[] | string[] | number[] | boolean[]>new DataManager(
1043
+ dataSource as DataOptions | JSON[]).executeLocal(new Query().skip(100));
1044
+ if (this.itemTemplate) {
1045
+ const listElements: HTMLElement = this.templateListItem(spliceData as { [key: string]: Object }[], fields);
1046
+ return [].slice.call(listElements.childNodes);
1047
+ }
1048
+ const type: string = this.typeOfData(spliceData).typeof as string;
1049
+ if (type === 'string' || type === 'number' || type === 'boolean') {
1050
+ return ListBase.createListItemFromArray(
1051
+ this.createElement, <string[] | number[]>spliceData,
1052
+ true,
1053
+ <{ [key: string]: Object }>this.listOption(spliceData, fields), this);
1054
+ }
1055
+ return ListBase.createListItemFromJson(
1056
+ this.createElement,
1057
+ <{ [key: string]: Object }[]>spliceData,
1058
+ <{ [key: string]: Object }>this.listOption(spliceData, fields),
1059
+ 1,
1060
+ true, this);
1061
+ }
1062
+ private emptyDataRequest(fields: FieldSettingsModel): void {
1063
+ const listItems: { [key: string]: Object }[] = [];
1064
+ this.onActionComplete(this.renderItems(listItems, fields), listItems);
1065
+ this.isRequested = false;
1066
+ this.hideSpinner();
1067
+ }
1068
+ protected showSpinner(): void {
1069
+ // Used this method in component side.
1070
+ }
1071
+ protected hideSpinner(): void {
1072
+ // Used this method in component side.
1073
+ }
1074
+ protected onActionFailure(e: Object): void {
1075
+ this.liCollections = [];
1076
+ this.trigger('actionFailure', e);
1077
+ this.l10nUpdate(true);
1078
+ if (!isNullOrUndefined(this.list)) {
1079
+ addClass([this.list], dropDownBaseClasses.noData);
1080
+ }
1081
+ }
1082
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1083
+ protected onActionComplete(
1084
+ ulElement: HTMLElement,
1085
+ list: { [key: string]: Object }[] | boolean[] | string[] | number[],
1086
+ e?: Object): void {
1087
+ /* eslint-enable @typescript-eslint/no-unused-vars */
1088
+ this.listData = list;
1089
+ if (this.isVirtualizationEnabled) {
1090
+ this.notify("setGeneratedData", {
1091
+ module: "VirtualScroll",
1092
+ });
1093
+ }
1094
+ if (this.getModuleName() !== 'listbox') {
1095
+ ulElement.setAttribute('tabindex', '0'); }
1096
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1097
+ if ((this as any).isReact) {
1098
+ this.clearTemplate(['itemTemplate', 'groupTemplate', 'actionFailureTemplate', 'noRecordsTemplate']);
1099
+ }
1100
+ if(!this.isVirtualizationEnabled){
1101
+ this.fixedHeaderElement = isNullOrUndefined(this.fixedHeaderElement) ? this.fixedHeaderElement : null;
1102
+ }
1103
+ if (this.getModuleName() === 'multiselect' && this.properties.allowCustomValue && this.fields.groupBy) {
1104
+ for (let i: number = 0; i< ulElement.childElementCount; i++) {
1105
+ if (ulElement.children[i as number].classList.contains('e-list-group-item')) {
1106
+ if (isNullOrUndefined(ulElement.children[i as number].innerHTML) || ulElement.children[i as number].innerHTML == "") {
1107
+ addClass([ulElement.children[i as number]], HIDE_GROUPLIST) }
1108
+ }
1109
+ }
1110
+ }
1111
+ if (!isNullOrUndefined(this.list)) {
1112
+ if (!this.isVirtualizationEnabled) {
1113
+ this.list.innerHTML = '';
1114
+ this.list.appendChild(ulElement);
1115
+ this.liCollections = <HTMLElement[] & NodeListOf<Element>>this.list.querySelectorAll('.' + dropDownBaseClasses.li);
1116
+ this.ulElement = this.list.querySelector('ul');
1117
+ this.postRender(this.list, list, this.bindEvent);
1118
+ }
1119
+ }
1120
+ }
1121
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1122
+ protected postRender(
1123
+ listElement: HTMLElement,
1124
+ list: { [key: string]: Object }[] | number[] | string[] | boolean[],
1125
+ bindEvent: boolean): void {
1126
+ /* eslint-enable @typescript-eslint/no-unused-vars */
1127
+ const focusItem: Element = listElement.querySelector('.' + dropDownBaseClasses.li);
1128
+ const selectedItem: Element = listElement.querySelector('.' + dropDownBaseClasses.selected);
1129
+ if (focusItem && !selectedItem) {
1130
+ focusItem.classList.add(dropDownBaseClasses.focus);
1131
+ }
1132
+ if (list.length <= 0) {
1133
+ this.l10nUpdate();
1134
+ addClass([listElement], dropDownBaseClasses.noData);
1135
+ } else {
1136
+ listElement.classList.remove(dropDownBaseClasses.noData);
1137
+ }
1138
+ }
1139
+
1140
+ /**
1141
+ * Get the query to do the data operation before list item generation.
1142
+ *
1143
+ * @param {Query} query - Accepts the external Query that execute along with data processing.
1144
+ * @returns {Query} Returns the query to do the data query operation.
1145
+ */
1146
+ protected getQuery(query: Query): Query {
1147
+ return query ? query : this.query ? this.query : new Query();
1148
+ }
1149
+
1150
+ protected updateVirtualizationProperties(itemCount: number, filtering: boolean): void {
1151
+ this.isVirtualizationEnabled = true;
1152
+ this.virtualizedItemsCount = itemCount;
1153
+ this.isAllowFiltering = filtering;
1154
+ }
1155
+ /**
1156
+ * To render the template content for group header element.
1157
+ *
1158
+ * @param {HTMLElement} listEle - Specifies the group list elements.
1159
+ * @returns {void}
1160
+ */
1161
+ private renderGroupTemplate(listEle: HTMLElement): void {
1162
+ if (this.fields.groupBy !== null && this.dataSource || this.element.querySelector('.' + dropDownBaseClasses.group)) {
1163
+ const dataSource: { [key: string]: Object }[] = <{ [key: string]: Object }[]>this.dataSource;
1164
+ const option: { [key: string]: Object } = { groupTemplateID: this.groupTemplateId, isStringTemplate: this.isStringTemplate };
1165
+ const headerItems: Element[] = <NodeListOf<Element> & Element[]>listEle.querySelectorAll('.' + dropDownBaseClasses.group);
1166
+ const groupcheck: boolean = this.templateCompiler(this.groupTemplate);
1167
+ if (typeof this.groupTemplate !== 'function' && groupcheck) {
1168
+ const groupValue: string = select(this.groupTemplate, document).innerHTML.trim();
1169
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1170
+ const tempHeaders: Element[] = ListBase.renderGroupTemplate(
1171
+ groupValue as string, <{ [key: string]: Object }[]>dataSource,
1172
+ (this.fields as FieldSettingsModel & { properties: Object }).properties,
1173
+ headerItems, option, this);
1174
+ //EJ2-55168- Group checkbox is not working with group template
1175
+ if (this.isGroupChecking) {
1176
+ for (let i: number = 0; i < tempHeaders.length; i++) {
1177
+ this.notify('addItem', { module: 'CheckBoxSelection', item: tempHeaders[i as number] });
1178
+ }
1179
+ }
1180
+ } else {
1181
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1182
+ const tempHeaders: Element[] = ListBase.renderGroupTemplate(
1183
+ this.groupTemplate as string, <{ [key: string]: Object }[]>dataSource,
1184
+ (this.fields as FieldSettingsModel & { properties: Object }).properties,
1185
+ headerItems, option, this);
1186
+ //EJ2-55168- Group checkbox is not working with group template
1187
+ if (this.isGroupChecking) {
1188
+ for (let i: number = 0; i < tempHeaders.length; i++) {
1189
+ this.notify('addItem', { module: 'CheckBoxSelection', item: tempHeaders[i as number] });
1190
+ }
1191
+ }
1192
+ }
1193
+ this.renderReactTemplates();
1194
+ }
1195
+ }
1196
+ /**
1197
+ * To create the ul li list items
1198
+ *
1199
+ * @param {object []} dataSource - Specifies the data to generate the list.
1200
+ * @param {FieldSettingsModel} fields - Maps the columns of the data table and binds the data to the component.
1201
+ * @returns {HTMLElement} Return the ul li list items.
1202
+ */
1203
+ private createListItems(dataSource: { [key: string]: Object }[], fields: FieldSettingsModel): HTMLElement {
1204
+ if (dataSource && fields.groupBy || this.element.querySelector('optgroup')) {
1205
+ if (fields.groupBy) {
1206
+ if (this.sortOrder !== 'None') {
1207
+ dataSource = this.getSortedDataSource(dataSource);
1208
+ }
1209
+ dataSource = ListBase.groupDataSource(
1210
+ dataSource, (fields as FieldSettingsModel & { properties: Object }).properties, this.sortOrder);
1211
+ }
1212
+ addClass([this.list], dropDownBaseClasses.grouping);
1213
+ } else {
1214
+ dataSource = this.getSortedDataSource(dataSource);
1215
+ }
1216
+ const options: { [key: string]: Object } = <{ [key: string]: Object }>this.listOption(dataSource, fields);
1217
+ const spliceData: { [key: string]: Object }[] = (dataSource.length > 100) ?
1218
+ <{ [key: string]: Object }[]>new DataManager(dataSource as DataOptions | JSON[]).executeLocal(new Query().take(100))
1219
+ : dataSource;
1220
+ this.sortedData = dataSource;
1221
+ return ListBase.createList(
1222
+ this.createElement, (this.getModuleName() === 'autocomplete') ? spliceData : dataSource, options, true, this);
1223
+ }
1224
+
1225
+ protected listOption(
1226
+ dataSource: { [key: string]: Object }[] | string[] | number[] | boolean[],
1227
+ fields: FieldSettingsModel): FieldSettingsModel {
1228
+ const iconCss: boolean = isNullOrUndefined(fields.iconCss) ? false : true;
1229
+ const fieldValues: FieldSettingsModel = !isNullOrUndefined((fields as FieldSettingsModel & { properties: Object }).properties) ?
1230
+ (fields as FieldSettingsModel & { properties: Object }).properties : fields;
1231
+ const options: { [key: string]: Object } = (fields.text !== null || fields.value !== null) ? {
1232
+ fields: fieldValues,
1233
+ showIcon: iconCss, ariaAttributes: { groupItemRole: 'presentation' }
1234
+ } : { fields: { value: 'text' } as Object };
1235
+ return extend({}, options, fields, true);
1236
+ }
1237
+
1238
+ protected setFloatingHeader(e: Event): void {
1239
+ if (!isNullOrUndefined(this.list) && !this.list.classList.contains(dropDownBaseClasses.noData)) {
1240
+ if (isNullOrUndefined(this.fixedHeaderElement)) {
1241
+ this.fixedHeaderElement = this.createElement('div', { className: dropDownBaseClasses.fixedHead });
1242
+ if ( !isNullOrUndefined(this.list) && !this.list.querySelector('li').classList.contains(dropDownBaseClasses.group)) {
1243
+ this.fixedHeaderElement.style.display = 'none';
1244
+ }
1245
+ if (!isNullOrUndefined(this.fixedHeaderElement) && !isNullOrUndefined(this.list)) {
1246
+ prepend([this.fixedHeaderElement], this.list);
1247
+ }
1248
+ this.setFixedHeader();
1249
+ }
1250
+ if (!isNullOrUndefined(this.fixedHeaderElement) && this.fixedHeaderElement.style.zIndex === '0') {
1251
+ this.setFixedHeader();
1252
+ }
1253
+ this.scrollStop(e);
1254
+ }
1255
+ }
1256
+
1257
+ protected scrollStop(e?: Event, isDownkey?: boolean): void {
1258
+ const target: Element = !isNullOrUndefined(e) ? <Element>e.target : this.list;
1259
+ const liHeight: number = parseInt(getComputedStyle(this.getValidLi(), null).getPropertyValue('height'), 10);
1260
+ const topIndex: number = Math.round(target.scrollTop / liHeight);
1261
+ const liCollections: NodeListOf<Element> = <NodeListOf<Element>>this.list.querySelectorAll('li' + ':not(.e-hide-listitem)');
1262
+ let virtualListCount: number = this.list.querySelectorAll('.e-virtual-list').length;
1263
+ let count:number = 0;
1264
+ let isCount: boolean = false;
1265
+ for (let i: number = topIndex; i > -1; i--) {
1266
+ const index: number = this.isVirtualizationEnabled ? i + virtualListCount : i;
1267
+ if (this.isVirtualizationEnabled) {
1268
+ const groupListLength: number = this.list.querySelectorAll('.e-list-group-item').length;
1269
+ let loadedGroupList: number = 0;
1270
+ if (isCount) {
1271
+ count++;
1272
+ }
1273
+ if (this.updateGroupHeader(index, liCollections, target)) {
1274
+ loadedGroupList++;
1275
+ if (count >= this.getPageCount()) {
1276
+ break;
1277
+ }
1278
+ if (groupListLength <= loadedGroupList) {
1279
+ break;
1280
+ }
1281
+ }
1282
+ if (isDownkey) {
1283
+ if ((!isNullOrUndefined(liCollections[index as number]) && liCollections[index as number].classList.contains(dropDownBaseClasses.selected) && this.getModuleName() !== 'autocomplete') || (!isNullOrUndefined(liCollections[index as number]) && liCollections[index as number].classList.contains(dropDownBaseClasses.focus) && this.getModuleName() === 'autocomplete')) {
1284
+ count++;
1285
+ isCount = true;
1286
+ }
1287
+ }
1288
+ } else {
1289
+ if (this.updateGroupHeader(index, liCollections, target)) {
1290
+ break;
1291
+ }
1292
+ }
1293
+ }
1294
+ }
1295
+
1296
+ protected getPageCount(returnExactCount?: boolean): number {
1297
+ const liHeight: string = this.list.classList.contains(dropDownBaseClasses.noData) ? null :
1298
+ getComputedStyle(this.getItems()[0], null).getPropertyValue('height');
1299
+ let pageCount = Math.round(this.list.getBoundingClientRect().height / parseInt(liHeight, 10));
1300
+ return returnExactCount? pageCount : Math.round(pageCount);
1301
+ }
1302
+
1303
+ private updateGroupHeader(index: number, liCollections: NodeListOf<Element>, target: Element): boolean {
1304
+ if (!isNullOrUndefined(liCollections[index as number]) && liCollections[index as number].classList.contains(dropDownBaseClasses.group)) {
1305
+ this.updateGroupFixedHeader(liCollections[index as number] as HTMLElement, target);
1306
+ return true;
1307
+ } else {
1308
+ this.fixedHeaderElement.style.display = 'none';
1309
+ this.fixedHeaderElement.style.top = 'none';
1310
+ return false;
1311
+ }
1312
+ }
1313
+
1314
+ private updateGroupFixedHeader(element: HTMLElement, target: Element): void {
1315
+ this.fixedHeaderElement.innerHTML = element.innerHTML;
1316
+ this.fixedHeaderElement.style.top = target.scrollTop + 'px';
1317
+ this.fixedHeaderElement.style.display = 'block';
1318
+ }
1319
+
1320
+ protected getValidLi() : HTMLElement {
1321
+ return this.liCollections[0];
1322
+ }
1323
+
1324
+ /**
1325
+ * To render the list items
1326
+ *
1327
+ * @param {object[]} listData - Specifies the list of array of data.
1328
+ * @param {FieldSettingsModel} fields - Maps the columns of the data table and binds the data to the component.
1329
+ * @returns {HTMLElement} Return the list items.
1330
+ */
1331
+ protected renderItems(listData: { [key: string]: Object }[], fields: FieldSettingsModel): HTMLElement {
1332
+ let ulElement: HTMLElement;
1333
+ if (this.itemTemplate && listData) {
1334
+ let dataSource: { [key: string]: Object }[] = listData;
1335
+ if (dataSource && fields.groupBy) {
1336
+ if (this.sortOrder !== 'None') {
1337
+ dataSource = this.getSortedDataSource(dataSource);
1338
+ }
1339
+ dataSource = ListBase.groupDataSource(
1340
+ dataSource, (fields as FieldSettingsModel & { properties: Object }).properties, this.sortOrder);
1341
+ } else {
1342
+ dataSource = this.getSortedDataSource(dataSource);
1343
+ }
1344
+ this.sortedData = dataSource;
1345
+ const spliceData: { [key: string]: Object }[] = (dataSource.length > 100) ?
1346
+ <{ [key: string]: Object }[]>new DataManager(dataSource as DataOptions | JSON[]).executeLocal(new Query().take(100))
1347
+ : dataSource;
1348
+ ulElement = this.templateListItem((this.getModuleName() === 'autocomplete') ? spliceData : dataSource, fields);
1349
+ if (this.isVirtualizationEnabled) {
1350
+ var oldUlElement = this.list.querySelector('.e-list-parent');
1351
+ var virtualUlElement = this.list.querySelector('.e-virtual-ddl-content');
1352
+ if ((listData.length >= this.virtualizedItemsCount && oldUlElement && virtualUlElement) || (oldUlElement && virtualUlElement && this.isAllowFiltering) || (oldUlElement && virtualUlElement && this.getModuleName() === 'autocomplete')) {
1353
+ virtualUlElement.replaceChild(ulElement, oldUlElement);
1354
+ this.updateListElements(listData);
1355
+ }
1356
+ else if ((!virtualUlElement)) {
1357
+ this.list.innerHTML = '';
1358
+ this.createVirtualContent();
1359
+ this.list.querySelector('.e-virtual-ddl-content').appendChild(ulElement);
1360
+ this.updateListElements(listData);
1361
+ }
1362
+ }
1363
+ } else {
1364
+ ulElement = this.createListItems(listData, fields);
1365
+ if(this.isIncrementalRequest){
1366
+ this.incrementalLiCollections = <HTMLElement[] & NodeListOf<Element>>ulElement.querySelectorAll('.' + dropDownBaseClasses.li);
1367
+ this.incrementalUlElement = ulElement;
1368
+ this.incrementalListData = listData;
1369
+ return ulElement;
1370
+ }
1371
+ if (this.isVirtualizationEnabled) {
1372
+ var oldUlElement = this.list.querySelector('.e-list-parent');
1373
+ var virtualUlElement = this.list.querySelector('.e-virtual-ddl-content');
1374
+ if ((listData.length >= this.virtualizedItemsCount && oldUlElement && virtualUlElement) || (oldUlElement && virtualUlElement && this.isAllowFiltering) || (oldUlElement && virtualUlElement && this.getModuleName() === 'autocomplete')) {
1375
+ virtualUlElement.replaceChild(ulElement, oldUlElement);
1376
+ this.updateListElements(listData);
1377
+ }
1378
+ else if ((!virtualUlElement)) {
1379
+ this.list.innerHTML = '';
1380
+ this.createVirtualContent();
1381
+ this.list.querySelector('.e-virtual-ddl-content').appendChild(ulElement);
1382
+ this.updateListElements(listData);
1383
+ }
1384
+ }
1385
+ }
1386
+ return ulElement;
1387
+ }
1388
+
1389
+ private createVirtualContent(): void {
1390
+ if (!this.list.querySelector('.e-virtual-ddl-content')) {
1391
+ this.list.appendChild(this.createElement('div', {
1392
+ className: 'e-virtual-ddl-content',
1393
+ }));
1394
+ }
1395
+ }
1396
+
1397
+ private updateListElements(listData: { [key: string]: Object }[]): void {
1398
+ this.liCollections = <HTMLElement[] & NodeListOf<Element>>this.list.querySelectorAll('.' + dropDownBaseClasses.li);
1399
+ this.ulElement = this.list.querySelector('ul');
1400
+ this.listData = listData;
1401
+ this.postRender(this.list, listData, this.bindEvent);
1402
+ }
1403
+
1404
+ protected templateListItem(dataSource: { [key: string]: Object }[], fields: FieldSettingsModel): HTMLElement {
1405
+ const option: { [key: string]: Object } = <{ [key: string]: Object }>this.listOption(dataSource, fields);
1406
+ option.templateID = this.itemTemplateId;
1407
+ option.isStringTemplate = this.isStringTemplate;
1408
+ const itemcheck: boolean = this.templateCompiler(this.itemTemplate);
1409
+ if (typeof this.itemTemplate !== 'function' && itemcheck) {
1410
+ const itemValue: string = select(this.itemTemplate, document).innerHTML.trim();
1411
+ return ListBase.renderContentTemplate(
1412
+ this.createElement, itemValue, dataSource,
1413
+ (fields as FieldSettingsModel & { properties: Object }).properties, option, this);
1414
+ } else {
1415
+ return ListBase.renderContentTemplate(
1416
+ this.createElement, this.itemTemplate as any, dataSource,
1417
+ (fields as FieldSettingsModel & { properties: Object }).properties, option, this);
1418
+ }
1419
+ }
1420
+
1421
+ protected typeOfData(items:
1422
+ { [key: string]: Object }[] | string[] | number[] | boolean[]): { [key: string]: Object } {
1423
+ let item: { [key: string]: Object } = { typeof: null, item: null };
1424
+ for (let i: number = 0; (!isNullOrUndefined(items) && i < items.length); i++) {
1425
+ if (!isNullOrUndefined(items[i as number])) {
1426
+ const listDataType: boolean = typeof (items[i as number]) === 'string' ||
1427
+ typeof (items[i as number]) === 'number' || typeof (items[i as number]) === 'boolean';
1428
+ const isNullData: boolean = listDataType ? isNullOrUndefined(items[i as number]) :
1429
+ isNullOrUndefined(getValue((this.fields.value ? this.fields.value : 'value'), items[i as number]));
1430
+ if (!isNullData) {
1431
+ return item = { typeof: typeof items[i as number], item: items[i as number] };
1432
+ }
1433
+ }
1434
+ }
1435
+ return item;
1436
+ }
1437
+
1438
+ protected setFixedHeader(): void {
1439
+ if (!isNullOrUndefined(this.list)) {
1440
+ this.list.parentElement.style.display = 'block';
1441
+ }
1442
+ let borderWidth: number = 0;
1443
+ if (this.list && this.list.parentElement) {
1444
+ borderWidth = parseInt(
1445
+ document.defaultView.getComputedStyle(this.list.parentElement, null).getPropertyValue('border-width'), 10
1446
+ );
1447
+ /*Shorthand property not working in Firefox for getComputedStyle method.
1448
+ Refer bug report https://bugzilla.mozilla.org/show_bug.cgi?id=137688
1449
+ Refer alternate solution https://stackoverflow.com/a/41696234/9133493*/
1450
+ if (isNaN(borderWidth)) {
1451
+ let borderTopWidth: number = parseInt(document.defaultView.getComputedStyle(this.list.parentElement, null).getPropertyValue('border-top-width'), 10);
1452
+ let borderBottomWidth: number = parseInt(document.defaultView.getComputedStyle(this.list.parentElement, null).getPropertyValue('border-bottom-width'), 10);
1453
+ let borderLeftWidth: number = parseInt(document.defaultView.getComputedStyle(this.list.parentElement, null).getPropertyValue('border-left-width'), 10);
1454
+ let borderRightWidth: number = parseInt(document.defaultView.getComputedStyle(this.list.parentElement, null).getPropertyValue('border-right-width'), 10);
1455
+ borderWidth = (borderTopWidth + borderBottomWidth + borderLeftWidth + borderRightWidth);
1456
+ }
1457
+ }
1458
+ if (!isNullOrUndefined(this.liCollections)) {
1459
+ const liWidth: number = this.getValidLi().offsetWidth - borderWidth;
1460
+ this.fixedHeaderElement.style.width = liWidth.toString() + 'px';
1461
+ }
1462
+ setStyleAttribute(this.fixedHeaderElement, { zIndex: 10 });
1463
+ const firstLi: HTMLElement = this.ulElement.querySelector('.' + dropDownBaseClasses.group + ':not(.e-hide-listitem)') as HTMLElement;
1464
+ this.fixedHeaderElement.innerHTML = firstLi.innerHTML;
1465
+ }
1466
+ private getSortedDataSource(dataSource: { [key: string]: Object }[]): { [key: string]: Object }[] {
1467
+ if (dataSource && this.sortOrder !== 'None') {
1468
+ let textField: string = this.fields.text ? this.fields.text : 'text';
1469
+ if (this.typeOfData(dataSource).typeof === 'string' || this.typeOfData(dataSource).typeof === 'number'
1470
+ || this.typeOfData(dataSource).typeof === 'boolean') {
1471
+ textField = '';
1472
+ }
1473
+ dataSource = ListBase.getDataSource(dataSource, ListBase.addSorting(this.sortOrder, textField));
1474
+ }
1475
+ return dataSource;
1476
+ }
1477
+ /**
1478
+ * Return the index of item which matched with given value in data source
1479
+ *
1480
+ * @param {string | number | boolean} value - Specifies given value.
1481
+ * @returns {number} Returns the index of the item.
1482
+ */
1483
+ protected getIndexByValue(value: string | number | boolean): number {
1484
+ let index: number;
1485
+ const listItems: Element[] = this.getItems();
1486
+ for (let i: number = 0; i < listItems.length; i++) {
1487
+ if (!isNullOrUndefined(value) && listItems[i as number].getAttribute('data-value') === value.toString()) {
1488
+ index = i;
1489
+ break;
1490
+ }
1491
+ }
1492
+ return index;
1493
+ }
1494
+ /**
1495
+ * Return the index of item which matched with given value in data source
1496
+ *
1497
+ * @param {string | number | boolean} value - Specifies given value.
1498
+ * @returns {number} Returns the index of the item.
1499
+ */
1500
+ protected getIndexByValueFilter(value: string | number | boolean): number {
1501
+ let index: number;
1502
+ const listItems: HTMLElement = this.renderItems(this.selectData as { [key: string]: Object }[], this.fields);
1503
+ for (let i: number = 0; i < listItems.children.length; i++) {
1504
+ if (!isNullOrUndefined(value) && listItems.children[i as number].getAttribute('data-value') === value.toString()) {
1505
+ index = i;
1506
+ break;
1507
+ }
1508
+ }
1509
+ return index;
1510
+ }
1511
+ /**
1512
+ * To dispatch the event manually
1513
+ *
1514
+ * @param {HTMLElement} element - Specifies the element to dispatch the event.
1515
+ * @param {string} type - Specifies the name of the event.
1516
+ * @returns {void}
1517
+ */
1518
+ protected dispatchEvent(element: HTMLElement, type: string): void {
1519
+ const evt: Event = document.createEvent('HTMLEvents');
1520
+ evt.initEvent(type, false, true);
1521
+ if(element){
1522
+ element.dispatchEvent(evt);
1523
+ }
1524
+ }
1525
+ /**
1526
+ * To set the current fields
1527
+ *
1528
+ * @returns {void}
1529
+ */
1530
+ protected setFields(): void {
1531
+ if (this.fields.value && !this.fields.text) {
1532
+ this.updateFields(this.fields.value, this.fields.value);
1533
+ } else if (!this.fields.value && this.fields.text) {
1534
+ this.updateFields(this.fields.text, this.fields.text);
1535
+ } else if (!this.fields.value && !this.fields.text) {
1536
+ this.updateFields('text', 'text');
1537
+ }
1538
+ }
1539
+ /**
1540
+ * reset the items list.
1541
+ *
1542
+ * @param {Object[] | string[] | number[] | DataManager | boolean[]} dataSource - Specifies the data to generate the list.
1543
+ * @param {FieldSettingsModel} fields - Maps the columns of the data table and binds the data to the component.
1544
+ * @param {Query} query - Accepts the external Query that execute along with data processing.
1545
+ * @returns {void}
1546
+ */
1547
+ protected resetList(
1548
+ dataSource?: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[],
1549
+ fields?: FieldSettingsModel, query?: Query, e?: MouseEvent | KeyboardEventArgs | TouchEvent): void {
1550
+ if (this.list) {
1551
+ if ((this.element.tagName === 'SELECT' && (<HTMLSelectElement>this.element).options.length > 0)
1552
+ || (this.element.tagName === 'UL' && (<HTMLUListElement>this.element).childNodes.length > 0)) {
1553
+ const data: boolean = dataSource instanceof Array ? (dataSource.length > 0)
1554
+ : !isNullOrUndefined(dataSource);
1555
+ if (!data && this.selectData && this.selectData.length > 0) {
1556
+ dataSource = this.selectData;
1557
+ }
1558
+ }
1559
+ dataSource = this.getModuleName() === 'combobox' && this.selectData && dataSource instanceof Array && dataSource.length < this.selectData.length && this.addedNewItem ? this.selectData : dataSource;
1560
+ this.addedNewItem = false;
1561
+ this.setListData(dataSource, fields, query, e);
1562
+ }
1563
+ }
1564
+
1565
+ protected updateSelectElementData(isFiltering: boolean): void {
1566
+ if ((isFiltering || this.isVirtualizationEnabled) && isNullOrUndefined(this.selectData) && this.listData && this.listData.length > 0) {
1567
+ this.selectData = this.listData;
1568
+ }
1569
+ }
1570
+
1571
+ protected updateSelection(): void {
1572
+ // This is for after added the item, need to update the selected index values.
1573
+ }
1574
+ protected renderList(): void {
1575
+ // This is for render the list items.
1576
+ this.render();
1577
+ }
1578
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1579
+ protected updateDataSource(props?: DropDownBaseModel): void {
1580
+ this.resetList(this.dataSource);
1581
+ this.totalItemCount = this.dataSource instanceof DataManager ? this.dataSource.dataSource.json.length : 0;
1582
+ }
1583
+ protected setUpdateInitial(props: string[], newProp: { [key: string]: string }): void {
1584
+ this.isDataFetched = false;
1585
+ const updateData: { [key: string]: string | { [key: string]: Object }[] } = {};
1586
+ for (let j: number = 0; props.length > j; j++) {
1587
+ if ((newProp as { [key: string]: string })[props[j as number]] && props[j as number] === 'fields') {
1588
+ this.setFields();
1589
+ (updateData as { [key: string]: string })[props[j as number]] = (newProp as { [key: string]: string })[props[j as number]];
1590
+ } else if ((newProp as { [key: string]: string })[props[j as number]]) {
1591
+ (updateData as { [key: string]: string })[props[j as number]] = (newProp as { [key: string]: string })[props[j as number]];
1592
+ }
1593
+ }
1594
+ if (Object.keys(updateData).length > 0) {
1595
+ if (Object.keys(updateData).indexOf('dataSource') === -1) {
1596
+ (updateData as { [key: string]: { [key: string]: Object }[] }).dataSource = this.dataSource as
1597
+ { [key: string]: Object }[];
1598
+ }
1599
+ this.updateDataSource(updateData);
1600
+ }
1601
+ }
1602
+
1603
+ /**
1604
+ * When property value changes happened, then onPropertyChanged method will execute the respective changes in this component.
1605
+ *
1606
+ * @param {DropDownBaseModel} newProp - Returns the dynamic property value of the component.
1607
+ * @param {DropDownBaseModel} oldProp - Returns the previous property value of the component.
1608
+ * @private
1609
+ * @returns {void}
1610
+ */
1611
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1612
+ public onPropertyChanged(newProp: DropDownBaseModel, oldProp: DropDownBaseModel): void {
1613
+ if (this.getModuleName() === 'dropdownbase') {
1614
+ this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp as { [key: string]: string });
1615
+ }
1616
+ this.setUpdateInitial(['sortOrder', 'itemTemplate'], newProp as { [key: string]: string });
1617
+ for (const prop of Object.keys(newProp)) {
1618
+ switch (prop) {
1619
+ case 'query':
1620
+ case 'sortOrder':
1621
+ case 'dataSource':
1622
+ case 'itemTemplate':
1623
+ break;
1624
+ case 'enableRtl':
1625
+ this.setEnableRtl();
1626
+ break;
1627
+ case 'groupTemplate':
1628
+ this.renderGroupTemplate(this.list);
1629
+ if (this.ulElement && this.fixedHeaderElement) {
1630
+ const firstLi: HTMLElement = this.ulElement.querySelector('.' + dropDownBaseClasses.group) as HTMLElement;
1631
+ this.fixedHeaderElement.innerHTML = firstLi.innerHTML;
1632
+ }
1633
+ break;
1634
+ case 'locale':
1635
+ if (this.list && (!isNullOrUndefined(this.liCollections) && this.liCollections.length === 0)) {
1636
+ this.l10nUpdate();
1637
+ }
1638
+ break;
1639
+ case 'zIndex':
1640
+ this.setProperties({ zIndex: newProp.zIndex }, true);
1641
+ this.setZIndex();
1642
+ break;
1643
+ }
1644
+ }
1645
+ }
1646
+ /**
1647
+ * Build and render the component
1648
+ *
1649
+ * @param {boolean} isEmptyData - Specifies the component to initialize with list data or not.
1650
+ * @private
1651
+ * @returns {void}
1652
+ */
1653
+ public render(e?: MouseEvent | KeyboardEventArgs | TouchEvent, isEmptyData?: boolean): void {
1654
+ if (this.getModuleName() === 'listbox') {
1655
+ this.list = this.createElement('div', { className: dropDownBaseClasses.content, attrs: { 'tabindex': '0' } }); }
1656
+ else {
1657
+ this.list = this.createElement('div', { className: dropDownBaseClasses.content});
1658
+ }
1659
+ this.list.classList.add(dropDownBaseClasses.root);
1660
+ this.setFields();
1661
+ const rippleModel: RippleOptions = { duration: 300, selector: '.' + dropDownBaseClasses.li };
1662
+ this.rippleFun = rippleEffect(this.list, rippleModel);
1663
+ const group: HTMLElement = <HTMLElement>this.element.querySelector('select>optgroup');
1664
+ if ((this.fields.groupBy || !isNullOrUndefined(group)) && !this.isGroupChecking) {
1665
+ EventHandler.add(this.list, 'scroll', this.setFloatingHeader, this);
1666
+ }
1667
+ if (this.getModuleName() === 'dropdownbase') {
1668
+ if (this.element.getAttribute('tabindex')) {
1669
+ this.list.setAttribute('tabindex', this.element.getAttribute('tabindex'));
1670
+ }
1671
+ removeClass([this.element], dropDownBaseClasses.root);
1672
+ this.element.style.display = 'none';
1673
+ const wrapperElement: HTMLElement = this.createElement('div');
1674
+ this.element.parentElement.insertBefore(wrapperElement, this.element);
1675
+ wrapperElement.appendChild(this.element);
1676
+ wrapperElement.appendChild(this.list);
1677
+ }
1678
+ this.setEnableRtl();
1679
+ if (!isEmptyData) {
1680
+ this.initialize(e);
1681
+ }
1682
+ }
1683
+ protected removeScrollEvent() : void
1684
+ {
1685
+ if (this.list) {
1686
+ EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
1687
+ }
1688
+ }
1689
+ /**
1690
+ * Return the module name of this component.
1691
+ *
1692
+ * @private
1693
+ * @returns {string} Return the module name of this component.
1694
+ */
1695
+ public getModuleName(): string {
1696
+ return 'dropdownbase';
1697
+ }
1698
+ /* eslint-disable valid-jsdoc, jsdoc/require-returns-description */
1699
+ /**
1700
+ * Gets all the list items bound on this component.
1701
+ *
1702
+ * @returns {Element[]}
1703
+ */
1704
+ public getItems(): Element[] {
1705
+ return <HTMLElement[] & NodeListOf<Element>>this.ulElement.querySelectorAll('.' + dropDownBaseClasses.li);
1706
+ }
1707
+ /* eslint-enable valid-jsdoc, jsdoc/require-returns-description */
1708
+ /**
1709
+ * Adds a new item to the popup list. By default, new item appends to the list as the last item,
1710
+ * but you can insert based on the index parameter.
1711
+ *
1712
+ * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
1713
+ * @param { number } itemIndex - Specifies the index to place the newly added item in the popup list.
1714
+ * @returns {void}
1715
+ * @deprecated
1716
+ */
1717
+ public addItem(
1718
+ items: { [key: string]: Object }[] | { [key: string]: Object } | string | boolean | number | string[] | boolean[] | number[],
1719
+ itemIndex?: number): void {
1720
+ if (!this.list || (this.list.textContent === this.noRecordsTemplate && this.getModuleName() !== 'listbox')) {
1721
+ this.renderList();
1722
+ }
1723
+ if (this.sortOrder !== 'None' && isNullOrUndefined(itemIndex)) {
1724
+ let newList: { [key: string]: Object }[] = [].slice.call(this.listData as { [key: string]: Object }[]);
1725
+ newList.push(items as { [key: string]: Object });
1726
+ newList = this.getSortedDataSource(newList);
1727
+ if (this.fields.groupBy) {
1728
+ newList = ListBase.groupDataSource(
1729
+ newList, (this.fields as FieldSettingsModel & { properties: Object }).properties, this.sortOrder);
1730
+ itemIndex = newList.indexOf(items as { [key: string]: Object });
1731
+ } else {
1732
+ itemIndex = newList.indexOf(items as { [key: string]: Object });
1733
+ }
1734
+ }
1735
+ const itemsCount: number = this.getItems().length;
1736
+ const selectedItemValue: Element = this.list.querySelector('.' + dropDownBaseClasses.selected);
1737
+ items = (items instanceof Array ? items : [items]) as { [key: string]: Object }[] | string[] | boolean[] | number[];
1738
+ let index: number;
1739
+ index = (isNullOrUndefined(itemIndex) || itemIndex < 0 || itemIndex > itemsCount - 1) ? itemsCount : itemIndex;
1740
+ const fields: FieldSettingsModel = this.fields;
1741
+ if (items && fields.groupBy) {
1742
+ items = ListBase.groupDataSource(
1743
+ (items as { [key: string]: Object }[]), (fields as FieldSettingsModel & { properties: Object }).properties);
1744
+ }
1745
+ const liCollections: HTMLElement[] = [];
1746
+ for (let i: number = 0; i < items.length; i++) {
1747
+ const item: { [key: string]: Object } | string | boolean | number = items[i as number];
1748
+ const isHeader: boolean = (item as { [key: string]: Object }).isHeader as boolean;
1749
+ const li: HTMLElement = this.createElement(
1750
+ 'li', { className: isHeader ? dropDownBaseClasses.group : dropDownBaseClasses.li, id: 'option-add-' + i });
1751
+
1752
+ const itemText: string = item instanceof Object ? getValue(fields.text, item) : item;
1753
+ if (isHeader) {
1754
+ li.innerText = itemText;
1755
+ }
1756
+ if (this.itemTemplate && !isHeader) {
1757
+ const itemCheck: boolean = this.templateCompiler(this.itemTemplate);
1758
+ const compiledString: Function = typeof this.itemTemplate !== 'function' &&
1759
+ itemCheck ? compile(select(this.itemTemplate, document).innerHTML.trim()) : compile(this.itemTemplate);
1760
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1761
+ const addItemTemplate: any = compiledString(
1762
+ item, this, 'itemTemplate', this.itemTemplateId, this.isStringTemplate, null, li);
1763
+ if (addItemTemplate) {
1764
+ append(addItemTemplate, li);
1765
+ }
1766
+ } else if (!isHeader) {
1767
+ li.appendChild(document.createTextNode(itemText));
1768
+ }
1769
+ li.setAttribute('data-value', item instanceof Object ? getValue(fields.value, item) : item);
1770
+ li.setAttribute('role', 'option');
1771
+ this.notify('addItem', { module: 'CheckBoxSelection', item: li });
1772
+ liCollections.push(li);
1773
+ (this.listData as { [key: string]: Object }[]).push(item as { [key: string]: Object });
1774
+ if (this.sortOrder === 'None' && isNullOrUndefined(itemIndex) && index === 0 ) {
1775
+ index = null;
1776
+ }
1777
+ this.updateActionCompleteData(li, item as { [key: string]: Object }, index);
1778
+ //Listbox event
1779
+ this.trigger('beforeItemRender', {element: li, item: item});
1780
+ }
1781
+ if (itemsCount === 0 && isNullOrUndefined(this.list.querySelector('ul'))) {
1782
+ if (!isNullOrUndefined(this.list)) {
1783
+ this.list.innerHTML = '';
1784
+ this.list.classList.remove(dropDownBaseClasses.noData);
1785
+ this.isAddNewItemTemplate = true;
1786
+ if (!isNullOrUndefined(this.ulElement)) {
1787
+ this.list.appendChild(this.ulElement);
1788
+ }
1789
+ }
1790
+ this.liCollections = liCollections;
1791
+ if (!isNullOrUndefined(liCollections) && !isNullOrUndefined(this.ulElement)) {
1792
+ append(liCollections, this.ulElement);
1793
+ }
1794
+ this.updateAddItemList(this.list, itemsCount);
1795
+ } else {
1796
+ if (this.getModuleName() === 'listbox' && itemsCount === 0) {
1797
+ this.ulElement.innerHTML = '';
1798
+ }
1799
+ const attr: string[] = [];
1800
+ for (let i: number = 0; i < items.length; i++) {
1801
+ const listGroupItem: NodeList = this.ulElement.querySelectorAll('.e-list-group-item');
1802
+ for (let j: number = 0; j < listGroupItem.length; j++) {
1803
+ attr[j as number] = (listGroupItem[j as number] as HTMLElement).innerText;
1804
+ }
1805
+ if (attr.indexOf(liCollections[i as number].innerText) > -1 && fields.groupBy) {
1806
+ for (let j: number = 0; j < listGroupItem.length; j++) {
1807
+ if (attr[j as number] === liCollections[i as number].innerText ) {
1808
+ if (this.sortOrder === 'None') {
1809
+ this.ulElement.insertBefore(liCollections[i + 1], listGroupItem[j + 1]);
1810
+ } else {
1811
+ this.ulElement.insertBefore(liCollections[i + 1], this.ulElement.childNodes[itemIndex as number]);
1812
+ }
1813
+ i = i + 1;
1814
+ break;
1815
+ }
1816
+ }
1817
+ } else {
1818
+ if (this.liCollections[index as number]) {
1819
+ this.liCollections[index as number].parentNode.insertBefore(liCollections[i as number], this.liCollections[index as number]);
1820
+ } else {
1821
+ this.ulElement.appendChild(liCollections[i as number]);
1822
+ }
1823
+ }
1824
+ const tempLi: HTMLElement[] = [].slice.call(this.liCollections);
1825
+ tempLi.splice(index, 0, liCollections[i as number]);
1826
+ this.liCollections = tempLi;
1827
+ index += 1;
1828
+ if (this.getModuleName() === 'multiselect') {
1829
+ this.updateDataList();
1830
+ }
1831
+ }
1832
+ }
1833
+ if (this.getModuleName() === 'listbox' && (this as any).isReact) {
1834
+ this.renderReactTemplates();
1835
+ }
1836
+ if (selectedItemValue || itemIndex === 0) {
1837
+ this.updateSelection();
1838
+ }
1839
+ this.addedNewItem = true;
1840
+ }
1841
+ protected validationAttribute(target: HTMLElement, hidden: Element): void {
1842
+ const name: string = target.getAttribute('name') ? target.getAttribute('name') : target.getAttribute('id');
1843
+ hidden.setAttribute('name', name);
1844
+ target.removeAttribute('name');
1845
+ const attributes: string[] = ['required', 'aria-required', 'form'];
1846
+ for (let i: number = 0; i < attributes.length; i++) {
1847
+ if (!target.getAttribute(attributes[i as number])) {
1848
+ continue;
1849
+ }
1850
+ const attr: string = target.getAttribute(attributes[i as number]);
1851
+ hidden.setAttribute(attributes[i as number], attr);
1852
+ target.removeAttribute(attributes[i as number]);
1853
+ }
1854
+ }
1855
+
1856
+ protected setZIndex(): void {
1857
+ // this is for component wise
1858
+ }
1859
+
1860
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1861
+ protected updateActionCompleteData(li: HTMLElement, item: { [key: string]: Object }, index?: number): void {
1862
+ // this is for ComboBox custom value
1863
+ }
1864
+
1865
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1866
+ protected updateAddItemList(list: HTMLElement, itemCount: number): void {
1867
+ // this is for multiselect add item
1868
+ }
1869
+ protected updateDataList(): void {
1870
+ // this is for multiselect update list items
1871
+ }
1872
+ /* eslint-disable valid-jsdoc, jsdoc/require-returns-description */
1873
+ /**
1874
+ * Gets the data Object that matches the given value.
1875
+ *
1876
+ * @param { string | number } value - Specifies the value of the list item.
1877
+ * @returns {Object}
1878
+ */
1879
+ public getDataByValue(value: string | number | boolean)
1880
+ : { [key: string]: Object } | string | number | boolean {
1881
+ if (!isNullOrUndefined(this.listData)) {
1882
+ const type: string = this.typeOfData(this.listData).typeof as string;
1883
+ if (type === 'string' || type === 'number' || type === 'boolean') {
1884
+ for (const item of this.listData) {
1885
+ if (!isNullOrUndefined(item) && item === value as Object) {
1886
+ return item;
1887
+ }
1888
+ }
1889
+ } else {
1890
+ for (const item of this.listData) {
1891
+ if (!isNullOrUndefined(item) && getValue((this.fields.value ? this.fields.value : 'value'), item) === value) {
1892
+ return item;
1893
+ }
1894
+ }
1895
+ }
1896
+ }
1897
+ return null;
1898
+ }
1899
+ /* eslint-enable valid-jsdoc, jsdoc/require-returns-description */
1900
+ /**
1901
+ * Removes the component from the DOM and detaches all its related event handlers. It also removes the attributes and classes.
1902
+ *
1903
+ * @method destroy
1904
+ * @returns {void}
1905
+ */
1906
+ public destroy(): void {
1907
+ if (document.body.contains(this.list)) {
1908
+ EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
1909
+ if (!isNullOrUndefined(this.rippleFun)) {
1910
+ this.rippleFun();
1911
+ }
1912
+ detach(this.list);
1913
+ }
1914
+ this.liCollections = null;
1915
+ this.ulElement = null;
1916
+ this.list = null;
1917
+ this.enableRtlElements = null;
1918
+ this.rippleFun = null;
1919
+ super.destroy();
1920
+ }
1921
+ }
1922
+ export interface ResultData {
1923
+ /**
1924
+ * To return the JSON result.
1925
+ */
1926
+ result: { [key: string]: Object }[]
1927
+ }
1928
+
1929
+ export interface FilteringEventArgs {
1930
+ /**
1931
+ * To prevent the internal filtering action.
1932
+ */
1933
+ preventDefaultAction: boolean
1934
+ /**
1935
+ * Gets the `keyup` event arguments.
1936
+ */
1937
+ baseEventArgs: Object
1938
+ /**
1939
+ * Illustrates whether the current action needs to be prevented or not.
1940
+ */
1941
+ cancel: boolean
1942
+ /**
1943
+ * Search text value.
1944
+ */
1945
+ text: string
1946
+ /**
1947
+ * To filter the data from given data source by using query
1948
+ *
1949
+ * @param {Object[] | DataManager } dataSource - Set the data source to filter.
1950
+ * @param {Query} query - Specify the query to filter the data.
1951
+ * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
1952
+ * @returns {void}
1953
+ */
1954
+ updateData(dataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[], query?: Query,
1955
+ fields?: FieldSettingsModel): void
1956
+ }
1957
+ export interface PopupEventArgs {
1958
+ /**
1959
+ * Specifies the popup Object.
1960
+ *
1961
+ * @deprecated
1962
+ */
1963
+ popup: Popup
1964
+ /**
1965
+ * Illustrates whether the current action needs to be prevented or not.
1966
+ */
1967
+ cancel?: boolean
1968
+ /**
1969
+ * Specifies the animation Object.
1970
+ */
1971
+ animation?: AnimationModel
1972
+ /**
1973
+ * Specifies the event.
1974
+ */
1975
+ event?: MouseEvent | KeyboardEventArgs | TouchEvent | Object
1976
+ }
1977
+ export interface FocusEventArgs {
1978
+ /**
1979
+ * Specifies the focus interacted.
1980
+ */
1981
+ isInteracted?: boolean
1982
+ /**
1983
+ * Specifies the event.
1984
+ */
1985
+ event?: MouseEvent | FocusEvent | TouchEvent | KeyboardEvent
1986
+ }