jsl-ui 9.18.3 → 9.18.4

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 (213) hide show
  1. package/lib/components/IntervalComponent.d.ts +17 -0
  2. package/lib/components/IntervalComponent.js +68 -0
  3. package/lib/components/auto-suggest/AutoSuggestComponent.d.ts +22 -0
  4. package/lib/components/auto-suggest/AutoSuggestComponent.js +49 -0
  5. package/lib/components/button/ButtonComponent.d.ts +18 -0
  6. package/lib/components/button/ButtonComponent.js +46 -0
  7. package/lib/components/checkbox/CheckBoxComponent.d.ts +28 -0
  8. package/lib/components/checkbox/CheckBoxComponent.js +94 -0
  9. package/lib/components/checkbox/CheckBoxStyle.scss +86 -0
  10. package/lib/components/date/DateComponent.d.ts +32 -0
  11. package/lib/components/date/DateComponent.js +106 -0
  12. package/lib/components/date-range/DateRangeComponent.d.ts +35 -0
  13. package/lib/components/date-range/DateRangeComponent.js +136 -0
  14. package/lib/components/date-range/DateRangeStyle.scss +12 -0
  15. package/lib/components/date-time/DateTimeComponent.d.ts +15 -0
  16. package/lib/components/date-time/DateTimeComponent.js +53 -0
  17. package/lib/components/date-time/DateTimeStyle.scss +7 -0
  18. package/lib/components/dialog/DialogComponent.d.ts +67 -0
  19. package/lib/components/dialog/DialogComponent.js +242 -0
  20. package/lib/components/drop-down/DropDownComponent.d.ts +27 -0
  21. package/lib/components/drop-down/DropDownComponent.js +74 -0
  22. package/lib/components/expander/ExpanderComponent.d.ts +27 -0
  23. package/lib/components/expander/ExpanderComponent.js +90 -0
  24. package/lib/components/expander/ExpanderStyle.scss +47 -0
  25. package/lib/components/expander/OldExpanderStyle.scss +37 -0
  26. package/lib/components/form-field/FormComponent.d.ts +12 -0
  27. package/lib/components/form-field/FormComponent.js +26 -0
  28. package/lib/components/form-field/FormFieldComponent.d.ts +38 -0
  29. package/lib/components/form-field/FormFieldComponent.js +139 -0
  30. package/lib/components/form-field/FormFieldStyle.scss +87 -0
  31. package/lib/components/grid/GridComponent.d.ts +26 -0
  32. package/lib/components/grid/GridComponent.js +116 -0
  33. package/lib/components/input/InputComponent.d.ts +33 -0
  34. package/lib/components/input/InputComponent.js +144 -0
  35. package/lib/components/loading/LoadingComponent.d.ts +8 -0
  36. package/lib/components/loading/LoadingComponent.js +22 -0
  37. package/lib/components/loading/LoadingStyle.css +29 -0
  38. package/lib/components/navigation/NavigationComponent.d.ts +34 -0
  39. package/lib/components/navigation/NavigationComponent.js +70 -0
  40. package/lib/components/navigation/NavigationStyle.scss +226 -0
  41. package/lib/components/notification/Notification.d.ts +17 -0
  42. package/lib/components/notification/Notification.js +56 -0
  43. package/lib/components/notification/Notification.scss +19 -0
  44. package/lib/components/number/NumberComponent.d.ts +25 -0
  45. package/lib/components/number/NumberComponent.js +87 -0
  46. package/lib/components/overlay/OverlayComponent.d.ts +27 -0
  47. package/lib/components/overlay/OverlayComponent.js +149 -0
  48. package/lib/components/overlay/overlay.css +57 -0
  49. package/lib/components/progress/ProgressComponent.d.ts +18 -0
  50. package/lib/components/progress/ProgressComponent.js +42 -0
  51. package/lib/components/progress/ProgressStyle.scss +15 -0
  52. package/lib/components/ribbon-menu/RibbonMenuComponent.d.ts +12 -0
  53. package/lib/components/ribbon-menu/RibbonMenuComponent.js +34 -0
  54. package/lib/components/ribbon-menu/RibbonMenuStyle.scss +76 -0
  55. package/lib/components/select/SelectComponent.d.ts +79 -0
  56. package/lib/components/select/SelectComponent.js +362 -0
  57. package/lib/components/select/SelectDDAreaComponent.d.ts +32 -0
  58. package/lib/components/select/SelectDDAreaComponent.js +317 -0
  59. package/lib/components/select/SelectStyle.scss +187 -0
  60. package/lib/components/slider/nouislider.css +310 -0
  61. package/lib/components/slider/nouislider.d.ts +44 -0
  62. package/lib/components/slider/nouislider.js +2158 -0
  63. package/lib/components/stack-panel/SplitterComponent.d.ts +21 -0
  64. package/lib/components/stack-panel/SplitterComponent.js +126 -0
  65. package/lib/components/stack-panel/SplitterStyle.scss +45 -0
  66. package/lib/components/stack-panel/StackPanelComponent.d.ts +20 -0
  67. package/lib/components/stack-panel/StackPanelComponent.js +64 -0
  68. package/lib/components/stack-panel/StackPanelStyle.scss +53 -0
  69. package/lib/components/tabs/TabsComponent.d.ts +39 -0
  70. package/lib/components/tabs/TabsComponent.js +177 -0
  71. package/lib/components/tabs/TabsStyle.scss +76 -0
  72. package/lib/components/time/TimeComponent.d.ts +29 -0
  73. package/lib/components/time/TimeComponent.js +113 -0
  74. package/lib/components/time/TimeComponent.scss +4 -0
  75. package/lib/components/tree-view/TreeViewComponent.d.ts +23 -0
  76. package/lib/components/tree-view/TreeViewComponent.js +45 -0
  77. package/lib/components/tree-view/TreeViewStyle.scss +96 -0
  78. package/lib/components/virtual-render/VirtualRenderComponent.d.ts +30 -0
  79. package/lib/components/virtual-render/VirtualRenderComponent.js +104 -0
  80. package/lib/components/virtual-render/VirtualRenderStyle.scss +9 -0
  81. package/lib/core/culture.d.ts +5 -0
  82. package/lib/core/culture.js +385 -0
  83. package/lib/core/date.d.ts +14 -0
  84. package/lib/core/date.js +350 -0
  85. package/lib/core/helper.d.ts +12 -0
  86. package/lib/core/helper.js +101 -0
  87. package/lib/core/jq.d.ts +37 -0
  88. package/lib/core/jq.js +371 -0
  89. package/lib/core/lang.d.ts +24 -0
  90. package/lib/core/lang.js +28 -0
  91. package/lib/core/numeric.d.ts +7 -0
  92. package/lib/core/numeric.js +143 -0
  93. package/lib/core/polyfills.d.ts +0 -0
  94. package/lib/core/polyfills.js +22 -0
  95. package/lib/core.d.ts +6 -0
  96. package/lib/core.js +6 -0
  97. package/lib/grid/controls/slick.columnpicker.css +46 -0
  98. package/lib/grid/controls/slick.draggablegrouping.css +52 -0
  99. package/lib/grid/controls/slick.gridmenu.css +127 -0
  100. package/lib/grid/controls/slick.pager.css +41 -0
  101. package/lib/grid/examples/examples.css +203 -0
  102. package/lib/grid/filterDialogs/dateRangeFilter.d.ts +7 -0
  103. package/lib/grid/filterDialogs/dateRangeFilter.js +156 -0
  104. package/lib/grid/filterDialogs/excelFilter.d.ts +9 -0
  105. package/lib/grid/filterDialogs/excelFilter.js +313 -0
  106. package/lib/grid/plugins/ext.overlay.css +28 -0
  107. package/lib/grid/plugins/ext.overlay.d.ts +2 -0
  108. package/lib/grid/plugins/ext.overlay.js +291 -0
  109. package/lib/grid/plugins/slick.cellrangedecorator.d.ts +12 -0
  110. package/lib/grid/plugins/slick.cellrangedecorator.js +68 -0
  111. package/lib/grid/plugins/slick.cellrangeselector.d.ts +1 -0
  112. package/lib/grid/plugins/slick.cellrangeselector.js +144 -0
  113. package/lib/grid/plugins/slick.cellselectionmodel.d.ts +1 -0
  114. package/lib/grid/plugins/slick.cellselectionmodel.js +194 -0
  115. package/lib/grid/plugins/slick.headerbuttons.css +40 -0
  116. package/lib/grid/plugins/slick.headerbuttons.d.ts +55 -0
  117. package/lib/grid/plugins/slick.headerbuttons.js +156 -0
  118. package/lib/grid/plugins/slick.headermenu.css +101 -0
  119. package/lib/grid/plugins/slick.headermenu.d.ts +74 -0
  120. package/lib/grid/plugins/slick.headermenu.js +260 -0
  121. package/lib/grid/plugins/slick.rowdetailview.css +37 -0
  122. package/lib/grid/plugins/slick.rowmovemanager.css +8 -0
  123. package/lib/grid/plugins/slick.rowmovemanager.d.ts +18 -0
  124. package/lib/grid/plugins/slick.rowmovemanager.js +249 -0
  125. package/lib/grid/plugins/slick.rowselectionmodel.d.ts +1 -0
  126. package/lib/grid/plugins/slick.rowselectionmodel.js +167 -0
  127. package/lib/grid/slick-default-theme.css +154 -0
  128. package/lib/grid/slick.core.d.ts +90 -0
  129. package/lib/grid/slick.core.js +574 -0
  130. package/lib/grid/slick.creator.d.ts +80 -0
  131. package/lib/grid/slick.creator.js +723 -0
  132. package/lib/grid/slick.dataview.d.ts +71 -0
  133. package/lib/grid/slick.dataview.js +1080 -0
  134. package/lib/grid/slick.editors.core.d.ts +4 -0
  135. package/lib/grid/slick.editors.core.js +232 -0
  136. package/lib/grid/slick.editors.date.d.ts +2 -0
  137. package/lib/grid/slick.editors.date.js +125 -0
  138. package/lib/grid/slick.editors.lookup.d.ts +14 -0
  139. package/lib/grid/slick.editors.lookup.js +353 -0
  140. package/lib/grid/slick.editors.nav.d.ts +6 -0
  141. package/lib/grid/slick.editors.nav.js +22 -0
  142. package/lib/grid/slick.formatters.d.ts +17 -0
  143. package/lib/grid/slick.formatters.js +137 -0
  144. package/lib/grid/slick.grid.css +325 -0
  145. package/lib/grid/slick.grid.d.ts +284 -0
  146. package/lib/grid/slick.grid.js +5395 -0
  147. package/lib/grid/slick.groupitemmetadataprovider.d.ts +39 -0
  148. package/lib/grid/slick.groupitemmetadataprovider.js +165 -0
  149. package/lib/grid/slick.tree.css +20 -0
  150. package/lib/grid/slick.tree.d.ts +33 -0
  151. package/lib/grid/slick.tree.js +220 -0
  152. package/lib/grid.d.ts +13 -0
  153. package/lib/grid.js +13 -0
  154. package/lib/index.css +2576 -0
  155. package/lib/index.css.map +1 -1
  156. package/lib/index.d.ts +56 -0
  157. package/lib/index.js +61 -10198
  158. package/lib/index.js.map +1 -1
  159. package/lib/interaction/dataconverter.d.ts +4 -0
  160. package/lib/interaction/dataconverter.js +1 -0
  161. package/lib/interaction/eventhandler.d.ts +13 -0
  162. package/lib/interaction/eventhandler.js +42 -0
  163. package/lib/interaction/moveable.css +0 -0
  164. package/lib/interaction/moveable.d.ts +39 -0
  165. package/lib/interaction/moveable.js +172 -0
  166. package/lib/interaction/resizable.css +33 -0
  167. package/lib/interaction/resizable.d.ts +37 -0
  168. package/lib/interaction/resizable.js +123 -0
  169. package/lib/ui/auto.suggest.css +14 -0
  170. package/lib/ui/auto.suggest.d.ts +17 -0
  171. package/lib/ui/auto.suggest.js +255 -0
  172. package/lib/ui/base.css +150 -0
  173. package/lib/ui/date.picker/css/date-range-picker.css +87 -0
  174. package/lib/ui/date.picker/css/tiny-date-picker.css +326 -0
  175. package/lib/ui/date.picker/date-picker-options.d.ts +11 -0
  176. package/lib/ui/date.picker/date-picker-options.js +76 -0
  177. package/lib/ui/date.picker/lib/date-manip.d.ts +74 -0
  178. package/lib/ui/date.picker/lib/date-manip.js +120 -0
  179. package/lib/ui/date.picker/lib/dom.d.ts +23 -0
  180. package/lib/ui/date.picker/lib/dom.js +28 -0
  181. package/lib/ui/date.picker/lib/emitter.d.ts +13 -0
  182. package/lib/ui/date.picker/lib/emitter.js +49 -0
  183. package/lib/ui/date.picker/lib/fns.d.ts +23 -0
  184. package/lib/ui/date.picker/lib/fns.js +43 -0
  185. package/lib/ui/date.picker/mode/base-mode.d.ts +26 -0
  186. package/lib/ui/date.picker/mode/base-mode.js +248 -0
  187. package/lib/ui/date.picker/mode/dropdown-mode.d.ts +28 -0
  188. package/lib/ui/date.picker/mode/dropdown-mode.js +50 -0
  189. package/lib/ui/date.picker/mode/index.d.ts +28 -0
  190. package/lib/ui/date.picker/mode/index.js +18 -0
  191. package/lib/ui/date.picker/mode/modal-mode.d.ts +25 -0
  192. package/lib/ui/date.picker/mode/modal-mode.js +17 -0
  193. package/lib/ui/date.picker/mode/permanent-mode.d.ts +29 -0
  194. package/lib/ui/date.picker/mode/permanent-mode.js +19 -0
  195. package/lib/ui/date.picker/views/day-picker.d.ts +40 -0
  196. package/lib/ui/date.picker/views/day-picker.js +155 -0
  197. package/lib/ui/date.picker/views/month-picker.d.ts +26 -0
  198. package/lib/ui/date.picker/views/month-picker.js +65 -0
  199. package/lib/ui/date.picker/views/year-picker.d.ts +20 -0
  200. package/lib/ui/date.picker/views/year-picker.js +66 -0
  201. package/lib/ui/date.picker.d.ts +66 -0
  202. package/lib/ui/date.picker.js +32 -0
  203. package/lib/ui/dialog.css +109 -0
  204. package/lib/ui/dialog.d.ts +22 -0
  205. package/lib/ui/dialog.js +113 -0
  206. package/lib/ui/drop.down.css +472 -0
  207. package/lib/ui/drop.down.d.ts +52 -0
  208. package/lib/ui/drop.down.js +2112 -0
  209. package/lib/ui/number.input.css +3 -0
  210. package/lib/ui/number.input.d.ts +12 -0
  211. package/lib/ui/number.input.js +64 -0
  212. package/lib/ui/tabs.css +53 -0
  213. package/package.json +1 -1
