x4js 1.4.52 → 1.4.53

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 (303) hide show
  1. package/lib/{action.js → cjs/action.js} +0 -0
  2. package/lib/{application.js → cjs/application.js} +13 -19
  3. package/lib/{autocomplete.js → cjs/autocomplete.js} +0 -4
  4. package/lib/cjs/base_component.js +124 -0
  5. package/lib/{button.js → cjs/button.js} +4 -4
  6. package/lib/{calendar.js → cjs/calendar.js} +22 -22
  7. package/lib/{canvas.js → cjs/canvas.js} +7 -8
  8. package/lib/{cardview.js → cjs/cardview.js} +3 -5
  9. package/lib/{checkbox.js → cjs/checkbox.js} +6 -5
  10. package/lib/cjs/color.js +591 -0
  11. package/lib/{colorpicker.js → cjs/colorpicker.js} +1 -14
  12. package/lib/{combobox.js → cjs/combobox.js} +2 -6
  13. package/lib/{component.js → cjs/component.js} +16 -25
  14. package/lib/{datastore.js → cjs/datastore.js} +18 -32
  15. package/lib/{dialog.js → cjs/dialog.js} +4 -21
  16. package/lib/{dom_events.js → cjs/dom_events.js} +0 -0
  17. package/lib/{drag_manager.js → cjs/drag_manager.js} +0 -5
  18. package/lib/{drawtext.js → cjs/drawtext.js} +5 -4
  19. package/lib/{fileupload.js → cjs/fileupload.js} +0 -3
  20. package/lib/{form.js → cjs/form.js} +2 -6
  21. package/lib/{formatters.js → cjs/formatters.js} +0 -0
  22. package/lib/{gridview.js → cjs/gridview.js} +20 -33
  23. package/lib/{i18n.js → cjs/i18n.js} +0 -0
  24. package/lib/{icon.js → cjs/icon.js} +17 -11
  25. package/lib/{image.js → cjs/image.js} +4 -5
  26. package/lib/{index.js → cjs/index.js} +0 -0
  27. package/lib/cjs/input.js +174 -0
  28. package/lib/{label.js → cjs/label.js} +2 -1
  29. package/lib/{layout.js → cjs/layout.js} +9 -8
  30. package/lib/{link.js → cjs/link.js} +3 -2
  31. package/lib/cjs/listview.js +544 -0
  32. package/{src/md5.ts → lib/cjs/md5.js} +403 -438
  33. package/lib/{menu.js → cjs/menu.js} +4 -11
  34. package/lib/{messagebox.js → cjs/messagebox.js} +4 -4
  35. package/lib/{panel.js → cjs/panel.js} +3 -4
  36. package/lib/{popup.js → cjs/popup.js} +4 -5
  37. package/lib/{property_editor.js → cjs/property_editor.js} +2 -5
  38. package/lib/{radiobtn.js → cjs/radiobtn.js} +6 -6
  39. package/lib/{rating.js → cjs/rating.js} +7 -6
  40. package/lib/cjs/request.js +246 -0
  41. package/lib/{router.js → cjs/router.js} +0 -1
  42. package/lib/cjs/settings.js +69 -0
  43. package/lib/{sidebarview.js → cjs/sidebarview.js} +2 -3
  44. package/lib/{spreadsheet.js → cjs/spreadsheet.js} +10 -27
  45. package/lib/{styles.js → cjs/styles.js} +5 -6
  46. package/lib/{svgcomponent.js → cjs/svgcomponent.js} +3 -11
  47. package/lib/{tabbar.js → cjs/tabbar.js} +5 -5
  48. package/lib/{tabview.js → cjs/tabview.js} +0 -2
  49. package/lib/{textarea.js → cjs/textarea.js} +4 -3
  50. package/lib/{textedit.js → cjs/textedit.js} +7 -8
  51. package/lib/{toaster.js → cjs/toaster.js} +0 -2
  52. package/lib/{tools.js → cjs/tools.js} +7 -16
  53. package/lib/{tooltips.js → cjs/tooltips.js} +0 -1
  54. package/lib/{treeview.js → cjs/treeview.js} +23 -19
  55. package/lib/{action.d.ts → cjs/types/action.d.ts} +0 -0
  56. package/lib/{application.d.ts → cjs/types/application.d.ts} +0 -0
  57. package/lib/{autocomplete.d.ts → cjs/types/autocomplete.d.ts} +0 -0
  58. package/lib/{base_component.d.ts → cjs/types/base_component.d.ts} +0 -0
  59. package/lib/{button.d.ts → cjs/types/button.d.ts} +0 -0
  60. package/lib/{calendar.d.ts → cjs/types/calendar.d.ts} +0 -0
  61. package/lib/{canvas.d.ts → cjs/types/canvas.d.ts} +0 -0
  62. package/lib/{cardview.d.ts → cjs/types/cardview.d.ts} +0 -0
  63. package/lib/{checkbox.d.ts → cjs/types/checkbox.d.ts} +0 -0
  64. package/lib/{color.d.ts → cjs/types/color.d.ts} +0 -0
  65. package/lib/{colorpicker.d.ts → cjs/types/colorpicker.d.ts} +0 -0
  66. package/lib/{combobox.d.ts → cjs/types/combobox.d.ts} +0 -0
  67. package/lib/{component.d.ts → cjs/types/component.d.ts} +0 -0
  68. package/lib/{datastore.d.ts → cjs/types/datastore.d.ts} +0 -0
  69. package/lib/{dialog.d.ts → cjs/types/dialog.d.ts} +0 -0
  70. package/lib/{dom_events.d.ts → cjs/types/dom_events.d.ts} +0 -0
  71. package/lib/{drag_manager.d.ts → cjs/types/drag_manager.d.ts} +0 -0
  72. package/lib/{drawtext.d.ts → cjs/types/drawtext.d.ts} +0 -0
  73. package/lib/{fileupload.d.ts → cjs/types/fileupload.d.ts} +0 -0
  74. package/lib/{form.d.ts → cjs/types/form.d.ts} +0 -0
  75. package/lib/{formatters.d.ts → cjs/types/formatters.d.ts} +0 -0
  76. package/lib/{gridview.d.ts → cjs/types/gridview.d.ts} +0 -0
  77. package/lib/{i18n.d.ts → cjs/types/i18n.d.ts} +0 -0
  78. package/lib/{icon.d.ts → cjs/types/icon.d.ts} +0 -0
  79. package/lib/{image.d.ts → cjs/types/image.d.ts} +0 -0
  80. package/lib/{index.d.ts → cjs/types/index.d.ts} +0 -0
  81. package/lib/{input.d.ts → cjs/types/input.d.ts} +0 -0
  82. package/lib/{label.d.ts → cjs/types/label.d.ts} +0 -0
  83. package/lib/{layout.d.ts → cjs/types/layout.d.ts} +0 -0
  84. package/lib/{link.d.ts → cjs/types/link.d.ts} +0 -0
  85. package/lib/{listview.d.ts → cjs/types/listview.d.ts} +0 -0
  86. package/lib/{md5.d.ts → cjs/types/md5.d.ts} +0 -0
  87. package/lib/{menu.d.ts → cjs/types/menu.d.ts} +0 -0
  88. package/lib/{messagebox.d.ts → cjs/types/messagebox.d.ts} +0 -0
  89. package/lib/{panel.d.ts → cjs/types/panel.d.ts} +0 -0
  90. package/lib/{popup.d.ts → cjs/types/popup.d.ts} +0 -0
  91. package/lib/{property_editor.d.ts → cjs/types/property_editor.d.ts} +0 -0
  92. package/lib/{radiobtn.d.ts → cjs/types/radiobtn.d.ts} +0 -0
  93. package/lib/{rating.d.ts → cjs/types/rating.d.ts} +0 -0
  94. package/lib/{request.d.ts → cjs/types/request.d.ts} +0 -0
  95. package/lib/{router.d.ts → cjs/types/router.d.ts} +0 -0
  96. package/lib/{settings.d.ts → cjs/types/settings.d.ts} +0 -0
  97. package/lib/{sidebarview.d.ts → cjs/types/sidebarview.d.ts} +0 -0
  98. package/lib/{spreadsheet.d.ts → cjs/types/spreadsheet.d.ts} +0 -0
  99. package/lib/{styles.d.ts → cjs/types/styles.d.ts} +0 -0
  100. package/lib/{svgcomponent.d.ts → cjs/types/svgcomponent.d.ts} +0 -0
  101. package/lib/{tabbar.d.ts → cjs/types/tabbar.d.ts} +0 -0
  102. package/lib/{tabview.d.ts → cjs/types/tabview.d.ts} +0 -0
  103. package/lib/{textarea.d.ts → cjs/types/textarea.d.ts} +0 -0
  104. package/lib/{textedit.d.ts → cjs/types/textedit.d.ts} +0 -0
  105. package/lib/{toaster.d.ts → cjs/types/toaster.d.ts} +0 -0
  106. package/lib/{tools.d.ts → cjs/types/tools.d.ts} +0 -0
  107. package/lib/{tooltips.d.ts → cjs/types/tooltips.d.ts} +0 -0
  108. package/lib/{treeview.d.ts → cjs/types/treeview.d.ts} +0 -0
  109. package/lib/{version.d.ts → cjs/types/version.d.ts} +0 -0
  110. package/lib/{x4dom.d.ts → cjs/types/x4dom.d.ts} +0 -0
  111. package/lib/{x4events.d.ts → cjs/types/x4events.d.ts} +0 -0
  112. package/lib/{x4react.d.ts → cjs/types/x4react.d.ts} +0 -0
  113. package/lib/{version.js → cjs/version.js} +0 -0
  114. package/lib/{x4dom.js → cjs/x4dom.js} +0 -0
  115. package/lib/{x4events.js → cjs/x4events.js} +6 -11
  116. package/lib/{x4react.js → cjs/x4react.js} +1 -4
  117. package/lib/esm/action.js +53 -0
  118. package/lib/esm/application.js +184 -0
  119. package/lib/esm/autocomplete.js +155 -0
  120. package/lib/{base_component.js → esm/base_component.js} +3 -7
  121. package/lib/esm/button.js +257 -0
  122. package/lib/esm/calendar.js +244 -0
  123. package/lib/esm/canvas.js +358 -0
  124. package/lib/esm/cardview.js +159 -0
  125. package/lib/esm/checkbox.js +133 -0
  126. package/lib/{color.js → esm/color.js} +3 -7
  127. package/lib/esm/colorpicker.js +1475 -0
  128. package/lib/esm/combobox.js +259 -0
  129. package/lib/esm/component.js +1711 -0
  130. package/lib/esm/datastore.js +990 -0
  131. package/lib/esm/dialog.js +490 -0
  132. package/lib/{base64.d.ts → esm/dom_events.js} +2 -8
  133. package/lib/esm/drag_manager.js +147 -0
  134. package/lib/esm/drawtext.js +271 -0
  135. package/lib/esm/fileupload.js +163 -0
  136. package/lib/esm/form.js +297 -0
  137. package/lib/esm/formatters.js +81 -0
  138. package/lib/esm/gridview.js +889 -0
  139. package/lib/esm/i18n.js +257 -0
  140. package/lib/esm/icon.js +256 -0
  141. package/lib/esm/image.js +154 -0
  142. package/lib/esm/index.mjs +86 -0
  143. package/lib/{input.js → esm/input.js} +2 -6
  144. package/lib/esm/label.js +90 -0
  145. package/lib/esm/layout.js +310 -0
  146. package/lib/esm/link.js +59 -0
  147. package/lib/{listview.js → esm/listview.js} +30 -36
  148. package/lib/{md5.js → esm/md5.js} +1 -5
  149. package/lib/esm/menu.js +300 -0
  150. package/lib/esm/messagebox.js +145 -0
  151. package/lib/esm/panel.js +65 -0
  152. package/lib/esm/popup.js +379 -0
  153. package/lib/esm/property_editor.js +251 -0
  154. package/lib/esm/radiobtn.js +136 -0
  155. package/lib/esm/rating.js +97 -0
  156. package/lib/{request.js → esm/request.js} +9 -16
  157. package/lib/esm/router.js +136 -0
  158. package/lib/{settings.js → esm/settings.js} +1 -5
  159. package/lib/esm/sidebarview.js +79 -0
  160. package/lib/esm/spreadsheet.js +1091 -0
  161. package/lib/esm/styles.js +270 -0
  162. package/lib/esm/svgcomponent.js +422 -0
  163. package/lib/esm/tabbar.js +107 -0
  164. package/lib/esm/tabview.js +83 -0
  165. package/lib/esm/textarea.js +123 -0
  166. package/lib/esm/textedit.js +412 -0
  167. package/lib/esm/toaster.js +62 -0
  168. package/lib/esm/tools.js +1155 -0
  169. package/lib/esm/tooltips.js +153 -0
  170. package/lib/esm/treeview.js +495 -0
  171. package/lib/esm/types/action.d.ts +57 -0
  172. package/lib/esm/types/application.d.ts +104 -0
  173. package/lib/esm/types/autocomplete.d.ts +58 -0
  174. package/lib/esm/types/base_component.d.ts +88 -0
  175. package/lib/esm/types/button.d.ts +151 -0
  176. package/lib/esm/types/calendar.d.ts +81 -0
  177. package/lib/esm/types/canvas.d.ts +92 -0
  178. package/lib/esm/types/cardview.d.ts +87 -0
  179. package/lib/esm/types/checkbox.d.ts +77 -0
  180. package/lib/esm/types/color.d.ts +148 -0
  181. package/lib/esm/types/colorpicker.d.ts +107 -0
  182. package/lib/esm/types/combobox.d.ts +101 -0
  183. package/lib/esm/types/component.d.ts +601 -0
  184. package/lib/esm/types/datastore.d.ts +396 -0
  185. package/lib/esm/types/dialog.d.ts +175 -0
  186. package/lib/esm/types/dom_events.d.ts +302 -0
  187. package/lib/esm/types/drag_manager.d.ts +54 -0
  188. package/lib/esm/types/drawtext.d.ts +48 -0
  189. package/lib/esm/types/fileupload.d.ts +64 -0
  190. package/lib/esm/types/form.d.ts +126 -0
  191. package/lib/esm/types/formatters.d.ts +35 -0
  192. package/lib/esm/types/gridview.d.ts +175 -0
  193. package/lib/esm/types/i18n.d.ts +73 -0
  194. package/lib/esm/types/icon.d.ts +64 -0
  195. package/lib/esm/types/image.d.ts +55 -0
  196. package/lib/esm/types/index.d.ts +83 -0
  197. package/lib/esm/types/input.d.ts +91 -0
  198. package/lib/esm/types/label.d.ts +58 -0
  199. package/lib/esm/types/layout.d.ts +87 -0
  200. package/lib/esm/types/link.d.ts +50 -0
  201. package/lib/esm/types/listview.d.ts +178 -0
  202. package/lib/esm/types/md5.d.ts +61 -0
  203. package/lib/esm/types/menu.d.ts +130 -0
  204. package/lib/esm/types/messagebox.d.ts +68 -0
  205. package/lib/esm/types/panel.d.ts +47 -0
  206. package/lib/esm/types/popup.d.ts +75 -0
  207. package/lib/esm/types/property_editor.d.ts +71 -0
  208. package/lib/esm/types/radiobtn.d.ts +72 -0
  209. package/lib/esm/types/rating.d.ts +53 -0
  210. package/lib/esm/types/request.d.ts +52 -0
  211. package/lib/esm/types/router.d.ts +42 -0
  212. package/lib/esm/types/settings.d.ts +37 -0
  213. package/lib/esm/types/sidebarview.d.ts +49 -0
  214. package/lib/esm/types/spreadsheet.d.ts +218 -0
  215. package/lib/esm/types/styles.d.ts +85 -0
  216. package/lib/esm/types/svgcomponent.d.ts +191 -0
  217. package/lib/esm/types/tabbar.d.ts +58 -0
  218. package/lib/esm/types/tabview.d.ts +49 -0
  219. package/lib/{texthiliter.d.ts → esm/types/textarea.d.ts} +26 -23
  220. package/lib/esm/types/textedit.d.ts +123 -0
  221. package/lib/esm/types/toaster.d.ts +42 -0
  222. package/lib/esm/types/tools.d.ts +394 -0
  223. package/lib/esm/types/tooltips.d.ts +46 -0
  224. package/lib/esm/types/treeview.d.ts +132 -0
  225. package/lib/esm/types/version.d.ts +29 -0
  226. package/lib/esm/types/x4dom.d.ts +49 -0
  227. package/lib/{x4_events.d.ts → esm/types/x4events.d.ts} +6 -3
  228. package/lib/esm/types/x4react.d.ts +41 -0
  229. package/lib/esm/version.js +29 -0
  230. package/lib/esm/x4dom.js +29 -0
  231. package/lib/{x4_events.js → esm/x4events.js} +11 -24
  232. package/lib/esm/x4react.js +71 -0
  233. package/lib/{x4.css → styles/x4.css} +0 -0
  234. package/{src → lib/styles}/x4.less +0 -0
  235. package/package.json +35 -14
  236. package/build.sh +0 -5
  237. package/lib/base64.js +0 -143
  238. package/lib/hosts/host.d.ts +0 -44
  239. package/lib/hosts/host.js +0 -73
  240. package/lib/smartedit.d.ts +0 -107
  241. package/lib/smartedit.js +0 -390
  242. package/lib/texthiliter.js +0 -227
  243. package/src/MIT-license.md +0 -14
  244. package/src/action.ts +0 -88
  245. package/src/alpha.jpg +0 -0
  246. package/src/application.ts +0 -251
  247. package/src/autocomplete.ts +0 -197
  248. package/src/base64.ts +0 -166
  249. package/src/base_component.ts +0 -152
  250. package/src/button.ts +0 -355
  251. package/src/calendar.ts +0 -322
  252. package/src/canvas.ts +0 -505
  253. package/src/cardview.ts +0 -227
  254. package/src/checkbox.ts +0 -187
  255. package/src/color.ts +0 -752
  256. package/src/colorpicker.ts +0 -1639
  257. package/src/combobox.ts +0 -362
  258. package/src/component.ts +0 -2329
  259. package/src/datastore.ts +0 -1322
  260. package/src/dialog.ts +0 -656
  261. package/src/dom_events.ts +0 -315
  262. package/src/drag_manager.ts +0 -199
  263. package/src/drawtext.ts +0 -355
  264. package/src/fileupload.ts +0 -213
  265. package/src/form.ts +0 -366
  266. package/src/formatters.ts +0 -105
  267. package/src/gridview.ts +0 -1185
  268. package/src/i18n.ts +0 -346
  269. package/src/icon.ts +0 -329
  270. package/src/image.ts +0 -204
  271. package/src/index.ts +0 -88
  272. package/src/input.ts +0 -249
  273. package/src/label.ts +0 -128
  274. package/src/layout.ts +0 -430
  275. package/src/link.ts +0 -86
  276. package/src/listview.ts +0 -762
  277. package/src/menu.ts +0 -425
  278. package/src/messagebox.ts +0 -203
  279. package/src/panel.ts +0 -86
  280. package/src/popup.ts +0 -494
  281. package/src/property_editor.ts +0 -337
  282. package/src/radiobtn.ts +0 -196
  283. package/src/rating.ts +0 -135
  284. package/src/request.ts +0 -300
  285. package/src/router.ts +0 -185
  286. package/src/settings.ts +0 -77
  287. package/src/sidebarview.ts +0 -103
  288. package/src/spreadsheet.ts +0 -1442
  289. package/src/styles.ts +0 -343
  290. package/src/svgcomponent.ts +0 -537
  291. package/src/tabbar.ts +0 -151
  292. package/src/tabview.ts +0 -110
  293. package/src/textarea.ts +0 -187
  294. package/src/textedit.ts +0 -544
  295. package/src/toaster.ts +0 -80
  296. package/src/tools.ts +0 -1468
  297. package/src/tooltips.ts +0 -191
  298. package/src/treeview.ts +0 -675
  299. package/src/version.ts +0 -30
  300. package/src/x4dom.ts +0 -57
  301. package/src/x4events.ts +0 -585
  302. package/src/x4react.ts +0 -90
  303. package/tsconfig.json +0 -21
