@syncfusion/ej2-dropdowns 23.1.39 → 23.1.40-85814

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