@@ -0,0 +1,1080 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jQueryReplacement } from "../core/jq";
13
+ import { Slick } from "./slick.core";
14
+ var $ = jQueryReplacement;
15
+ /***
16
+ * A sample Model implementation.
17
+ * Provides a filtered view of the underlying data.
18
+ *
19
+ * Relies on the data item having an "id" property uniquely identifying it.
20
+ */
21
+ export function DataView(options) {
22
+ var self = this;
23
+ var defaults = {
24
+ groupItemMetadataProvider: null,
25
+ inlineFilters: false
26
+ };
27
+ // private
28
+ var idProperty = "id"; // property holding a unique row id
29
+ var items = []; // data by index
30
+ var rows = []; // data by row
31
+ var idxById = {}; // indexes by id
32
+ var rowsById = null; // rows by id; lazy-calculated
33
+ var filter = null; // filter function
34
+ var updated = null; // updated item ids
35
+ var suspend = false; // suspends the recalculation
36
+ var sortAsc = true;
37
+ // var fastSortField;
38
+ var sortComparer;
39
+ var refreshHints = {};
40
+ var prevRefreshHints = {};
41
+ var filterArgs;
42
+ var filteredItems = [];
43
+ // let compiledFilter;
44
+ // let compiledFilterWithCaching;
45
+ var filterCache = [];
46
+ // grouping
47
+ var groupingInfoDefaults = {
48
+ getter: null,
49
+ formatter: null,
50
+ comparer: function (a, b) {
51
+ return (a.value === b.value ? 0 :
52
+ (a.value > b.value ? 1 : -1));
53
+ },
54
+ predefinedValues: [],
55
+ aggregators: [],
56
+ aggregateEmpty: false,
57
+ aggregateCollapsed: false,
58
+ aggregateChildGroups: false,
59
+ collapsed: false,
60
+ displayTotalsRow: true,
61
+ lazyTotalsCalculation: false
62
+ };
63
+ var groupingInfos = [];
64
+ var groups = [];
65
+ var toggledGroupsByLevel = [];
66
+ var groupingDelimiter = ":|:";
67
+ var pagesize = 0;
68
+ var pagenum = 0;
69
+ var totalRows = 0;
70
+ // events
71
+ var onRowCountChanged = new Slick.Event();
72
+ var onRowsChanged = new Slick.Event();
73
+ var onRowsOrCountChanged = new Slick.Event();
74
+ var onPagingInfoChanged = new Slick.Event();
75
+ options = $.deepExtend({}, defaults, options);
76
+ function beginUpdate() {
77
+ suspend = true;
78
+ }
79
+ function endUpdate() {
80
+ suspend = false;
81
+ refresh();
82
+ }
83
+ function setRefreshHints(hints) {
84
+ refreshHints = hints;
85
+ }
86
+ function setFilterArgs(args) {
87
+ filterArgs = args;
88
+ }
89
+ function updateIdxById(startingIndex) {
90
+ startingIndex = startingIndex || 0;
91
+ var id;
92
+ for (var i = startingIndex, l = items.length; i < l; i++) {
93
+ id = items[i][idProperty];
94
+ if (id === undefined) {
95
+ // throw new Error("Each data element must implement a unique 'id' property");
96
+ throw new Error("Id (" + idProperty + ") of element at index " + i + " was undefined");
97
+ }
98
+ idxById[id] = i;
99
+ }
100
+ }
101
+ function ensureIdUniqueness() {
102
+ var id;
103
+ for (var i = 0, l = items.length; i < l; i++) {
104
+ id = items[i][idProperty];
105
+ if (id === undefined) {
106
+ throw new Error("Id (" + idProperty + ") of element at index " + i + " was undefined");
107
+ }
108
+ else if (idxById[id] !== i) {
109
+ throw new Error("Duplicate id (" + idProperty + ") for " + id + " found at index (" + idxById[id] + ", " + i + ")");
110
+ }
111
+ }
112
+ }
113
+ function getItems() {
114
+ return items;
115
+ }
116
+ function setItems(data, objectIdProperty) {
117
+ if (objectIdProperty !== undefined) {
118
+ idProperty = objectIdProperty;
119
+ }
120
+ items = filteredItems = data;
121
+ idxById = {};
122
+ updateIdxById();
123
+ ensureIdUniqueness();
124
+ refresh();
125
+ }
126
+ function setPagingOptions(args) {
127
+ if (args.pageSize != undefined) {
128
+ pagesize = args.pageSize;
129
+ pagenum = pagesize ? Math.min(pagenum, Math.max(0, Math.ceil(totalRows / pagesize) - 1)) : 0;
130
+ }
131
+ if (args.pageNum != undefined) {
132
+ pagenum = Math.min(args.pageNum, Math.max(0, Math.ceil(totalRows / pagesize) - 1));
133
+ }
134
+ onPagingInfoChanged.notify(getPagingInfo(), null, self);
135
+ refresh();
136
+ }
137
+ function getPagingInfo() {
138
+ var totalPages = pagesize ? Math.max(1, Math.ceil(totalRows / pagesize)) : 1;
139
+ return { pageSize: pagesize, pageNum: pagenum, totalRows: totalRows, totalPages: totalPages, dataView: self };
140
+ }
141
+ function sort(comparer, ascending) {
142
+ sortAsc = ascending;
143
+ sortComparer = comparer;
144
+ // fastSortField = null;
145
+ if (ascending === false) {
146
+ items.reverse();
147
+ }
148
+ items.sort(comparer);
149
+ if (ascending === false) {
150
+ items.reverse();
151
+ }
152
+ idxById = {};
153
+ updateIdxById();
154
+ refresh();
155
+ }
156
+ function reSort() {
157
+ if (sortComparer) {
158
+ sort(sortComparer, sortAsc);
159
+ }
160
+ }
161
+ function getFilteredItems() {
162
+ return filteredItems;
163
+ }
164
+ function getFilter() {
165
+ return filter;
166
+ }
167
+ function setFilter(filterFn) {
168
+ filter = filterFn;
169
+ // if (options.inlineFilters) {
170
+ // compiledFilter = compileFilter();
171
+ // compiledFilterWithCaching = compileFilterWithCaching();
172
+ // }
173
+ refresh();
174
+ }
175
+ function getGrouping() {
176
+ return groupingInfos;
177
+ }
178
+ function setGrouping(groupingInfo) {
179
+ if (!options.groupItemMetadataProvider) {
180
+ options.groupItemMetadataProvider = new Slick.Data.GroupItemMetadataProvider();
181
+ }
182
+ groups = [];
183
+ toggledGroupsByLevel = [];
184
+ groupingInfo = groupingInfo || [];
185
+ groupingInfos = (groupingInfo instanceof Array) ? groupingInfo : [groupingInfo];
186
+ for (var i = 0; i < groupingInfos.length; i++) {
187
+ var gi = groupingInfos[i] = $.deepExtend({}, groupingInfoDefaults, groupingInfos[i]);
188
+ gi.getterIsAFn = typeof gi.getter === "function";
189
+ // pre-compile accumulator loops
190
+ gi.compiledAccumulators = [];
191
+ var idx = gi.aggregators.length;
192
+ while (idx--) {
193
+ gi.compiledAccumulators[idx] = compileAccumulatorLoop(gi.aggregators[idx]);
194
+ }
195
+ toggledGroupsByLevel[i] = {};
196
+ }
197
+ refresh();
198
+ }
199
+ /**
200
+ * @deprecated Please use {@link setGrouping}.
201
+ */
202
+ function groupBy(valueGetter, valueFormatter, sortComparer) {
203
+ if (valueGetter == null) {
204
+ setGrouping([]);
205
+ return;
206
+ }
207
+ setGrouping({
208
+ getter: valueGetter,
209
+ formatter: valueFormatter,
210
+ comparer: sortComparer
211
+ });
212
+ }
213
+ /**
214
+ * @deprecated Please use {@link setGrouping}.
215
+ */
216
+ function setAggregators(groupAggregators, includeCollapsed) {
217
+ if (!groupingInfos.length) {
218
+ throw new Error("At least one grouping must be specified before calling setAggregators().");
219
+ }
220
+ groupingInfos[0].aggregators = groupAggregators;
221
+ groupingInfos[0].aggregateCollapsed = includeCollapsed;
222
+ setGrouping(groupingInfos);
223
+ }
224
+ function getItemByIdx(i) {
225
+ return items[i];
226
+ }
227
+ function getIdxById(id) {
228
+ return idxById[id];
229
+ }
230
+ function getIdxByItem(item) {
231
+ return idxById[item[idProperty]];
232
+ }
233
+ function ensureRowsByIdCache() {
234
+ if (!rowsById) {
235
+ rowsById = {};
236
+ for (var i = 0, l = rows.length; i < l; i++) {
237
+ rowsById[rows[i][idProperty]] = i;
238
+ }
239
+ }
240
+ }
241
+ function getRowByItem(item) {
242
+ ensureRowsByIdCache();
243
+ return rowsById[item[idProperty]];
244
+ }
245
+ function getRowById(id) {
246
+ ensureRowsByIdCache();
247
+ return rowsById[id];
248
+ }
249
+ function getItemById(id) {
250
+ return items[idxById[id]];
251
+ }
252
+ function mapItemsToRows(itemArray) {
253
+ var rows = [];
254
+ ensureRowsByIdCache();
255
+ for (var i = 0, l = itemArray.length; i < l; i++) {
256
+ var row = rowsById[itemArray[i][idProperty]];
257
+ if (row != null) {
258
+ rows[rows.length] = row;
259
+ }
260
+ }
261
+ return rows;
262
+ }
263
+ function mapIdsToRows(idArray) {
264
+ var rows = [];
265
+ ensureRowsByIdCache();
266
+ for (var i = 0, l = idArray.length; i < l; i++) {
267
+ var row = rowsById[idArray[i]];
268
+ if (row != null) {
269
+ rows[rows.length] = row;
270
+ }
271
+ }
272
+ return rows;
273
+ }
274
+ function mapRowsToIds(rowArray) {
275
+ var ids = [];
276
+ for (var i = 0, l = rowArray.length; i < l; i++) {
277
+ if (rowArray[i] < rows.length) {
278
+ ids[ids.length] = rows[rowArray[i]][idProperty];
279
+ }
280
+ }
281
+ return ids;
282
+ }
283
+ function updateItem(id, item) {
284
+ // see also https://github.com/mleibman/SlickGrid/issues/1082
285
+ if (idxById[id] === undefined) {
286
+ throw new Error("Invalid id");
287
+ }
288
+ // what if the specified item also has an updated idProperty?
289
+ // then we'll have to update the index as well, and possibly the `updated` cache too.
290
+ if (id !== item[idProperty]) {
291
+ // make sure the new id is unique:
292
+ var newId = item[idProperty];
293
+ if (newId == null) {
294
+ throw new Error("Cannot update item to associate with a null id");
295
+ }
296
+ if (idxById[newId] !== undefined) {
297
+ throw new Error("Cannot update item to associate with a non-unique id");
298
+ }
299
+ idxById[newId] = idxById[id];
300
+ delete idxById[id];
301
+ // also update the `updated` hashtable/markercache? Yes, `recalc()` inside `refresh()` needs that one!
302
+ if (updated && updated[id]) {
303
+ delete updated[id];
304
+ }
305
+ // also update the row indexes? no need since the `refresh()`, further down, blows away the `rowsById[]` cache!
306
+ id = newId;
307
+ }
308
+ items[idxById[id]] = item;
309
+ // also update the rows? no need since the `refresh()`, further down, blows away the `rows[]` cache and recalculates it via `recalc()`!
310
+ if (!updated) {
311
+ updated = {};
312
+ }
313
+ updated[id] = true;
314
+ refresh();
315
+ }
316
+ function insertItem(insertBefore, item) {
317
+ items.splice(insertBefore, 0, item);
318
+ updateIdxById(insertBefore);
319
+ refresh();
320
+ }
321
+ function addItem(item) {
322
+ items.push(item);
323
+ updateIdxById(items.length - 1);
324
+ refresh();
325
+ }
326
+ function deleteItem(id) {
327
+ var idx = idxById[id];
328
+ if (idx === undefined) {
329
+ throw new Error("Invalid id");
330
+ }
331
+ delete idxById[id];
332
+ items.splice(idx, 1);
333
+ updateIdxById(idx);
334
+ refresh();
335
+ }
336
+ function sortedAddItem(item) {
337
+ if (!sortComparer) {
338
+ throw new Error("sortedAddItem() requires a sort comparer, use sort()");
339
+ }
340
+ insertItem(sortedIndex(item), item);
341
+ }
342
+ function sortedUpdateItem(id, item) {
343
+ if (idxById[id] === undefined || id !== item[idProperty]) {
344
+ throw new Error("Invalid or non-matching id " + idxById[id]);
345
+ }
346
+ if (!sortComparer) {
347
+ throw new Error("sortedUpdateItem() requires a sort comparer, use sort()");
348
+ }
349
+ var oldItem = getItemById(id);
350
+ if (sortComparer(oldItem, item) !== 0) {
351
+ // item affects sorting -> must use sorted add
352
+ deleteItem(id);
353
+ sortedAddItem(item);
354
+ }
355
+ else { // update does not affect sorting -> regular update works fine
356
+ updateItem(id, item);
357
+ }
358
+ }
359
+ function sortedIndex(searchItem) {
360
+ var low = 0, high = items.length;
361
+ while (low < high) {
362
+ var mid = low + high >>> 1;
363
+ if (sortComparer(items[mid], searchItem) === -1) {
364
+ low = mid + 1;
365
+ }
366
+ else {
367
+ high = mid;
368
+ }
369
+ }
370
+ return low;
371
+ }
372
+ function getLength() {
373
+ return rows.length;
374
+ }
375
+ function getItem(i) {
376
+ var item = rows[i];
377
+ // if this is a group row, make sure totals are calculated and update the title
378
+ if (item && item.__group && item.totals && !item.totals.initialized) {
379
+ var gi = groupingInfos[item.level];
380
+ if (!gi.displayTotalsRow) {
381
+ calculateTotals(item.totals);
382
+ item.title = gi.formatter ? gi.formatter(item) : item.value;
383
+ }
384
+ }
385
+ else if (item && item.__groupTotals && !item.initialized) {
386
+ calculateTotals(item);
387
+ }
388
+ return item;
389
+ }
390
+ function getItemMetadata(i) {
391
+ var item = rows[i];
392
+ if (item === undefined) {
393
+ return null;
394
+ }
395
+ // overrides for grouping rows
396
+ if (item.__group) {
397
+ return options.groupItemMetadataProvider.getGroupRowMetadata(item);
398
+ }
399
+ // overrides for totals rows
400
+ if (item.__groupTotals) {
401
+ return options.groupItemMetadataProvider.getTotalsRowMetadata(item);
402
+ }
403
+ if (item.__height) {
404
+ if (item.getItemMetadata != null) {
405
+ return __assign({ height: item.__height }, (item.getItemMetadata || {}));
406
+ }
407
+ return { height: item.__height };
408
+ }
409
+ return item.getItemMetadata != null ? item.getItemMetadata(i, item) : null;
410
+ }
411
+ function expandCollapseAllGroups(level, collapse) {
412
+ if (level == null) {
413
+ for (var i = 0; i < groupingInfos.length; i++) {
414
+ toggledGroupsByLevel[i] = {};
415
+ groupingInfos[i].collapsed = collapse;
416
+ }
417
+ }
418
+ else {
419
+ toggledGroupsByLevel[level] = {};
420
+ groupingInfos[level].collapsed = collapse;
421
+ }
422
+ refresh();
423
+ }
424
+ /**
425
+ * @param level {Number} Optional level to collapse. If not specified, applies to all levels.
426
+ */
427
+ function collapseAllGroups(level) {
428
+ expandCollapseAllGroups(level, true);
429
+ }
430
+ /**
431
+ * @param level {Number} Optional level to expand. If not specified, applies to all levels.
432
+ */
433
+ function expandAllGroups(level) {
434
+ expandCollapseAllGroups(level, false);
435
+ }
436
+ function expandCollapseGroup(level, groupingKey, collapse) {
437
+ toggledGroupsByLevel[level][groupingKey] = groupingInfos[level].collapsed ^ collapse;
438
+ refresh();
439
+ }
440
+ /**
441
+ * @param varArgs Either a Slick.Group's "groupingKey" property, or a
442
+ * variable argument list of grouping values denoting a unique path to the row. For
443
+ * example, calling collapseGroup('high', '10%') will collapse the '10%' subgroup of
444
+ * the 'high' group.
445
+ */
446
+ function collapseGroup(varArgs) {
447
+ var args = Array.prototype.slice.call(arguments);
448
+ var arg0 = args[0];
449
+ if (args.length == 1 && arg0.indexOf(groupingDelimiter) != -1) {
450
+ expandCollapseGroup(arg0.split(groupingDelimiter).length - 1, arg0, true);
451
+ }
452
+ else {
453
+ expandCollapseGroup(args.length - 1, args.join(groupingDelimiter), true);
454
+ }
455
+ }
456
+ /**
457
+ * @param varArgs Either a Slick.Group's "groupingKey" property, or a
458
+ * variable argument list of grouping values denoting a unique path to the row. For
459
+ * example, calling expandGroup('high', '10%') will expand the '10%' subgroup of
460
+ * the 'high' group.
461
+ */
462
+ function expandGroup(varArgs) {
463
+ var args = Array.prototype.slice.call(arguments);
464
+ var arg0 = args[0];
465
+ if (args.length == 1 && arg0.indexOf(groupingDelimiter) != -1) {
466
+ expandCollapseGroup(arg0.split(groupingDelimiter).length - 1, arg0, false);
467
+ }
468
+ else {
469
+ expandCollapseGroup(args.length - 1, args.join(groupingDelimiter), false);
470
+ }
471
+ }
472
+ function getGroups() {
473
+ return groups;
474
+ }
475
+ function extractGroups(rows, parentGroup) {
476
+ var group;
477
+ var val;
478
+ var groups = [];
479
+ var groupsByVal = {};
480
+ var r;
481
+ var level = parentGroup ? parentGroup.level + 1 : 0;
482
+ var gi = groupingInfos[level];
483
+ for (var i = 0, l = gi.predefinedValues.length; i < l; i++) {
484
+ val = gi.predefinedValues[i];
485
+ group = groupsByVal[val];
486
+ if (!group) {
487
+ group = new Slick.Group();
488
+ group.value = val;
489
+ group.level = level;
490
+ group.groupingKey = (parentGroup ? parentGroup.groupingKey + groupingDelimiter : "") + val;
491
+ groups[groups.length] = group;
492
+ groupsByVal[val] = group;
493
+ }
494
+ }
495
+ for (var i = 0, l = rows.length; i < l; i++) {
496
+ r = rows[i];
497
+ val = gi.getterIsAFn ? gi.getter(r) : r[gi.getter];
498
+ group = groupsByVal[val];
499
+ if (!group) {
500
+ group = new Slick.Group();
501
+ group.value = val;
502
+ group.level = level;
503
+ group.groupingKey = (parentGroup ? parentGroup.groupingKey + groupingDelimiter : "") + val;
504
+ groups[groups.length] = group;
505
+ groupsByVal[val] = group;
506
+ }
507
+ group.rows[group.count++] = r;
508
+ }
509
+ if (level < groupingInfos.length - 1) {
510
+ for (var i = 0; i < groups.length; i++) {
511
+ group = groups[i];
512
+ group.groups = extractGroups(group.rows, group);
513
+ }
514
+ }
515
+ groups.sort(groupingInfos[level].comparer);
516
+ return groups;
517
+ }
518
+ function calculateTotals(totals) {
519
+ var group = totals.group;
520
+ var gi = groupingInfos[group.level];
521
+ var isLeafLevel = (group.level == groupingInfos.length);
522
+ var agg, idx = gi.aggregators.length;
523
+ if (!isLeafLevel && gi.aggregateChildGroups) {
524
+ // make sure all the subgroups are calculated
525
+ var i = group.groups.length;
526
+ while (i--) {
527
+ if (!group.groups[i].totals.initialized) {
528
+ calculateTotals(group.groups[i].totals);
529
+ }
530
+ }
531
+ }
532
+ while (idx--) {
533
+ agg = gi.aggregators[idx];
534
+ agg.init();
535
+ if (!isLeafLevel && gi.aggregateChildGroups) {
536
+ gi.compiledAccumulators[idx].call(agg, group.groups);
537
+ }
538
+ else {
539
+ gi.compiledAccumulators[idx].call(agg, group.rows);
540
+ }
541
+ agg.storeResult(totals);
542
+ }
543
+ totals.initialized = true;
544
+ }
545
+ function addGroupTotals(group) {
546
+ var gi = groupingInfos[group.level];
547
+ var totals = new Slick.GroupTotals();
548
+ totals.group = group;
549
+ group.totals = totals;
550
+ if (!gi.lazyTotalsCalculation) {
551
+ calculateTotals(totals);
552
+ }
553
+ }
554
+ function addTotals(groups, level) {
555
+ level = level || 0;
556
+ var gi = groupingInfos[level];
557
+ var groupCollapsed = gi.collapsed;
558
+ var toggledGroups = toggledGroupsByLevel[level];
559
+ var idx = groups.length, g;
560
+ while (idx--) {
561
+ g = groups[idx];
562
+ if (g.collapsed && !gi.aggregateCollapsed) {
563
+ continue;
564
+ }
565
+ // do a depth-first aggregation so that parent group aggregators can access subgroup totals.
566
+ if (g.groups) {
567
+ addTotals(g.groups, level + 1);
568
+ }
569
+ if (gi.aggregators.length && (gi.aggregateEmpty || g.rows.length || (g.groups && g.groups.length))) {
570
+ addGroupTotals(g);
571
+ }
572
+ g.collapsed = groupCollapsed ^ toggledGroups[g.groupingKey];
573
+ g.title = gi.formatter ? gi.formatter(g) : g.value;
574
+ }
575
+ }
576
+ function flattenGroupedRows(groups, level) {
577
+ level = level || 0;
578
+ var gi = groupingInfos[level];
579
+ var groupedRows = [], rows, gl = 0, g;
580
+ for (var i = 0, l = groups.length; i < l; i++) {
581
+ g = groups[i];
582
+ groupedRows[gl++] = g;
583
+ if (!g.collapsed) {
584
+ rows = g.groups ? flattenGroupedRows(g.groups, level + 1) : g.rows;
585
+ for (var j = 0, jj = rows.length; j < jj; j++) {
586
+ groupedRows[gl++] = rows[j];
587
+ }
588
+ }
589
+ if (g.totals && gi.displayTotalsRow && (!g.collapsed || gi.aggregateCollapsed)) {
590
+ groupedRows[gl++] = g.totals;
591
+ }
592
+ }
593
+ return groupedRows;
594
+ }
595
+ function getFunctionInfo(fn) {
596
+ var fnRegex = /^function[^(]*\(([^)]*)\)\s*{([\s\S]*)}$/;
597
+ var matches = fn.toString().match(fnRegex);
598
+ return {
599
+ params: matches[1].split(","),
600
+ body: matches[2]
601
+ };
602
+ }
603
+ function compileAccumulatorLoop(aggregator) {
604
+ var accumulatorInfo = getFunctionInfo(aggregator.accumulate);
605
+ var fn = new Function("_items", "for (var " + accumulatorInfo.params[0] + ", _i=0, _il=_items.length; _i<_il; _i++) {" +
606
+ accumulatorInfo.params[0] + " = _items[_i]; " +
607
+ accumulatorInfo.body +
608
+ "}");
609
+ fn.displayName /*= fn.name*/ = "compiledAccumulatorLoop";
610
+ return fn;
611
+ }
612
+ // function compileFilter() {
613
+ // let filterInfo = getFunctionInfo(filter);
614
+ // let filterPath1 = "{ continue _coreloop; }$1";
615
+ // let filterPath2 = "{ _retval[_idx++] = $item$; continue _coreloop; }$1";
616
+ // // make some allowances for minification - there's only so far we can go with RegEx
617
+ // let filterBody = filterInfo.body
618
+ // .replace(/return false\s*([;}]|\}|$)/gi, filterPath1)
619
+ // .replace(/return!1([;}]|\}|$)/gi, filterPath1)
620
+ // .replace(/return true\s*([;}]|\}|$)/gi, filterPath2)
621
+ // .replace(/return!0([;}]|\}|$)/gi, filterPath2)
622
+ // .replace(/return ([^;}]+?)\s*([;}]|$)/gi,
623
+ // "{ if ($1) { _retval[_idx++] = $item$; }; continue _coreloop; }$2");
624
+ // // This preserves the function template code after JS compression,
625
+ // // so that replace() commands still work as expected.
626
+ // let tpl = [
627
+ // // "function(_items, _args) { ",
628
+ // "var _retval = [], _idx = 0; ",
629
+ // "var $item$, $args$ = _args; ",
630
+ // "_coreloop: ",
631
+ // "for (var _i = 0, _il = _items.length; _i < _il; _i++) { ",
632
+ // "$item$ = _items[_i]; ",
633
+ // "$filter$; ",
634
+ // "} ",
635
+ // "return _retval; "
636
+ // // "}"
637
+ // ].join("");
638
+ // tpl = tpl.replace(/\$filter\$/gi, filterBody);
639
+ // tpl = tpl.replace(/\$item\$/gi, filterInfo.params[0]);
640
+ // tpl = tpl.replace(/\$args\$/gi, filterInfo.params[1]);
641
+ // let fn: any = new Function("_items,_args", tpl);
642
+ // fn.displayName = /*fn.name =*/ "compiledFilter";
643
+ // return fn;
644
+ // }
645
+ // function compileFilterWithCaching() {
646
+ // let filterInfo = getFunctionInfo(filter);
647
+ // let filterPath1 = "{ continue _coreloop; }$1";
648
+ // let filterPath2 = "{ _cache[_i] = true;_retval[_idx++] = $item$; continue _coreloop; }$1";
649
+ // // make some allowances for minification - there's only so far we can go with RegEx
650
+ // let filterBody = filterInfo.body
651
+ // .replace(/return false\s*([;}]|\}|$)/gi, filterPath1)
652
+ // .replace(/return!1([;}]|\}|$)/gi, filterPath1)
653
+ // .replace(/return true\s*([;}]|\}|$)/gi, filterPath2)
654
+ // .replace(/return!0([;}]|\}|$)/gi, filterPath2)
655
+ // .replace(/return ([^;}]+?)\s*([;}]|$)/gi,
656
+ // "{ if ((_cache[_i] = $1)) { _retval[_idx++] = $item$; }; continue _coreloop; }$2");
657
+ // // This preserves the function template code after JS compression,
658
+ // // so that replace() commands still work as expected.
659
+ // let tpl = [
660
+ // // "function(_items, _args, _cache) { ",
661
+ // "var _retval = [], _idx = 0; ",
662
+ // "var $item$, $args$ = _args; ",
663
+ // "_coreloop: ",
664
+ // "for (var _i = 0, _il = _items.length; _i < _il; _i++) { ",
665
+ // "$item$ = _items[_i]; ",
666
+ // "if (_cache[_i]) { ",
667
+ // "_retval[_idx++] = $item$; ",
668
+ // "continue _coreloop; ",
669
+ // "} ",
670
+ // "$filter$; ",
671
+ // "} ",
672
+ // "return _retval; "
673
+ // // "}"
674
+ // ].join("");
675
+ // tpl = tpl.replace(/\$filter\$/gi, filterBody);
676
+ // tpl = tpl.replace(/\$item\$/gi, filterInfo.params[0]);
677
+ // tpl = tpl.replace(/\$args\$/gi, filterInfo.params[1]);
678
+ // let fn: any = new Function("_items,_args,_cache", tpl);
679
+ // fn.displayName /*= fn.name*/ = "compiledFilterWithCaching";
680
+ // return fn;
681
+ // }
682
+ function uncompiledFilter(items, args) {
683
+ var retval = [], idx = 0;
684
+ for (var i = 0, ii = items.length; i < ii; i++) {
685
+ if (filter(items[i], args)) {
686
+ retval[idx++] = items[i];
687
+ }
688
+ }
689
+ return retval;
690
+ }
691
+ function uncompiledFilterWithCaching(items, args, cache) {
692
+ var retval = [], idx = 0, item;
693
+ for (var i = 0, ii = items.length; i < ii; i++) {
694
+ item = items[i];
695
+ if (cache[i]) {
696
+ retval[idx++] = item;
697
+ }
698
+ else if (filter(item, args)) {
699
+ retval[idx++] = item;
700
+ cache[i] = true;
701
+ }
702
+ }
703
+ return retval;
704
+ }
705
+ function getFilteredAndPagedItems(items) {
706
+ if (filter) {
707
+ var batchFilter = uncompiledFilter; // options.inlineFilters ? compiledFilter : uncompiledFilter;
708
+ var batchFilterWithCaching = uncompiledFilterWithCaching; // options.inlineFilters ? compiledFilterWithCaching : uncompiledFilterWithCaching;
709
+ if (refreshHints.isFilterNarrowing) {
710
+ filteredItems = batchFilter(filteredItems, filterArgs);
711
+ }
712
+ else if (refreshHints.isFilterExpanding) {
713
+ filteredItems = batchFilterWithCaching(items, filterArgs, filterCache);
714
+ }
715
+ else if (!refreshHints.isFilterUnchanged) {
716
+ filteredItems = batchFilter(items, filterArgs);
717
+ }
718
+ }
719
+ else {
720
+ // special case: if not filtering and not paging, the resulting
721
+ // rows collection needs to be a copy so that changes due to sort
722
+ // can be caught
723
+ filteredItems = pagesize ? items : items.concat();
724
+ }
725
+ // get the current page
726
+ var paged;
727
+ if (pagesize) {
728
+ if (filteredItems.length <= pagenum * pagesize) {
729
+ if (filteredItems.length === 0) {
730
+ pagenum = 0;
731
+ }
732
+ else {
733
+ pagenum = Math.floor((filteredItems.length - 1) / pagesize);
734
+ }
735
+ }
736
+ paged = filteredItems.slice(pagesize * pagenum, pagesize * pagenum + pagesize);
737
+ }
738
+ else {
739
+ paged = filteredItems;
740
+ }
741
+ return { totalRows: filteredItems.length, rows: paged };
742
+ }
743
+ function getRowDiffs(rows, newRows) {
744
+ var item, r, eitherIsNonData, diff = [];
745
+ var from = 0, to = newRows.length;
746
+ if (refreshHints && refreshHints.ignoreDiffsBefore) {
747
+ from = Math.max(0, Math.min(newRows.length, refreshHints.ignoreDiffsBefore));
748
+ }
749
+ if (refreshHints && refreshHints.ignoreDiffsAfter) {
750
+ to = Math.min(newRows.length, Math.max(0, refreshHints.ignoreDiffsAfter));
751
+ }
752
+ for (var i = from, rl = rows.length; i < to; i++) {
753
+ if (i >= rl) {
754
+ diff[diff.length] = i;
755
+ }
756
+ else {
757
+ item = newRows[i];
758
+ r = rows[i];
759
+ if ((groupingInfos.length && (eitherIsNonData = (item.__nonDataRow) || (r.__nonDataRow)) &&
760
+ item.__group !== r.__group ||
761
+ item.__group && !item.equals(r))
762
+ || (eitherIsNonData &&
763
+ // no good way to compare totals since they are arbitrary DTOs
764
+ // deep object comparison is pretty expensive
765
+ // always considering them 'dirty' seems easier for the time being
766
+ (item.__groupTotals || r.__groupTotals))
767
+ || item[idProperty] != r[idProperty]
768
+ || (updated && updated[item[idProperty]])) {
769
+ diff[diff.length] = i;
770
+ }
771
+ }
772
+ }
773
+ return diff;
774
+ }
775
+ function recalc(_items, second) {
776
+ rowsById = null;
777
+ if (refreshHints.isFilterNarrowing != prevRefreshHints.isFilterNarrowing ||
778
+ refreshHints.isFilterExpanding != prevRefreshHints.isFilterExpanding) {
779
+ filterCache = [];
780
+ }
781
+ var filteredItems = getFilteredAndPagedItems(_items);
782
+ totalRows = filteredItems.totalRows;
783
+ var newRows = filteredItems.rows;
784
+ groups = [];
785
+ if (groupingInfos.length) {
786
+ groups = extractGroups(newRows);
787
+ if (groups.length) {
788
+ addTotals(groups);
789
+ newRows = flattenGroupedRows(groups);
790
+ }
791
+ }
792
+ var diff = getRowDiffs(rows, newRows);
793
+ rows = newRows;
794
+ return diff;
795
+ }
796
+ function refresh() {
797
+ if (suspend) {
798
+ return;
799
+ }
800
+ var countBefore = rows.length;
801
+ var totalRowsBefore = totalRows;
802
+ var diff = recalc(items, filter); // pass as direct refs to avoid closure perf hit
803
+ // if the current page is no longer valid, go to last page and recalc
804
+ // we suffer a performance penalty here, but the main loop (recalc) remains highly optimized
805
+ if (pagesize && totalRows < pagenum * pagesize) {
806
+ pagenum = Math.max(0, Math.ceil(totalRows / pagesize) - 1);
807
+ diff = recalc(items, filter);
808
+ }
809
+ updated = null;
810
+ prevRefreshHints = refreshHints;
811
+ refreshHints = {};
812
+ if (totalRowsBefore !== totalRows) {
813
+ onPagingInfoChanged.notify(getPagingInfo(), null, self);
814
+ }
815
+ if (countBefore !== rows.length) {
816
+ onRowCountChanged.notify({ previous: countBefore, current: rows.length, dataView: self, callingOnRowsChanged: (diff.length > 0) }, null, self);
817
+ }
818
+ if (diff.length > 0) {
819
+ onRowsChanged.notify({ rows: diff, dataView: self, calledOnRowCountChanged: (countBefore !== rows.length) }, null, self);
820
+ }
821
+ if (countBefore !== rows.length || diff.length > 0) {
822
+ onRowsOrCountChanged.notify({
823
+ rowsDiff: diff, previousRowCount: countBefore, currentRowCount: rows.length,
824
+ rowCountChanged: countBefore !== rows.length, rowsChanged: diff.length > 0, dataView: self
825
+ }, null, self);
826
+ }
827
+ }
828
+ /***
829
+ * Wires the grid and the DataView together to keep row selection tied to item ids.
830
+ * This is useful since, without it, the grid only knows about rows, so if the items
831
+ * move around, the same rows stay selected instead of the selection moving along
832
+ * with the items.
833
+ *
834
+ * NOTE: This doesn't work with cell selection model.
835
+ *
836
+ * @param grid {Slick.Grid} The grid to sync selection with.
837
+ * @param preserveHidden {Boolean} Whether to keep selected items that go out of the
838
+ * view due to them getting filtered out.
839
+ * @param preserveHiddenOnSelectionChange {Boolean} Whether to keep selected items
840
+ * that are currently out of the view (see preserveHidden) as selected when selection
841
+ * changes.
842
+ * @return {Slick.Event} An event that notifies when an internal list of selected row ids
843
+ * changes. This is useful since, in combination with the above two options, it allows
844
+ * access to the full list selected row ids, and not just the ones visible to the grid.
845
+ * @method syncGridSelection
846
+ */
847
+ function syncGridSelection(grid, preserveHidden, preserveHiddenOnSelectionChange) {
848
+ var self = this;
849
+ var inHandler;
850
+ var selectedRowIds = self.mapRowsToIds(grid.getSelectedRows());
851
+ var onSelectedRowIdsChanged = new Slick.Event();
852
+ function setSelectedRowIds(rowIds) {
853
+ if (selectedRowIds.join(",") == rowIds.join(",")) {
854
+ return;
855
+ }
856
+ selectedRowIds = rowIds;
857
+ onSelectedRowIdsChanged.notify({
858
+ grid: grid,
859
+ ids: selectedRowIds,
860
+ dataView: self
861
+ }, new Slick.EventData(), self);
862
+ }
863
+ function update() {
864
+ if (selectedRowIds.length > 0) {
865
+ inHandler = true;
866
+ var selectedRows = self.mapIdsToRows(selectedRowIds);
867
+ if (!preserveHidden) {
868
+ setSelectedRowIds(self.mapRowsToIds(selectedRows));
869
+ }
870
+ grid.setSelectedRows(selectedRows);
871
+ inHandler = false;
872
+ }
873
+ }
874
+ grid.onSelectedRowsChanged.subscribe(function (e, args) {
875
+ if (inHandler) {
876
+ return;
877
+ }
878
+ var newSelectedRowIds = self.mapRowsToIds(grid.getSelectedRows());
879
+ if (!preserveHiddenOnSelectionChange || !grid.getOptions().multiSelect) {
880
+ setSelectedRowIds(newSelectedRowIds);
881
+ }
882
+ else {
883
+ // keep the ones that are hidden
884
+ var existing = [];
885
+ for (var i = 0; i < selectedRowIds.length; i++) {
886
+ if (self.getRowById(selectedRowIds[i]) === undefined) {
887
+ existing.push(selectedRowIds[i]);
888
+ }
889
+ }
890
+ // $.grep(selectedRowIds, function(id) { return self.getRowById(id) === undefined; });
891
+ // add the newly selected ones
892
+ setSelectedRowIds(existing.concat(newSelectedRowIds));
893
+ }
894
+ });
895
+ this.onRowsOrCountChanged.subscribe(update);
896
+ return onSelectedRowIdsChanged;
897
+ }
898
+ function syncGridCellCssStyles(grid, key) {
899
+ var hashById;
900
+ var inHandler;
901
+ // since this method can be called after the cell styles have been set,
902
+ // get the existing ones right away
903
+ storeCellCssStyles(grid.getCellCssStyles(key));
904
+ function storeCellCssStyles(hash) {
905
+ hashById = {};
906
+ for (var row in hash) {
907
+ var id = rows[row][idProperty];
908
+ hashById[id] = hash[row];
909
+ }
910
+ }
911
+ function update() {
912
+ if (hashById) {
913
+ inHandler = true;
914
+ ensureRowsByIdCache();
915
+ var newHash = {};
916
+ for (var id in hashById) {
917
+ var row = rowsById[id];
918
+ if (row != undefined) {
919
+ newHash[row] = hashById[id];
920
+ }
921
+ }
922
+ grid.setCellCssStyles(key, newHash);
923
+ inHandler = false;
924
+ }
925
+ }
926
+ grid.onCellCssStylesChanged.subscribe(function (e, args) {
927
+ if (inHandler) {
928
+ return;
929
+ }
930
+ if (key != args.key) {
931
+ return;
932
+ }
933
+ if (args.hash) {
934
+ storeCellCssStyles(args.hash);
935
+ }
936
+ else {
937
+ // grid.onCellCssStylesChanged.unsubscribe(styleChanged); //styleChanged not declared
938
+ self.onRowsOrCountChanged.unsubscribe(update);
939
+ }
940
+ });
941
+ this.onRowsOrCountChanged.subscribe(update);
942
+ }
943
+ $.shallowExtend(this, {
944
+ // methods
945
+ beginUpdate: beginUpdate,
946
+ endUpdate: endUpdate,
947
+ setPagingOptions: setPagingOptions,
948
+ getPagingInfo: getPagingInfo,
949
+ getItems: getItems,
950
+ setItems: setItems,
951
+ setFilter: setFilter,
952
+ getFilter: getFilter,
953
+ getFilteredItems: getFilteredItems,
954
+ sort: sort,
955
+ // "fastSort": fastSort,
956
+ reSort: reSort,
957
+ setGrouping: setGrouping,
958
+ getGrouping: getGrouping,
959
+ groupBy: groupBy,
960
+ setAggregators: setAggregators,
961
+ collapseAllGroups: collapseAllGroups,
962
+ expandAllGroups: expandAllGroups,
963
+ collapseGroup: collapseGroup,
964
+ expandGroup: expandGroup,
965
+ getGroups: getGroups,
966
+ getIdxById: getIdxById,
967
+ getIdxByItem: getIdxByItem,
968
+ getRowByItem: getRowByItem,
969
+ getRowById: getRowById,
970
+ getItemById: getItemById,
971
+ getItemByIdx: getItemByIdx,
972
+ mapItemsToRows: mapItemsToRows,
973
+ mapRowsToIds: mapRowsToIds,
974
+ mapIdsToRows: mapIdsToRows,
975
+ setRefreshHints: setRefreshHints,
976
+ setFilterArgs: setFilterArgs,
977
+ refresh: refresh,
978
+ updateItem: updateItem,
979
+ insertItem: insertItem,
980
+ addItem: addItem,
981
+ deleteItem: deleteItem,
982
+ sortedAddItem: sortedAddItem,
983
+ sortedUpdateItem: sortedUpdateItem,
984
+ syncGridSelection: syncGridSelection,
985
+ syncGridCellCssStyles: syncGridCellCssStyles,
986
+ // data provider methods
987
+ getLength: getLength,
988
+ getItem: getItem,
989
+ getItemMetadata: getItemMetadata,
990
+ // events
991
+ onRowCountChanged: onRowCountChanged,
992
+ onRowsChanged: onRowsChanged,
993
+ onRowsOrCountChanged: onRowsOrCountChanged,
994
+ onPagingInfoChanged: onPagingInfoChanged
995
+ });
996
+ }
997
+ export function AvgAggregator(field) {
998
+ this.field_ = field;
999
+ this.init = function () {
1000
+ this.count_ = 0;
1001
+ this.nonNullCount_ = 0;
1002
+ this.sum_ = 0;
1003
+ };
1004
+ this.accumulate = function (item) {
1005
+ var val = item[this.field_];
1006
+ this.count_++;
1007
+ if (val != null && val !== "" && !isNaN(val)) {
1008
+ this.nonNullCount_++;
1009
+ this.sum_ += parseFloat(val);
1010
+ }
1011
+ };
1012
+ this.storeResult = function (groupTotals) {
1013
+ if (!groupTotals.avg) {
1014
+ groupTotals.avg = {};
1015
+ }
1016
+ if (this.nonNullCount_ != 0) {
1017
+ groupTotals.avg[this.field_] = this.sum_ / this.nonNullCount_;
1018
+ }
1019
+ };
1020
+ }
1021
+ export function MinAggregator(field) {
1022
+ this.field_ = field;
1023
+ this.init = function () {
1024
+ this.min_ = null;
1025
+ };
1026
+ this.accumulate = function (item) {
1027
+ var val = item[this.field_];
1028
+ if (val != null && val !== "" && !isNaN(val)) {
1029
+ if (this.min_ == null || val < this.min_) {
1030
+ this.min_ = val;
1031
+ }
1032
+ }
1033
+ };
1034
+ this.storeResult = function (groupTotals) {
1035
+ if (!groupTotals.min) {
1036
+ groupTotals.min = {};
1037
+ }
1038
+ groupTotals.min[this.field_] = this.min_;
1039
+ };
1040
+ }
1041
+ export function MaxAggregator(field) {
1042
+ this.field_ = field;
1043
+ this.init = function () {
1044
+ this.max_ = null;
1045
+ };
1046
+ this.accumulate = function (item) {
1047
+ var val = item[this.field_];
1048
+ if (val != null && val !== "" && !isNaN(val)) {
1049
+ if (this.max_ == null || val > this.max_) {
1050
+ this.max_ = val;
1051
+ }
1052
+ }
1053
+ };
1054
+ this.storeResult = function (groupTotals) {
1055
+ if (!groupTotals.max) {
1056
+ groupTotals.max = {};
1057
+ }
1058
+ groupTotals.max[this.field_] = this.max_;
1059
+ };
1060
+ }
1061
+ export function SumAggregator(field) {
1062
+ this.field_ = field;
1063
+ this.init = function () {
1064
+ this.sum_ = null;
1065
+ };
1066
+ this.accumulate = function (item) {
1067
+ var val = item[this.field_];
1068
+ if (val != null && val !== "" && !isNaN(val)) {
1069
+ this.sum_ += parseFloat(val);
1070
+ }
1071
+ };
1072
+ this.storeResult = function (groupTotals) {
1073
+ if (!groupTotals.sum) {
1074
+ groupTotals.sum = {};
1075
+ }
1076
+ groupTotals.sum[this.field_] = this.sum_;
1077
+ };
1078
+ }
1079
+ // tODO: add more built-in aggregators
1080
+ // tODO: merge common aggregators in one to prevent needles iterating