package/src/gridview.ts DELETED
@@ -1,1185 +0,0 @@
1
- /**
2
- * ___ ___ __
3
- * \ \/ / / _
4
- * \ / /_| |_
5
- * / \____ _|
6
- * /__/\__\ |_|
7
- *
8
- * @file gridview.ts
9
- * @author Etienne Cochard
10
- *
11
- * Copyright (c) 2019-2022 R-libre ingenierie
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
- * of the Software, and to permit persons to whom the Software is furnished to do so,
18
- * subject to the following conditions:
19
- * The above copyright notice and this permission notice shall be included in all copies
20
- * or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
- **/
29
-
30
- const T_UPDATE = Symbol('update');
31
-
32
- /**
33
- * todo: sizable column
34
- * todo: button in a column
35
- */
36
-
37
- import { x4document } from './x4dom'
38
-
39
- import { HLayout, VLayout } from './layout'
40
- import { Component, ContainerEventMap, EvSize, EvDblClick, CProps, flyWrap, html, HtmlString, SizerOverlay, Flex } from './component'
41
- import { Label } from './label'
42
- import { _tr } from './i18n'
43
- import * as Formatters from './formatters'
44
- import { downloadData, isFunction } from './tools'
45
- import { DataView, DataStore, Record } from './datastore'
46
-
47
- import { EvContextMenu, EvSelectionChange, BasicEvent, EventDisposer } from "./x4events";
48
- import { Icon } from './icon.js';
49
-
50
- export interface EvGridCheck extends BasicEvent {
51
- rec: Record;
52
- chk: boolean;
53
- }
54
-
55
- export function EvGridCheck(rec: Record, chk: boolean) {
56
- return BasicEvent<EvGridCheck>( { rec, chk } );
57
- }
58
-
59
-
60
-
61
-
62
-
63
- /**
64
- *
65
- */
66
-
67
- export interface GridColumn {
68
- id: any;
69
- title: string;
70
- width: number;
71
- flex?: number;
72
- align?: 'left' | 'center' | 'right';
73
- renderer?: CellRenderer;
74
- formatter?: Formatters.FormatFunc;
75
- cls?: string;
76
- sortable?: boolean;
77
- }
78
-
79
- interface GridColumnInternal extends GridColumn {
80
- $hdr: ColHeader;
81
- $ftr: Component;
82
- }
83
-
84
-
85
-
86
- export type CellRenderer = (rec: Record) => Component;
87
- export type RowClassifier = (rec: Record, Row: Component) => void;
88
- export type ContextMenuGridItem = (event: MouseEvent, item: Record, grid: GridView) => any;
89
-
90
- type emptyFn = () => string;
91
-
92
- interface GridViewEventMap extends ContainerEventMap {
93
- dblClick?: EvDblClick;
94
- selectionChange?: EvSelectionChange;
95
- contextMenu?: EvContextMenu;
96
- gridCheck?: EvGridCheck;
97
- }
98
-
99
- export interface GridViewProps extends CProps<GridViewEventMap> {
100
- store: DataStore | DataView;
101
- columns: GridColumn[];
102
- calcRowClass?: RowClassifier;
103
- empty_text?: string | emptyFn; // set or return '' to avoid message
104
- hasMarks?: boolean; // if true add a checkbox on left side cf. clearMarks, getMarksIds
105
- hasFooter?: boolean;
106
- }
107
-
108
-
109
- class ColHeader extends Component {
110
-
111
- private m_sens: "up" | "dn";
112
- private m_sorted: boolean;
113
-
114
- constructor( props, title ) {
115
- super( props );
116
-
117
- this.m_sorted = false;
118
- this.m_sens = 'dn';
119
-
120
- this.setContent( [
121
- new Component({
122
- tag: 'span',
123
- content: title
124
- }),
125
- new Icon( {
126
- ref: 'sorter',
127
- cls: '@hidden sort',
128
- icon: 'var( --x4-icon-arrow-down )'
129
- })
130
- ]);
131
- }
132
-
133
- get sorted( ) {
134
- return this.m_sorted;
135
- }
136
-
137
- //set sorted( v ) {
138
- // this.m_sorted = v;
139
- // this.m_sens = 'dn';
140
- // this.itemWithRef<Icon>( 'sorter' ).show( v );
141
- //}
142
-
143
- sort( v: boolean, sens: "up" | "dn" ) {
144
- this.m_sorted = v;
145
- this.m_sens = sens;
146
-
147
- const ic = this.itemWithRef<Icon>('sorter');
148
- ic.icon = this.m_sens == 'up' ? 'var( --x4-icon-arrow-down )' : 'var( --x4-icon-arrow-up )';
149
- ic.show(v);
150
- }
151
-
152
- get sens( ) {
153
- return this.m_sens;
154
- }
155
-
156
- toggleSens( ) {
157
- this.m_sens = this.m_sens=='up' ? 'dn' : 'up';
158
- this.itemWithRef<Icon>( 'sorter' ).icon = this.m_sens=='up' ? 'var( --x4-icon-arrow-down )' : 'var( --x4-icon-arrow-up )';
159
- }
160
- }
161
-
162
-
163
-
164
- /**
165
- * gridview class
166
- */
167
-
168
- export class GridView extends VLayout<GridViewProps, GridViewEventMap> {
169
-
170
- protected m_dataview: DataView;
171
- protected m_data_cx: EventDisposer;
172
-
173
- protected m_columns: GridColumn[];
174
-
175
- protected m_view_el: Component;
176
- protected m_container: Component;
177
- protected m_header: Component;
178
-
179
- protected m_footer: Component;
180
-
181
- protected m_empty_msg: Label;
182
- protected m_empty_text: string | emptyFn;
183
-
184
- protected m_selection: any;
185
- private m_itemHeight: number;
186
- private m_topIndex: number;
187
- protected m_visible_rows: Component[]; // shown elements
188
-
189
- protected m_hasMarks: boolean;
190
- protected m_marks: Set<any>; // checked elements
191
-
192
- private m_recycler: Component[];
193
-
194
- private m_rowClassifier: RowClassifier;
195
-
196
- constructor(props: GridViewProps) {
197
- super(props);
198
-
199
- this.m_columns = props.columns;
200
- this.m_hasMarks = props.hasMarks ?? false;
201
- this.m_marks = new Set<any>();
202
-
203
- // prepend the checkable column
204
- if (this.m_hasMarks) {
205
- this.m_columns.unshift({
206
- id: 'id',
207
- title: '',
208
- width: 30,
209
- renderer: (e) => this._renderCheck( e )
210
- });
211
- }
212
-
213
- this.setAttribute('tabindex', 0);
214
-
215
- this.m_topIndex = 0;
216
- this.m_itemHeight = 0;
217
- this.m_recycler = [];
218
- this.m_rowClassifier = props.calcRowClass;
219
-
220
- this.m_empty_text = props.empty_text ?? _tr.global.empty_list;
221
-
222
- //this.setDomEvent('create', this._handleCreate, this);
223
- this.setDomEvent('click', (e)=>this._itemClick(e));
224
- this.setDomEvent('dblclick', (e)=>this._itemDblClick(e));
225
- this.setDomEvent('contextmenu', (e)=>this._itemMenu(e));
226
- this.setDomEvent('keydown', (e)=>this._handleKey(e));
227
-
228
- this.setStore(props.store);
229
- }
230
-
231
- componentCreated() {
232
- this._updateScroll(true);
233
- }
234
-
235
- /**
236
- *
237
- */
238
-
239
- private _moveSel(sens: number, select = true) {
240
-
241
- let sel = this.m_selection;
242
- let scrolltype = null;
243
-
244
- if (sel === undefined) {
245
- sel = this.m_dataview.getByIndex(0).getID();
246
- }
247
- else {
248
-
249
- let index = this.m_dataview.indexOfId(this.m_selection);
250
-
251
- if (sens == 1) {
252
- index++;
253
- }
254
- else if (sens == -1) {
255
- index--;
256
- }
257
- else if (sens == 2) {
258
- index += this.m_visible_rows.length - 1;
259
- }
260
- else if (sens == -2) {
261
- index -= this.m_visible_rows.length - 1;
262
- }
263
-
264
- if (sens < 0) {
265
- scrolltype = 'start';
266
- }
267
- else {
268
- scrolltype = 'end';
269
- }
270
-
271
- if (index < 0) {
272
- index = 0;
273
- }
274
- else if (index >= this.m_dataview.count) {
275
- index = this.m_dataview.count - 1;
276
- }
277
-
278
- sel = this.m_dataview.getByIndex(index).getID();
279
- }
280
-
281
- if (this.m_selection != sel && select) {
282
- this._selectItem(sel, null, scrolltype);
283
- }
284
-
285
- return sel;
286
- }
287
-
288
- /**
289
- *
290
- */
291
-
292
- private _handleKey(event: KeyboardEvent) {
293
- if (!this.m_dataview || this.m_dataview.count == 0) {
294
- return;
295
- }
296
-
297
- switch (event.key) {
298
- case 'ArrowDown':
299
- case 'Down': {
300
- this._moveSel(1);
301
- break;
302
- }
303
-
304
- case 'ArrowUp':
305
- case 'Up': {
306
- this._moveSel(-1);
307
- break;
308
- }
309
-
310
- case 'PageUp': {
311
- this._moveSel(-2);
312
- break;
313
- }
314
-
315
- case 'PageDown': {
316
- this._moveSel(2);
317
- break;
318
- }
319
- }
320
- }
321
-
322
- /**
323
- *
324
- */
325
-
326
- getNextSel(sens: number) {
327
- return this._moveSel(sens, false);
328
- }
329
-
330
- private _scrollIntoView(id: any, sens?: string) {
331
-
332
- let itm = this._findItem(id);
333
- if (itm) {
334
- itm.scrollIntoView({
335
- block: 'center' //<ScrollLogicalPosition>sens ?? 'nearest'
336
- });
337
- }
338
- else {
339
- this.m_topIndex = this.m_dataview.indexOfId(id);
340
- this.m_view_el.dom.scrollTop = this.m_topIndex * this.m_itemHeight;
341
- this._buildItems();
342
-
343
- this._scrollIntoView(id);
344
- }
345
-
346
- }
347
-
348
- /**
349
- * change the list of item displayed
350
- * @param items - new array of items
351
- */
352
-
353
- public setStore(store: DataStore | DataView) {
354
-
355
- this.m_selection = undefined;
356
-
357
- if (store instanceof DataStore) {
358
- this.m_dataview = store.createView();
359
- }
360
- else {
361
- this.m_dataview = store;
362
- }
363
-
364
- if( this.m_hasMarks ) {
365
- this.clearMarks( );
366
- }
367
-
368
- // unlink previous observer
369
- if (this.m_data_cx) {
370
- this.m_data_cx.dispose( );
371
- }
372
-
373
- if (this.m_dataview) {
374
-
375
- this.m_data_cx = this.m_dataview.on( 'view_change', ( ev ) => {
376
- if (ev.action == 'change') {
377
- this.m_selection = undefined;
378
- }
379
-
380
- this._updateScroll(true);
381
- });
382
-
383
- //this.update( );
384
- this._updateScroll(true);
385
- }
386
- }
387
-
388
- public getView(): DataView {
389
- return this.m_dataview;
390
- }
391
-
392
- /**
393
- * return the current selection (row id) or null
394
- */
395
-
396
- public getSelection(): any {
397
- return this.m_selection;
398
- }
399
-
400
- public getSelRec(): Record {
401
- if (this.m_selection) {
402
- return this.m_dataview.getById(this.m_selection);
403
- }
404
-
405
- return null;
406
- }
407
-
408
- public setSelection(recId: any) {
409
- this._selectItem(recId, null, 'center');
410
- }
411
-
412
- /** @ignore */
413
- render() {
414
-
415
- this.m_recycler = [];
416
- this.m_container = new Component({
417
- cls: 'content',
418
- });
419
-
420
- this.m_empty_msg = new Label({
421
- cls: 'empty-msg',
422
- text: ''
423
- });
424
-
425
- this.m_view_el = new Component({
426
- cls: '@scroll-view',
427
- flex: 1,
428
- dom_events: {
429
- sizechange: ( ) => this._updateScroll(true),
430
- scroll: ( ) => this._updateScroll(false)
431
- },
432
- content: this.m_container
433
- });
434
-
435
- let flex = false;
436
- let cols = this.m_columns.map((col, index) => {
437
-
438
- let cls = '@cell';
439
- if (col.cls) {
440
- cls += ' ' + col.cls;
441
- }
442
-
443
- let comp = new ColHeader({
444
- cls,
445
- flex: col.flex,
446
- sizable: 'right',
447
- style: {
448
- width: col.width
449
- },
450
- dom_events: {
451
- click: (ev: MouseEvent) => {
452
- let t = flyWrap(<HTMLElement>ev.target);
453
- if (!t.hasClass('@sizer-overlay')) { // avoid sizer click
454
- this._sortCol(col);
455
- ev.preventDefault();
456
- }
457
- }
458
- }
459
- }, col.title );
460
-
461
- const resizeCol = ( ev: EvSize ) => {
462
- this._on_col_resize(index, ev.size.width);
463
-
464
- if( this.m_footer ) {
465
- let col = Component.getElement( this.m_footer.dom.childNodes[index] as HTMLElement );
466
- if( col ) {
467
- col.setStyleValue( 'width', ev.size.width );
468
- }
469
- }
470
- }
471
-
472
- new SizerOverlay({
473
- target: comp,
474
- sens: 'right',
475
- events: {resize: ( e ) => resizeCol(e )}
476
- });
477
-
478
- if( col.flex ) {
479
- flex = true;
480
- }
481
-
482
- (<any>col).$hdr = comp;
483
- return comp;
484
- });
485
-
486
- (cols as any).push( new Flex( {
487
- ref: 'flex',
488
- cls: flex ? '@hidden' : ''
489
- } ) );
490
-
491
- // compute full width
492
- let full_width = 0;
493
- this.m_columns.forEach((col) => {
494
- full_width += col.width ?? 0;
495
- });
496
-
497
- this.m_header = new HLayout({
498
- cls: '@header',
499
- content: <any>cols,
500
- style: {
501
- minWidth: full_width
502
- }
503
- });
504
-
505
- if( this.m_props.hasFooter ) {
506
- let foots = this.m_columns.map((col, index) => {
507
-
508
- let cls = '@cell';
509
-
510
- if (col.align) {
511
- cls += ' ' + col.align;
512
- }
513
-
514
- if (col.cls) {
515
- cls += ' ' + col.cls;
516
- }
517
-
518
- let comp = new Component({
519
- cls,
520
- data: { col: index },
521
- flex: col.flex,
522
- style: {
523
- width: col.width
524
- }
525
- });
526
-
527
- (col as GridColumnInternal).$ftr = comp;
528
- return comp;
529
- });
530
-
531
- (foots as any).push( new Flex( {
532
- ref: 'flex',
533
- cls: flex ? '@hidden' : ''
534
- } ) );
535
-
536
- this.m_footer = new HLayout({
537
- cls: '@footer',
538
- content: <any>foots,
539
- style: {
540
- minWidth: full_width
541
- }
542
- });
543
- }
544
- else {
545
- this.m_footer = null;
546
- }
547
-
548
- this.setContent([
549
- this.m_header,
550
- this.m_view_el,
551
- this.m_footer,
552
- this.m_empty_msg,
553
- ]);
554
-
555
- }
556
-
557
- private _on_col_resize(col: number, width: number) {
558
-
559
- const _col = this.m_columns[col] as GridColumnInternal;
560
-
561
- let updateFlex = false;
562
-
563
- if( width>=0 ) {
564
- _col.width = width;
565
- if( _col.flex ) {
566
- _col.$hdr.removeClass( '@flex' );
567
- _col.$ftr?.removeClass( '@flex' );
568
- _col.flex = undefined;
569
- updateFlex = true;
570
- }
571
- }
572
- else if( width<0 && !_col.flex ) {
573
- _col.$hdr.addClass( '@flex' );
574
- _col.$ftr?.addClass( '@flex' );
575
- _col.flex = 1;
576
- updateFlex = true;
577
- }
578
-
579
- if( updateFlex ) {
580
- let flex = false;
581
- this.m_columns.forEach( c => {
582
- if( c.flex ) {
583
- flex = true;
584
- }
585
- });
586
-
587
- this.m_header.itemWithRef( 'flex' )?.show( flex ? false : true );
588
- if( this.m_footer ) {
589
- this.m_footer.itemWithRef( 'flex' )?.show( flex ? false : true );
590
- }
591
- }
592
-
593
- this._updateScroll(true);
594
- }
595
-
596
- /**
597
- *
598
- */
599
-
600
- sortCol( name: string, asc = true ) {
601
- const col = this.m_columns.find(c => c.id==name );
602
- if( col===undefined ) {
603
- console.assert( false, "unknown field "+name+" in grid.sortCol" );
604
- return;
605
- }
606
-
607
- this._sortCol( col, asc ? "dn" : "up" );
608
- }
609
-
610
- /**
611
- *
612
- */
613
-
614
- private _sortCol(col: GridColumn, sens: "up" | "dn" = "up" ) {
615
-
616
- if (col.sortable === false) {
617
- return;
618
- }
619
-
620
- this.m_columns.forEach((c) => {
621
- if (c !== col) {
622
- (c as GridColumnInternal).$hdr.sort( false, "dn" );
623
- }
624
- });
625
-
626
- const $hdr = (col as GridColumnInternal).$hdr;
627
-
628
- if ($hdr.sorted) {
629
- $hdr.toggleSens( );
630
- }
631
- else {
632
- $hdr.sort( true, sens );
633
- }
634
-
635
- if (this.m_dataview) {
636
- this.m_dataview.sort([
637
- { field: col.id, ascending: $hdr.sens=='dn' ? false : true }
638
- ]);
639
- }
640
- }
641
-
642
- /**
643
- *
644
- */
645
-
646
- private _computeItemHeight() {
647
- let gr = x4document.createElement('div');
648
- gr.classList.add('x-row');
649
-
650
- let gv = x4document.createElement('div');
651
- gv.classList.add('x-grid-view');
652
- gv.style.position = 'absolute';
653
- gv.style.top = '-1000px';
654
- gv.appendChild(gr);
655
-
656
- this.dom.appendChild(gv);
657
- let rc = gr.getBoundingClientRect();
658
- this.dom.removeChild(gv);
659
-
660
- this.m_itemHeight = rc.height;
661
- }
662
-
663
- private _createRow( props: CProps ): Component {
664
-
665
- let row: Component;
666
- if (this.m_recycler.length) {
667
- row = this.m_recycler.pop();
668
- row.clearClasses();
669
- row.addClass( props.cls );
670
- row.setContent( props.content );
671
- row.setStyle( props.style );
672
-
673
- for( let n in props.data ) {
674
- row.setData( n, props.data[n] );
675
- }
676
- }
677
- else {
678
- row = new HLayout( props );
679
- }
680
-
681
- if (!row.dom) {
682
- this.m_container.appendChild(row);
683
- }
684
-
685
- return row;
686
- }
687
-
688
- private _buildItems( canOpt = true ) {
689
- let rc = this.getBoundingRect();
690
- let rh = this.m_header.getBoundingRect();
691
- let height = rc.height - rh.height + this.m_itemHeight;
692
-
693
- if (this.m_itemHeight == 0) {
694
- this._computeItemHeight();
695
- }
696
-
697
- let top = this.m_topIndex * this.m_itemHeight;
698
- let y = 0;
699
- let cidx = 0;
700
- let index = this.m_topIndex;
701
- let count = this.m_dataview ? this.m_dataview.count : 0;
702
-
703
- let full_width = 0; // todo: +4 pixel of left border
704
- let even = this.m_topIndex & 1 ? true : false;
705
-
706
- // compute full width
707
- this.m_columns.forEach((col) => {
708
- full_width += col.width ?? 0;
709
- });
710
-
711
- // if items height make scroll visible, update header width
712
- if (((count + 1) * this.m_itemHeight) >= height) {
713
- let w = Component.getScrollbarSize();
714
- this.m_header.setStyleValue("paddingRight", w);
715
- this.m_footer?.setStyleValue("paddingRight", w);
716
- }
717
- else {
718
- this.m_header.setStyleValue("paddingRight", 0);
719
- this.m_footer?.setStyleValue("paddingRight", 0);
720
- }
721
-
722
- // passe 0 - all created cells are moved to the recycler
723
- if( this.m_visible_rows ) {
724
- this.m_visible_rows.forEach((c) => {
725
- this.m_recycler.push(c);
726
- });
727
- }
728
-
729
- this.m_visible_rows = [];
730
- let limit = 100;
731
- while (y < height && index < count && --limit > 0) {
732
-
733
- let rec = this.m_dataview.getByIndex(index);
734
- let rowid = rec.getID();
735
-
736
- let crow = canOpt ? this.m_recycler.findIndex( ( r ) => r.getData('row-id')==rowid ) : -1;
737
- if( crow>=0 ) {
738
- let rrow = this.m_recycler.splice( crow, 1 )[ 0 ];
739
- rrow.setStyle( {
740
- top: y + top,
741
- minWidth: full_width,
742
- } );
743
-
744
- if (this.m_hasMarks) {
745
- rrow.setClass( '@marked', this.m_marks.has(rowid) );
746
- }
747
-
748
- rrow.removeClass( '@hidden' );
749
- rrow.setClass( '@selected', this.m_selection === rowid );
750
-
751
- this.m_visible_rows[cidx] = rrow;
752
- }
753
- else {
754
- let cols = this.m_columns.map( col => {
755
-
756
- let cls = '@cell';
757
- if (col.align) {
758
- cls += ' ' + col.align;
759
- }
760
-
761
- if (col.cls) {
762
- cls += ' ' + col.cls;
763
- }
764
-
765
- let cell: Component;
766
- if (col.renderer) {
767
- cell = col.renderer(rec);
768
- if (cell) {
769
- cell.addClass(cls);
770
- cell.setStyleValue('width', col.width);
771
- if (col.flex !== undefined) {
772
- cell.addClass('@flex');
773
- cell.setStyleValue('flex', col.flex);
774
- }
775
- }
776
- }
777
- else {
778
-
779
- let fmt = col.formatter;
780
- let text;
781
-
782
- if (fmt && fmt instanceof Function) {
783
- text = fmt(rec.getRaw(col.id), rec);
784
- }
785
- else {
786
- text = rec.getField(col.id);
787
- }
788
-
789
- cell = new Component({
790
- cls,
791
- width: col.width,
792
- content: html`<span>${text}</span>`,
793
- flex: col.flex
794
- })
795
- }
796
-
797
- return cell;
798
- });
799
-
800
- let cls = '@row @hlayout center';
801
- if (this.m_hasMarks) {
802
- if (this.m_marks.has(rowid)) {
803
- cls += ' @marked';
804
- }
805
- }
806
-
807
- if (this.m_selection === rowid) {
808
- cls += ' @selected';
809
- }
810
-
811
- let row = this.m_visible_rows[cidx] = this._createRow( {
812
- cls,
813
- content: <any>cols,
814
- style: {
815
- top: y + top,
816
- minWidth: full_width,
817
- },
818
- data: {
819
- 'row-id': rowid,
820
- 'row-idx': index
821
- }
822
- });
823
-
824
- row.addClass(even ? 'even' : 'odd');
825
- even = !even;
826
-
827
- if (this.m_rowClassifier) {
828
- this.m_rowClassifier(rec, row);
829
- }
830
- }
831
-
832
- y += this.m_itemHeight;
833
-
834
- index++;
835
- cidx++;
836
- }
837
-
838
- // if some cells are still in cache, hide them
839
- this.m_recycler.forEach((c) => {
840
- c.addClass('@hidden');
841
- })
842
-
843
- //this.m_container.setContent(<ComponentContent>this.m_visible_rows);
844
-
845
- let show = !count;
846
- let msg = (this.m_empty_text instanceof Function) ? this.m_empty_text() : this.m_empty_text;
847
- this.m_empty_msg.text = msg;
848
-
849
- if (show && msg.length == 0) {
850
- show = false;
851
- }
852
-
853
- this.m_empty_msg.show(show);
854
-
855
- if (full_width < rc.width) {
856
- this.m_header.setStyleValue('width', null);
857
- this.m_footer?.setStyleValue('width', null);
858
- this.m_container.setStyle({
859
- height: count * this.m_itemHeight,
860
- width: null
861
- });
862
- }
863
- else {
864
- this.m_header.setStyleValue('width', full_width + 1000 );
865
- this.m_footer?.setStyleValue('width', full_width + 1000 );
866
- this.m_container.setStyle({
867
- height: count * this.m_itemHeight,
868
- width: full_width
869
- });
870
- }
871
- }
872
-
873
- /**
874
- *
875
- */
876
-
877
- private _updateScroll(forceUpdate) {
878
- if (!this.m_view_el || !this.m_view_el.dom) {
879
- return;
880
- }
881
-
882
- const update = () => {
883
-
884
- // element destroyed between updateScroll and now
885
- if( !this.dom ) {
886
- return;
887
- }
888
-
889
- let newTop = Math.floor(this.m_view_el.dom.scrollTop / (this.m_itemHeight || 1));
890
-
891
- if (newTop != this.m_topIndex || forceUpdate) {
892
- this.m_topIndex = newTop;
893
- this._buildItems( !forceUpdate );
894
- }
895
-
896
- let newLeft = this.m_view_el.dom.scrollLeft;
897
- this.m_header.setStyleValue('left', -newLeft);
898
- this.m_footer?.setStyleValue('left', -newLeft);
899
- }
900
-
901
- if (forceUpdate) {
902
- this.singleShot( update, 10 );
903
- }
904
- else {
905
- update();
906
- }
907
- }
908
-
909
- /** @ignore */
910
-
911
- private _rowFromTarget(dom) {
912
- let self = this.dom;
913
-
914
- while (dom && dom != self) {
915
- let itm = Component.getElement(dom);
916
-
917
- if (itm) {
918
- let id = itm.getData('row-id');
919
- if (id !== undefined) {
920
- return { id, itm };
921
- }
922
- }
923
-
924
- dom = dom.parentElement;
925
- }
926
-
927
- return undefined;
928
- }
929
-
930
- private _itemClick(e: MouseEvent) {
931
- let hit = this._rowFromTarget(e.target);
932
- if (hit) {
933
- this._selectItem(hit.id, hit.itm);
934
- }
935
- else {
936
- this._selectItem(undefined, undefined);
937
- }
938
- }
939
-
940
- private _itemDblClick(e: MouseEvent) {
941
- let hit = this._rowFromTarget(e.target);
942
- if (hit) {
943
- this._selectItem(hit.id, hit.itm);
944
-
945
- let rec = this.m_dataview.getById(hit.id);
946
- this.emit( 'dblClick', EvDblClick(rec) );
947
-
948
- if (this.m_hasMarks) {
949
- this._toggleMark(rec);
950
- }
951
- }
952
-
953
- }
954
-
955
- /** @ignore */
956
- private _itemMenu(e: MouseEvent) {
957
-
958
- let dom = e.target as HTMLElement,
959
- self = this.dom;
960
-
961
- while (dom && dom != self) {
962
- let itm = Component.getElement(dom),
963
- id = itm?.getData('row-id');
964
-
965
- if (id !== undefined) {
966
- this._selectItem(id, itm);
967
-
968
- let idx = itm.getData('row-idx');
969
- let rec = this.m_dataview.getByIndex(idx);
970
-
971
- this._showItemContextMenu(e, rec);
972
- e.preventDefault();
973
- return;
974
- }
975
-
976
- dom = dom.parentElement;
977
- }
978
- }
979
-
980
- /**
981
- *
982
- */
983
-
984
- private _findItem(id): Component {
985
-
986
- for (let i = 0; i < this.m_visible_rows.length; i++) {
987
- let itm = this.m_visible_rows[i];
988
- if (itm.getData('row-id') === id) {
989
- return itm;
990
- }
991
- }
992
-
993
- return null;
994
- }
995
-
996
- /**
997
- * @ignore
998
- * called when an item is selected by mouse
999
- */
1000
-
1001
- protected _selectItem(item: any, dom_item: Component, scrollIntoView?: string) {
1002
-
1003
- if (this.m_selection !== undefined) {
1004
- let old = this._findItem(this.m_selection);
1005
- if (old) {
1006
- old.removeClass('@selected');
1007
- }
1008
- }
1009
-
1010
- this.m_selection = item;
1011
-
1012
- if (item) {
1013
- if (scrollIntoView) {
1014
- this._scrollIntoView(item, scrollIntoView);
1015
- }
1016
-
1017
- if (!dom_item) {
1018
- dom_item = this._findItem(item);
1019
- }
1020
-
1021
- if (dom_item) {
1022
- dom_item.addClass('@selected');
1023
- }
1024
-
1025
- let rec = this.m_dataview.getById(item);
1026
- this.emit( 'selectionChange', EvSelectionChange(rec));
1027
- }
1028
- else {
1029
- this.emit( 'selectionChange', EvSelectionChange(null));
1030
- }
1031
- }
1032
-
1033
- /**
1034
- *
1035
- */
1036
-
1037
- protected _showItemContextMenu(event: MouseEvent, item: Record) {
1038
- this.emit( 'contextMenu', EvContextMenu(event,item));
1039
- }
1040
-
1041
- /**
1042
- *
1043
- */
1044
-
1045
- public clearSelection() {
1046
- this._selectItem(null, null);
1047
- }
1048
-
1049
- /**
1050
- * todo: moveto datastore
1051
- */
1052
-
1053
- public exportData(filename) {
1054
-
1055
- let data = '';
1056
- const fsep = '\t';
1057
- const lsep = '\r\n';
1058
-
1059
- let rec = '';
1060
- this.m_columns.map((col) => {
1061
-
1062
- if (rec.length) {
1063
- rec += fsep;
1064
- }
1065
-
1066
- rec += col.title;
1067
- });
1068
-
1069
- data += rec + lsep;
1070
-
1071
- let count = this.m_dataview.count;
1072
-
1073
- for (let i = 0; i < count; i++) {
1074
-
1075
- let record = this.m_dataview.getByIndex(i);
1076
-
1077
- rec = '';
1078
- let cols = this.m_columns.map((col) => {
1079
-
1080
- let text = record.getField(col.id);
1081
- let fmt = col.formatter;
1082
-
1083
- if (fmt && fmt instanceof Function) {
1084
- text = fmt(text, record);
1085
- }
1086
-
1087
- if (rec.length > 0) {
1088
- rec += fsep;
1089
- }
1090
-
1091
- rec += text;
1092
- });
1093
-
1094
- data += rec + lsep;
1095
- }
1096
-
1097
- //todo: review that
1098
- data = data.replace(/[àâä]/gm, 'a');
1099
- data = data.replace(/[éèê]/gm, 'e');
1100
- data = data.replace(/[îï]/gm, 'i');
1101
- data = data.replace(/[ûüù]/gm, 'u');
1102
- data = data.replace(/ /gm, ' '); // non breaking space
1103
-
1104
- downloadData(data, 'text/csv', filename);
1105
- }
1106
-
1107
- set empty_text(text: string | HtmlString) {
1108
- this.m_empty_msg.text = text;
1109
- }
1110
-
1111
- private _renderCheck(rec: Record) {
1112
- let icon = '--x4-icon-square';
1113
- if (this.m_marks.has(rec.getID())) {
1114
- icon = '--x4-icon-square-check';
1115
- }
1116
-
1117
- return new Icon({ icon: `var(${icon})` });
1118
- }
1119
-
1120
- private _toggleMark(rec: Record) {
1121
-
1122
- let id = rec.getID();
1123
- let chk = false;
1124
-
1125
- if (this.m_marks.has(id)) {
1126
- this.m_marks.delete(id);
1127
- }
1128
- else {
1129
- this.m_marks.add(id);
1130
- chk = true;
1131
- }
1132
-
1133
- this.emit( 'gridCheck', EvGridCheck(rec, chk));
1134
- this._buildItems( false );
1135
- }
1136
-
1137
- public getMarks(): any[] {
1138
- let ids = [];
1139
- for (const v of this.m_marks.values()) {
1140
- ids.push(v);
1141
- }
1142
-
1143
- return ids;
1144
- }
1145
-
1146
- public clearMarks() {
1147
- if (this.m_marks.size) {
1148
- this.m_marks = new Set<any>();
1149
- this._buildItems( false );
1150
- }
1151
- }
1152
-
1153
- public setFooterData( rec: any ) {
1154
- if( !this.m_footer ) {
1155
- return;
1156
- }
1157
-
1158
- this.m_footer.enumChilds( (c) => {
1159
- let cid = c.getData( 'col' );
1160
- if( cid ) {
1161
- let col = this.m_columns[cid];
1162
-
1163
- let value = rec[col.id];
1164
- if( value!==undefined ) {
1165
- if( isFunction(value) ) { // FooterRenderer
1166
- value( c );
1167
- }
1168
- else {
1169
- let text;
1170
- const fmt = col.formatter;
1171
- if (fmt && fmt instanceof Function) {
1172
- text = fmt(value, rec);
1173
- }
1174
- else {
1175
- text = value;
1176
- }
1177
-
1178
- c.setContent( text, false );
1179
- }
1180
- }
1181
- }
1182
- });
1183
- }
1184
- }
1185
-