tabulator-tables 5.4.3 → 5.4.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 (253) hide show
  1. package/.babelrc.json +3 -3
  2. package/.editorconfig +6 -6
  3. package/.eslintignore +3 -3
  4. package/.eslintrc.js +28 -28
  5. package/.github/ISSUE_TEMPLATE/bug_report.md +58 -58
  6. package/.github/ISSUE_TEMPLATE/documentation.md +14 -14
  7. package/.github/ISSUE_TEMPLATE/feature_request.md +24 -24
  8. package/.github/ISSUE_TEMPLATE/question.md +12 -12
  9. package/.github/workflows/bad-files-check.yml +39 -39
  10. package/.github/workflows/lint-and-test.yml +30 -30
  11. package/CODE_OF_CONDUCT.md +46 -46
  12. package/CONTRIBUTING.md +22 -22
  13. package/LICENSE +20 -20
  14. package/README.md +76 -76
  15. package/bower.json +40 -40
  16. package/build/Bundler.js +185 -185
  17. package/build/rollup.js +6 -6
  18. package/dist/css/tabulator.css +0 -5
  19. package/dist/css/tabulator.css.map +1 -1
  20. package/dist/css/tabulator.min.css +1 -1
  21. package/dist/css/tabulator.min.css.map +1 -1
  22. package/dist/css/tabulator_bootstrap3.css +0 -5
  23. package/dist/css/tabulator_bootstrap3.css.map +1 -1
  24. package/dist/css/tabulator_bootstrap3.min.css +1 -1
  25. package/dist/css/tabulator_bootstrap3.min.css.map +1 -1
  26. package/dist/css/tabulator_bootstrap4.css +0 -5
  27. package/dist/css/tabulator_bootstrap4.css.map +1 -1
  28. package/dist/css/tabulator_bootstrap4.min.css +1 -1
  29. package/dist/css/tabulator_bootstrap4.min.css.map +1 -1
  30. package/dist/css/tabulator_bootstrap5.css +0 -5
  31. package/dist/css/tabulator_bootstrap5.css.map +1 -1
  32. package/dist/css/tabulator_bootstrap5.min.css +1 -1
  33. package/dist/css/tabulator_bootstrap5.min.css.map +1 -1
  34. package/dist/css/tabulator_bulma.css +0 -5
  35. package/dist/css/tabulator_bulma.css.map +1 -1
  36. package/dist/css/tabulator_bulma.min.css +1 -1
  37. package/dist/css/tabulator_bulma.min.css.map +1 -1
  38. package/dist/css/tabulator_materialize.css +0 -5
  39. package/dist/css/tabulator_materialize.css.map +1 -1
  40. package/dist/css/tabulator_materialize.min.css +1 -1
  41. package/dist/css/tabulator_materialize.min.css.map +1 -1
  42. package/dist/css/tabulator_midnight.css +0 -5
  43. package/dist/css/tabulator_midnight.css.map +1 -1
  44. package/dist/css/tabulator_midnight.min.css +1 -1
  45. package/dist/css/tabulator_midnight.min.css.map +1 -1
  46. package/dist/css/tabulator_modern.css +0 -5
  47. package/dist/css/tabulator_modern.css.map +1 -1
  48. package/dist/css/tabulator_modern.min.css +1 -1
  49. package/dist/css/tabulator_modern.min.css.map +1 -1
  50. package/dist/css/tabulator_semanticui.css +102 -107
  51. package/dist/css/tabulator_semanticui.css.map +1 -1
  52. package/dist/css/tabulator_semanticui.min.css +1 -1
  53. package/dist/css/tabulator_semanticui.min.css.map +1 -1
  54. package/dist/css/tabulator_simple.css +0 -5
  55. package/dist/css/tabulator_simple.css.map +1 -1
  56. package/dist/css/tabulator_simple.min.css +1 -1
  57. package/dist/css/tabulator_simple.min.css.map +1 -1
  58. package/dist/css/tabulator_site.css +0 -5
  59. package/dist/css/tabulator_site.css.map +1 -1
  60. package/dist/css/tabulator_site.min.css +1 -1
  61. package/dist/css/tabulator_site.min.css.map +1 -1
  62. package/dist/js/jquery_wrapper.js +55 -55
  63. package/dist/js/tabulator.js +25847 -25711
  64. package/dist/js/tabulator.js.map +1 -1
  65. package/dist/js/tabulator.min.js +2 -2
  66. package/dist/js/tabulator.min.js.map +1 -1
  67. package/dist/js/tabulator_esm.js +25926 -25790
  68. package/dist/js/tabulator_esm.js.map +1 -1
  69. package/dist/js/tabulator_esm.min.js +2 -2
  70. package/dist/js/tabulator_esm.min.js.map +1 -1
  71. package/package.json +65 -65
  72. package/src/js/builds/esm.js +14 -14
  73. package/src/js/builds/jquery_wrapper.js +55 -55
  74. package/src/js/core/ColumnManager.js +730 -730
  75. package/src/js/core/CoreFeature.js +138 -138
  76. package/src/js/core/FooterManager.js +101 -101
  77. package/src/js/core/Module.js +141 -141
  78. package/src/js/core/RowManager.js +1112 -1101
  79. package/src/js/core/Tabulator.js +895 -892
  80. package/src/js/core/TabulatorFull.js +10 -10
  81. package/src/js/core/cell/Cell.js +295 -295
  82. package/src/js/core/cell/CellComponent.js +76 -76
  83. package/src/js/core/column/Column.js +949 -949
  84. package/src/js/core/column/ColumnComponent.js +152 -152
  85. package/src/js/core/column/defaults/options.js +17 -17
  86. package/src/js/core/defaults/options.js +65 -65
  87. package/src/js/core/modules/core.js +2 -2
  88. package/src/js/core/modules/optional.js +34 -34
  89. package/src/js/core/rendering/Renderer.js +203 -203
  90. package/src/js/core/rendering/renderers/BasicHorizontal.js +19 -19
  91. package/src/js/core/rendering/renderers/BasicVertical.js +79 -78
  92. package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +577 -577
  93. package/src/js/core/rendering/renderers/VirtualDomVertical.js +579 -579
  94. package/src/js/core/row/PseudoRow.js +44 -44
  95. package/src/js/core/row/Row.js +457 -457
  96. package/src/js/core/row/RowComponent.js +93 -93
  97. package/src/js/core/tools/Alert.js +61 -61
  98. package/src/js/core/tools/ComponentFunctionBinder.js +32 -32
  99. package/src/js/core/tools/DataLoader.js +119 -119
  100. package/src/js/core/tools/DeprecationAdvisor.js +46 -46
  101. package/src/js/core/tools/ExternalEventBus.js +104 -104
  102. package/src/js/core/tools/Helpers.js +46 -46
  103. package/src/js/core/tools/InteractionMonitor.js +321 -321
  104. package/src/js/core/tools/InternalEventBus.js +161 -161
  105. package/src/js/core/tools/ModuleBinder.js +104 -104
  106. package/src/js/core/tools/OptionsList.js +44 -40
  107. package/src/js/core/tools/Popup.js +304 -304
  108. package/src/js/core/tools/TableRegistry.js +61 -61
  109. package/src/js/modules/Accessor/Accessor.js +115 -115
  110. package/src/js/modules/Ajax/Ajax.js +143 -143
  111. package/src/js/modules/Ajax/defaults/config.js +2 -2
  112. package/src/js/modules/Ajax/defaults/contentTypeFormatters.js +44 -44
  113. package/src/js/modules/Ajax/defaults/loaderPromise.js +86 -86
  114. package/src/js/modules/Ajax/defaults/urlGenerator.js +43 -43
  115. package/src/js/modules/Clipboard/Clipboard.js +279 -279
  116. package/src/js/modules/Clipboard/defaults/pasteActions.js +10 -10
  117. package/src/js/modules/Clipboard/defaults/pasteParsers.js +74 -74
  118. package/src/js/modules/ColumnCalcs/CalcComponent.js +47 -47
  119. package/src/js/modules/ColumnCalcs/ColumnCalcs.js +581 -568
  120. package/src/js/modules/ColumnCalcs/defaults/calculations.js +85 -85
  121. package/src/js/modules/Comms/Comms.js +51 -51
  122. package/src/js/modules/DataTree/DataTree.js +603 -603
  123. package/src/js/modules/Download/Download.js +148 -148
  124. package/src/js/modules/Download/defaults/downloaders/csv.js +61 -61
  125. package/src/js/modules/Download/defaults/downloaders/html.js +4 -4
  126. package/src/js/modules/Download/defaults/downloaders/json.js +33 -33
  127. package/src/js/modules/Download/defaults/downloaders/jsonLines.js +31 -31
  128. package/src/js/modules/Download/defaults/downloaders/pdf.js +111 -111
  129. package/src/js/modules/Download/defaults/downloaders/xlsx.js +98 -98
  130. package/src/js/modules/Download/defaults/downloaders.js +14 -14
  131. package/src/js/modules/Edit/Edit.js +735 -736
  132. package/src/js/modules/Edit/List.js +1037 -1033
  133. package/src/js/modules/Edit/defaults/editors/autocomplete.js +11 -11
  134. package/src/js/modules/Edit/defaults/editors/date.js +138 -110
  135. package/src/js/modules/Edit/defaults/editors/datetime.js +125 -97
  136. package/src/js/modules/Edit/defaults/editors/input.js +76 -74
  137. package/src/js/modules/Edit/defaults/editors/list.js +6 -6
  138. package/src/js/modules/Edit/defaults/editors/number.js +109 -107
  139. package/src/js/modules/Edit/defaults/editors/progress.js +126 -126
  140. package/src/js/modules/Edit/defaults/editors/range.js +80 -78
  141. package/src/js/modules/Edit/defaults/editors/select.js +9 -9
  142. package/src/js/modules/Edit/defaults/editors/star.js +145 -145
  143. package/src/js/modules/Edit/defaults/editors/textarea.js +122 -120
  144. package/src/js/modules/Edit/defaults/editors/tickCross.js +94 -96
  145. package/src/js/modules/Edit/defaults/editors/time.js +126 -98
  146. package/src/js/modules/Edit/defaults/editors.js +28 -28
  147. package/src/js/modules/Edit/inputMask.js +73 -73
  148. package/src/js/modules/Export/Export.js +623 -623
  149. package/src/js/modules/Export/ExportColumn.js +10 -10
  150. package/src/js/modules/Export/ExportRow.js +9 -9
  151. package/src/js/modules/Filter/Filter.js +892 -892
  152. package/src/js/modules/Filter/defaults/filters.js +107 -107
  153. package/src/js/modules/Format/Format.js +212 -212
  154. package/src/js/modules/Format/defaults/formatters/buttonCross.js +2 -2
  155. package/src/js/modules/Format/defaults/formatters/buttonTick.js +2 -2
  156. package/src/js/modules/Format/defaults/formatters/color.js +3 -3
  157. package/src/js/modules/Format/defaults/formatters/datetime.js +36 -36
  158. package/src/js/modules/Format/defaults/formatters/datetimediff.js +40 -40
  159. package/src/js/modules/Format/defaults/formatters/handle.js +3 -3
  160. package/src/js/modules/Format/defaults/formatters/html.js +2 -2
  161. package/src/js/modules/Format/defaults/formatters/image.js +39 -39
  162. package/src/js/modules/Format/defaults/formatters/link.js +77 -77
  163. package/src/js/modules/Format/defaults/formatters/lookup.js +9 -9
  164. package/src/js/modules/Format/defaults/formatters/money.js +36 -36
  165. package/src/js/modules/Format/defaults/formatters/plaintext.js +2 -2
  166. package/src/js/modules/Format/defaults/formatters/progress.js +132 -132
  167. package/src/js/modules/Format/defaults/formatters/responsiveCollapse.js +43 -43
  168. package/src/js/modules/Format/defaults/formatters/rowSelection.js +59 -59
  169. package/src/js/modules/Format/defaults/formatters/rownum.js +9 -9
  170. package/src/js/modules/Format/defaults/formatters/star.js +37 -37
  171. package/src/js/modules/Format/defaults/formatters/textarea.js +3 -3
  172. package/src/js/modules/Format/defaults/formatters/tickCross.js +21 -21
  173. package/src/js/modules/Format/defaults/formatters/traffic.js +46 -46
  174. package/src/js/modules/Format/defaults/formatters.js +42 -42
  175. package/src/js/modules/FrozenColumns/FrozenColumns.js +299 -299
  176. package/src/js/modules/FrozenRows/FrozenRows.js +169 -159
  177. package/src/js/modules/GroupRows/Group.js +597 -598
  178. package/src/js/modules/GroupRows/GroupComponent.js +66 -66
  179. package/src/js/modules/GroupRows/GroupRows.js +639 -639
  180. package/src/js/modules/History/History.js +171 -171
  181. package/src/js/modules/History/defaults/redoers.js +24 -24
  182. package/src/js/modules/History/defaults/undoers.js +24 -24
  183. package/src/js/modules/HtmlTableImport/HtmlTableImport.js +181 -181
  184. package/src/js/modules/Import/Import.js +193 -193
  185. package/src/js/modules/Import/defaults/importers/array.js +4 -4
  186. package/src/js/modules/Import/defaults/importers/csv.js +62 -62
  187. package/src/js/modules/Import/defaults/importers/json.js +7 -7
  188. package/src/js/modules/Import/defaults/importers.js +8 -8
  189. package/src/js/modules/Interaction/Interaction.js +325 -325
  190. package/src/js/modules/Keybindings/Keybindings.js +172 -172
  191. package/src/js/modules/Keybindings/defaults/actions.js +118 -118
  192. package/src/js/modules/Keybindings/defaults/bindings.js +12 -12
  193. package/src/js/modules/Layout/Layout.js +49 -49
  194. package/src/js/modules/Layout/defaults/modes/fitColumns.js +171 -171
  195. package/src/js/modules/Layout/defaults/modes/fitData.js +9 -9
  196. package/src/js/modules/Layout/defaults/modes/fitDataGeneral.js +9 -9
  197. package/src/js/modules/Layout/defaults/modes/fitDataStretch.js +39 -39
  198. package/src/js/modules/Layout/defaults/modes.js +11 -11
  199. package/src/js/modules/Localize/Localize.js +185 -185
  200. package/src/js/modules/Localize/defaults/langs.js +36 -36
  201. package/src/js/modules/Menu/Menu.js +302 -302
  202. package/src/js/modules/MoveColumns/MoveColumns.js +299 -299
  203. package/src/js/modules/MoveRows/MoveRows.js +635 -635
  204. package/src/js/modules/Mutator/Mutator.js +161 -161
  205. package/src/js/modules/Page/Page.js +881 -881
  206. package/src/js/modules/Page/defaults/pageCounters/pages.js +32 -32
  207. package/src/js/modules/Page/defaults/pageCounters/rows.js +39 -39
  208. package/src/js/modules/Page/defaults/pageCounters.js +7 -7
  209. package/src/js/modules/Persistence/Persistence.js +458 -458
  210. package/src/js/modules/Persistence/defaults/readers.js +29 -29
  211. package/src/js/modules/Persistence/defaults/writers.js +12 -12
  212. package/src/js/modules/Popup/Popup.js +231 -231
  213. package/src/js/modules/Print/Print.js +137 -137
  214. package/src/js/modules/ReactiveData/ReactiveData.js +408 -408
  215. package/src/js/modules/ResizeColumns/ResizeColumns.js +309 -309
  216. package/src/js/modules/ResizeRows/ResizeRows.js +111 -111
  217. package/src/js/modules/ResizeTable/ResizeTable.js +159 -159
  218. package/src/js/modules/ResponsiveLayout/ResponsiveLayout.js +345 -345
  219. package/src/js/modules/SelectRow/SelectRow.js +446 -444
  220. package/src/js/modules/Sort/Sort.js +470 -470
  221. package/src/js/modules/Sort/defaults/sorters/alphanum.js +43 -43
  222. package/src/js/modules/Sort/defaults/sorters/array.js +53 -53
  223. package/src/js/modules/Sort/defaults/sorters/boolean.js +6 -6
  224. package/src/js/modules/Sort/defaults/sorters/date.js +9 -9
  225. package/src/js/modules/Sort/defaults/sorters/datetime.js +43 -43
  226. package/src/js/modules/Sort/defaults/sorters/exists.js +6 -6
  227. package/src/js/modules/Sort/defaults/sorters/number.js +39 -39
  228. package/src/js/modules/Sort/defaults/sorters/string.js +33 -33
  229. package/src/js/modules/Sort/defaults/sorters/time.js +9 -9
  230. package/src/js/modules/Sort/defaults/sorters.js +20 -20
  231. package/src/js/modules/Tooltip/Tooltip.js +130 -130
  232. package/src/js/modules/Validate/Validate.js +305 -305
  233. package/src/js/modules/Validate/defaults/validators.js +138 -138
  234. package/src/scss/tabulator.scss +1464 -1467
  235. package/src/scss/themes/bootstrap/functions4.scss +118 -118
  236. package/src/scss/themes/bootstrap/functions5.scss +302 -302
  237. package/src/scss/themes/bootstrap/tabulator_bootstrap3.scss +284 -284
  238. package/src/scss/themes/bootstrap/tabulator_bootstrap4.scss +544 -544
  239. package/src/scss/themes/bootstrap/tabulator_bootstrap5.scss +574 -574
  240. package/src/scss/themes/bootstrap/variables3.scss +870 -870
  241. package/src/scss/themes/bootstrap/variables4.scss +930 -930
  242. package/src/scss/themes/bootstrap/variables5.scss +1641 -1641
  243. package/src/scss/themes/bulma/tabulator_bulma.scss +252 -252
  244. package/src/scss/themes/bulma/variables.scss +197 -197
  245. package/src/scss/themes/materialize/tabulator_materialize.scss +265 -265
  246. package/src/scss/themes/materialize/variables.scss +70 -70
  247. package/src/scss/themes/semanticui/tabulator_semanticui.scss +561 -561
  248. package/src/scss/themes/semanticui/variables.scss +839 -839
  249. package/src/scss/themes/semanticui/variables_table.scss +247 -247
  250. package/src/scss/themes/tabulator_midnight.scss +158 -158
  251. package/src/scss/themes/tabulator_modern.scss +231 -231
  252. package/src/scss/themes/tabulator_simple.scss +102 -102
  253. package/src/scss/themes/tabulator_site.scss +189 -189
@@ -1,569 +1,582 @@
1
- import Module from '../../core/Module.js';
2
-
3
- import CalcComponent from './CalcComponent.js';
4
-
5
- import Cell from '../../core/cell/Cell.js';
6
- import Column from '../../core/column/Column.js';
7
- import Row from '../../core/row/Row.js';
8
-
9
- import defaultCalculations from './defaults/calculations.js';
10
-
11
- class ColumnCalcs extends Module{
12
-
13
- constructor(table){
14
- super(table);
15
-
16
- this.topCalcs = [];
17
- this.botCalcs = [];
18
- this.genColumn = false;
19
- this.topElement = this.createElement();
20
- this.botElement = this.createElement();
21
- this.topRow = false;
22
- this.botRow = false;
23
- this.topInitialized = false;
24
- this.botInitialized = false;
25
-
26
- this.blocked = false;
27
- this.recalcAfterBlock = false;
28
-
29
- this.registerTableOption("columnCalcs", true);
30
-
31
- this.registerColumnOption("topCalc");
32
- this.registerColumnOption("topCalcParams");
33
- this.registerColumnOption("topCalcFormatter");
34
- this.registerColumnOption("topCalcFormatterParams");
35
- this.registerColumnOption("bottomCalc");
36
- this.registerColumnOption("bottomCalcParams");
37
- this.registerColumnOption("bottomCalcFormatter");
38
- this.registerColumnOption("bottomCalcFormatterParams");
39
- }
40
-
41
- createElement (){
42
- var el = document.createElement("div");
43
- el.classList.add("tabulator-calcs-holder");
44
- return el;
45
- }
46
-
47
- initialize(){
48
- this.genColumn = new Column({field:"value"}, this);
49
-
50
- this.subscribe("cell-value-changed", this.cellValueChanged.bind(this));
51
- this.subscribe("column-init", this.initializeColumnCheck.bind(this));
52
- this.subscribe("row-deleted", this.rowsUpdated.bind(this));
53
- this.subscribe("scroll-horizontal", this.scrollHorizontal.bind(this));
54
- this.subscribe("row-added", this.rowsUpdated.bind(this));
55
- this.subscribe("column-moved", this.recalcActiveRows.bind(this));
56
- this.subscribe("column-add", this.recalcActiveRows.bind(this));
57
- this.subscribe("data-refreshed", this.recalcActiveRowsRefresh.bind(this));
58
- this.subscribe("table-redraw", this.tableRedraw.bind(this));
59
- this.subscribe("rows-visible", this.visibleRows.bind(this));
60
- this.subscribe("scrollbar-vertical", this.adjustForScrollbar.bind(this));
61
-
62
- this.subscribe("redraw-blocked", this.blockRedraw.bind(this));
63
- this.subscribe("redraw-restored", this.restoreRedraw.bind(this));
64
-
65
- this.registerTableFunction("getCalcResults", this.getResults.bind(this));
66
- this.registerTableFunction("recalc", this.userRecalc.bind(this));
67
- }
68
-
69
- tableRedraw(force){
70
- this.recalc(this.table.rowManager.activeRows);
71
-
72
- if(force){
73
- this.redraw();
74
- }
75
- }
76
-
77
- blockRedraw(){
78
- this.blocked = true;
79
- this.recalcAfterBlock = false;
80
- }
81
-
82
-
83
- restoreRedraw(){
84
- this.blocked = false;
85
-
86
- if(this.recalcAfterBlock){
87
- this.recalcAfterBlock = false;
88
- this.recalcActiveRowsRefresh();
89
- }
90
- }
91
-
92
- ///////////////////////////////////
93
- ///////// Table Functions /////////
94
- ///////////////////////////////////
95
- userRecalc(){
96
- this.recalc(this.table.rowManager.activeRows);
97
- }
98
-
99
- ///////////////////////////////////
100
- ///////// Internal Logic //////////
101
- ///////////////////////////////////
102
-
103
- blockCheck(){
104
- if(this.blocked){
105
- this.recalcAfterBlock = true;
106
- }
107
-
108
- return this.blocked;
109
- }
110
-
111
- visibleRows(viewable, rows){
112
- if(this.topRow){
113
- rows.unshift(this.topRow);
114
- }
115
-
116
- if(this.botRow){
117
- rows.push(this.botRow);
118
- }
119
-
120
- return rows;
121
- }
122
-
123
- rowsUpdated(row){
124
- if(this.table.options.groupBy){
125
- this.recalcRowGroup(row);
126
- }else{
127
- this.recalcActiveRows();
128
- }
129
- }
130
-
131
- recalcActiveRowsRefresh(){
132
- if(this.table.options.groupBy && this.table.options.dataTreeStartExpanded && this.table.options.dataTree){
133
- this.recalcAll();
134
- }else{
135
- this.recalcActiveRows();
136
- }
137
- }
138
-
139
- recalcActiveRows(){
140
- this.recalc(this.table.rowManager.activeRows);
141
- }
142
-
143
- cellValueChanged(cell){
144
- if(cell.column.definition.topCalc || cell.column.definition.bottomCalc){
145
- if(this.table.options.groupBy){
146
- if(this.table.options.columnCalcs == "table" || this.table.options.columnCalcs == "both"){
147
- this.recalcActiveRows();
148
- }
149
-
150
- if(this.table.options.columnCalcs != "table"){
151
- this.recalcRowGroup(cell.row);
152
- }
153
- }else{
154
- this.recalcActiveRows();
155
- }
156
- }
157
- }
158
-
159
- initializeColumnCheck(column){
160
- if(column.definition.topCalc || column.definition.bottomCalc){
161
- this.initializeColumn(column);
162
- }
163
- }
164
-
165
- //initialize column calcs
166
- initializeColumn(column){
167
- var def = column.definition;
168
-
169
- var config = {
170
- topCalcParams:def.topCalcParams || {},
171
- botCalcParams:def.bottomCalcParams || {},
172
- };
173
-
174
- if(def.topCalc){
175
-
176
- switch(typeof def.topCalc){
177
- case "string":
178
- if(ColumnCalcs.calculations[def.topCalc]){
179
- config.topCalc = ColumnCalcs.calculations[def.topCalc];
180
- }else{
181
- console.warn("Column Calc Error - No such calculation found, ignoring: ", def.topCalc);
182
- }
183
- break;
184
-
185
- case "function":
186
- config.topCalc = def.topCalc;
187
- break;
188
-
189
- }
190
-
191
- if(config.topCalc){
192
- column.modules.columnCalcs = config;
193
- this.topCalcs.push(column);
194
-
195
- if(this.table.options.columnCalcs != "group"){
196
- this.initializeTopRow();
197
- }
198
- }
199
-
200
- }
201
-
202
- if(def.bottomCalc){
203
- switch(typeof def.bottomCalc){
204
- case "string":
205
- if(ColumnCalcs.calculations[def.bottomCalc]){
206
- config.botCalc = ColumnCalcs.calculations[def.bottomCalc];
207
- }else{
208
- console.warn("Column Calc Error - No such calculation found, ignoring: ", def.bottomCalc);
209
- }
210
- break;
211
-
212
- case "function":
213
- config.botCalc = def.bottomCalc;
214
- break;
215
-
216
- }
217
-
218
- if(config.botCalc){
219
- column.modules.columnCalcs = config;
220
- this.botCalcs.push(column);
221
-
222
- if(this.table.options.columnCalcs != "group"){
223
- this.initializeBottomRow();
224
- }
225
- }
226
- }
227
-
228
- }
229
-
230
- //dummy functions to handle being mock column manager
231
- registerColumnField(){}
232
-
233
- removeCalcs(){
234
- var changed = false;
235
-
236
- if(this.topInitialized){
237
- this.topInitialized = false;
238
- this.topElement.parentNode.removeChild(this.topElement);
239
- changed = true;
240
- }
241
-
242
- if(this.botInitialized){
243
- this.botInitialized = false;
244
- this.footerRemove(this.botElement);
245
- changed = true;
246
- }
247
-
248
- if(changed){
249
- this.table.rowManager.adjustTableSize();
250
- }
251
- }
252
-
253
- reinitializeCalcs(){
254
- if(this.topCalcs.length){
255
- this.initializeTopRow();
256
- }
257
-
258
- if(this.botCalcs.length){
259
- this.initializeBottomRow();
260
- }
261
- }
262
-
263
- initializeTopRow(){
264
- if(!this.topInitialized){
265
- this.table.columnManager.getContentsElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
266
- this.topInitialized = true;
267
- }
268
- }
269
-
270
- initializeBottomRow(){
271
- if(!this.botInitialized){
272
- this.footerPrepend(this.botElement);
273
- this.botInitialized = true;
274
- }
275
- }
276
-
277
- scrollHorizontal(left){
278
- if(this.botInitialized && this.botRow){
279
- this.botElement.scrollLeft = left;
280
- }
281
- }
282
-
283
- recalc(rows){
284
- var data, row;
285
-
286
- if(!this.blockCheck()){
287
- if(this.topInitialized || this.botInitialized){
288
- data = this.rowsToData(rows);
289
-
290
- if(this.topInitialized){
291
- if(this.topRow){
292
- this.topRow.deleteCells();
293
- }
294
-
295
- row = this.generateRow("top", data);
296
- this.topRow = row;
297
- while(this.topElement.firstChild) this.topElement.removeChild(this.topElement.firstChild);
298
- this.topElement.appendChild(row.getElement());
299
- row.initialize(true);
300
- }
301
-
302
- if(this.botInitialized){
303
- if(this.botRow){
304
- this.botRow.deleteCells();
305
- }
306
-
307
- row = this.generateRow("bottom", data);
308
- this.botRow = row;
309
- while(this.botElement.firstChild) this.botElement.removeChild(this.botElement.firstChild);
310
- this.botElement.appendChild(row.getElement());
311
- row.initialize(true);
312
- }
313
-
314
- this.table.rowManager.adjustTableSize();
315
-
316
- //set resizable handles
317
- if(this.table.modExists("frozenColumns")){
318
- this.table.modules.frozenColumns.layout();
319
- }
320
- }
321
- }
322
- }
323
-
324
- recalcRowGroup(row){
325
- this.recalcGroup(this.table.modules.groupRows.getRowGroup(row));
326
- }
327
-
328
- recalcAll(){
329
- if(this.topCalcs.length || this.botCalcs.length){
330
- if(this.table.options.columnCalcs !== "group"){
331
- this.recalcActiveRows();
332
- }
333
-
334
- if(this.table.options.groupBy && this.table.options.columnCalcs !== "table"){
335
-
336
- var groups = this.table.modules.groupRows.getChildGroups();
337
-
338
- groups.forEach((group) => {
339
- this.recalcGroup(group);
340
- });
341
- }
342
- }
343
- }
344
-
345
- recalcGroup(group){
346
- var data, rowData;
347
-
348
- if(!this.blockCheck()){
349
- if(group){
350
- if(group.calcs){
351
- if(group.calcs.bottom){
352
- data = this.rowsToData(group.rows);
353
- rowData = this.generateRowData("bottom", data);
354
-
355
- group.calcs.bottom.updateData(rowData);
356
- group.calcs.bottom.reinitialize();
357
- }
358
-
359
- if(group.calcs.top){
360
- data = this.rowsToData(group.rows);
361
- rowData = this.generateRowData("top", data);
362
-
363
- group.calcs.top.updateData(rowData);
364
- group.calcs.top.reinitialize();
365
- }
366
- }
367
- }
368
- }
369
- }
370
-
371
- //generate top stats row
372
- generateTopRow(rows){
373
- return this.generateRow("top", this.rowsToData(rows));
374
- }
375
- //generate bottom stats row
376
- generateBottomRow(rows){
377
- return this.generateRow("bottom", this.rowsToData(rows));
378
- }
379
-
380
- rowsToData(rows){
381
- var data = [];
382
-
383
- rows.forEach((row) => {
384
- data.push(row.getData());
385
-
386
- if(this.table.options.dataTree && this.table.options.dataTreeChildColumnCalcs){
387
- if(row.modules.dataTree && row.modules.dataTree.open){
388
- var children = this.rowsToData(this.table.modules.dataTree.getFilteredTreeChildren(row));
389
- data = data.concat(children);
390
- }
391
- }
392
- });
393
-
394
- return data;
395
- }
396
-
397
- //generate stats row
398
- generateRow(pos, data){
399
- var rowData = this.generateRowData(pos, data),
400
- row;
401
-
402
- if(this.table.modExists("mutator")){
403
- this.table.modules.mutator.disable();
404
- }
405
-
406
- row = new Row(rowData, this, "calc");
407
-
408
- if(this.table.modExists("mutator")){
409
- this.table.modules.mutator.enable();
410
- }
411
-
412
- row.getElement().classList.add("tabulator-calcs", "tabulator-calcs-" + pos);
413
-
414
- row.component = false;
415
-
416
- row.getComponent = () => {
417
- if(!row.component){
418
- row.component = new CalcComponent(row);
419
- }
420
-
421
- return row.component;
422
- };
423
-
424
- row.generateCells = () => {
425
-
426
- var cells = [];
427
-
428
- this.table.columnManager.columnsByIndex.forEach((column) => {
429
-
430
- //set field name of mock column
431
- this.genColumn.setField(column.getField());
432
- this.genColumn.hozAlign = column.hozAlign;
433
-
434
- if(column.definition[pos + "CalcFormatter"] && this.table.modExists("format")){
435
- this.genColumn.modules.format = {
436
- formatter: this.table.modules.format.getFormatter(column.definition[pos + "CalcFormatter"]),
437
- params: column.definition[pos + "CalcFormatterParams"] || {},
438
- };
439
- }else{
440
- this.genColumn.modules.format = {
441
- formatter: this.table.modules.format.getFormatter("plaintext"),
442
- params:{}
443
- };
444
- }
445
-
446
- //ensure css class definition is replicated to calculation cell
447
- this.genColumn.definition.cssClass = column.definition.cssClass;
448
-
449
- //generate cell and assign to correct column
450
- var cell = new Cell(this.genColumn, row);
451
- cell.getElement();
452
- cell.column = column;
453
- cell.setWidth();
454
-
455
- column.cells.push(cell);
456
- cells.push(cell);
457
-
458
- if(!column.visible){
459
- cell.hide();
460
- }
461
- });
462
-
463
- row.cells = cells;
464
- };
465
-
466
- return row;
467
- }
468
-
469
- //generate stats row
470
- generateRowData(pos, data){
471
- var rowData = {},
472
- calcs = pos == "top" ? this.topCalcs : this.botCalcs,
473
- type = pos == "top" ? "topCalc" : "botCalc",
474
- params, paramKey;
475
-
476
- calcs.forEach(function(column){
477
- var values = [];
478
-
479
- if(column.modules.columnCalcs && column.modules.columnCalcs[type]){
480
- data.forEach(function(item){
481
- values.push(column.getFieldValue(item));
482
- });
483
-
484
- paramKey = type + "Params";
485
- params = typeof column.modules.columnCalcs[paramKey] === "function" ? column.modules.columnCalcs[paramKey](values, data) : column.modules.columnCalcs[paramKey];
486
-
487
- column.setFieldValue(rowData, column.modules.columnCalcs[type](values, data, params));
488
- }
489
- });
490
-
491
- return rowData;
492
- }
493
-
494
- hasTopCalcs(){
495
- return !!(this.topCalcs.length);
496
- }
497
-
498
- hasBottomCalcs(){
499
- return !!(this.botCalcs.length);
500
- }
501
-
502
- //handle table redraw
503
- redraw(){
504
- if(this.topRow){
505
- this.topRow.normalizeHeight(true);
506
- }
507
- if(this.botRow){
508
- this.botRow.normalizeHeight(true);
509
- }
510
- }
511
-
512
- //return the calculated
513
- getResults(){
514
- var results = {},
515
- groups;
516
-
517
- if(this.table.options.groupBy && this.table.modExists("groupRows")){
518
- groups = this.table.modules.groupRows.getGroups(true);
519
-
520
- groups.forEach((group) => {
521
- results[group.getKey()] = this.getGroupResults(group);
522
- });
523
- }else{
524
- results = {
525
- top: this.topRow ? this.topRow.getData() : {},
526
- bottom: this.botRow ? this.botRow.getData() : {},
527
- };
528
- }
529
-
530
- return results;
531
- }
532
-
533
- //get results from a group
534
- getGroupResults(group){
535
- var groupObj = group._getSelf(),
536
- subGroups = group.getSubGroups(),
537
- subGroupResults = {},
538
- results = {};
539
-
540
- subGroups.forEach((subgroup) => {
541
- subGroupResults[subgroup.getKey()] = this.getGroupResults(subgroup);
542
- });
543
-
544
- results = {
545
- top: groupObj.calcs.top ? groupObj.calcs.top.getData() : {},
546
- bottom: groupObj.calcs.bottom ? groupObj.calcs.bottom.getData() : {},
547
- groups: subGroupResults,
548
- };
549
-
550
- return results;
551
- }
552
-
553
- adjustForScrollbar(width){
554
- if(this.botRow){
555
- if(this.table.rtl){
556
- this.botElement.style.paddingLeft = width + "px";
557
- }else{
558
- this.botElement.style.paddingRight = width + "px";
559
- }
560
- }
561
- }
562
- }
563
-
564
- ColumnCalcs.moduleName = "columnCalcs";
565
-
566
- //load defaults
567
- ColumnCalcs.calculations = defaultCalculations;
568
-
1
+ import Module from '../../core/Module.js';
2
+
3
+ import CalcComponent from './CalcComponent.js';
4
+
5
+ import Cell from '../../core/cell/Cell.js';
6
+ import Column from '../../core/column/Column.js';
7
+ import Row from '../../core/row/Row.js';
8
+
9
+ import defaultCalculations from './defaults/calculations.js';
10
+
11
+ class ColumnCalcs extends Module{
12
+
13
+ constructor(table){
14
+ super(table);
15
+
16
+ this.topCalcs = [];
17
+ this.botCalcs = [];
18
+ this.genColumn = false;
19
+ this.topElement = this.createElement();
20
+ this.botElement = this.createElement();
21
+ this.topRow = false;
22
+ this.botRow = false;
23
+ this.topInitialized = false;
24
+ this.botInitialized = false;
25
+
26
+ this.blocked = false;
27
+ this.recalcAfterBlock = false;
28
+
29
+ this.registerTableOption("columnCalcs", true);
30
+
31
+ this.registerColumnOption("topCalc");
32
+ this.registerColumnOption("topCalcParams");
33
+ this.registerColumnOption("topCalcFormatter");
34
+ this.registerColumnOption("topCalcFormatterParams");
35
+ this.registerColumnOption("bottomCalc");
36
+ this.registerColumnOption("bottomCalcParams");
37
+ this.registerColumnOption("bottomCalcFormatter");
38
+ this.registerColumnOption("bottomCalcFormatterParams");
39
+ }
40
+
41
+ createElement (){
42
+ var el = document.createElement("div");
43
+ el.classList.add("tabulator-calcs-holder");
44
+ return el;
45
+ }
46
+
47
+ initialize(){
48
+ this.genColumn = new Column({field:"value"}, this);
49
+
50
+ this.subscribe("cell-value-changed", this.cellValueChanged.bind(this));
51
+ this.subscribe("column-init", this.initializeColumnCheck.bind(this));
52
+ this.subscribe("row-deleted", this.rowsUpdated.bind(this));
53
+ this.subscribe("scroll-horizontal", this.scrollHorizontal.bind(this));
54
+ this.subscribe("row-added", this.rowsUpdated.bind(this));
55
+ this.subscribe("column-moved", this.recalcActiveRows.bind(this));
56
+ this.subscribe("column-add", this.recalcActiveRows.bind(this));
57
+ this.subscribe("data-refreshed", this.recalcActiveRowsRefresh.bind(this));
58
+ this.subscribe("table-redraw", this.tableRedraw.bind(this));
59
+ this.subscribe("rows-visible", this.visibleRows.bind(this));
60
+ this.subscribe("scrollbar-vertical", this.adjustForScrollbar.bind(this));
61
+
62
+ this.subscribe("redraw-blocked", this.blockRedraw.bind(this));
63
+ this.subscribe("redraw-restored", this.restoreRedraw.bind(this));
64
+
65
+ this.subscribe("table-redrawing", this.resizeHolderWidth.bind(this));
66
+ this.subscribe("column-resized", this.resizeHolderWidth.bind(this));
67
+ this.subscribe("column-show", this.resizeHolderWidth.bind(this));
68
+ this.subscribe("column-hide", this.resizeHolderWidth.bind(this));
69
+
70
+ this.registerTableFunction("getCalcResults", this.getResults.bind(this));
71
+ this.registerTableFunction("recalc", this.userRecalc.bind(this));
72
+
73
+
74
+ this.resizeHolderWidth();
75
+ }
76
+
77
+ resizeHolderWidth(){
78
+ this.topElement.style.minWidth = this.table.columnManager.headersElement.offsetWidth + "px";
79
+ }
80
+
81
+
82
+ tableRedraw(force){
83
+ this.recalc(this.table.rowManager.activeRows);
84
+
85
+ if(force){
86
+ this.redraw();
87
+ }
88
+ }
89
+
90
+ blockRedraw(){
91
+ this.blocked = true;
92
+ this.recalcAfterBlock = false;
93
+ }
94
+
95
+
96
+ restoreRedraw(){
97
+ this.blocked = false;
98
+
99
+ if(this.recalcAfterBlock){
100
+ this.recalcAfterBlock = false;
101
+ this.recalcActiveRowsRefresh();
102
+ }
103
+ }
104
+
105
+ ///////////////////////////////////
106
+ ///////// Table Functions /////////
107
+ ///////////////////////////////////
108
+ userRecalc(){
109
+ this.recalc(this.table.rowManager.activeRows);
110
+ }
111
+
112
+ ///////////////////////////////////
113
+ ///////// Internal Logic //////////
114
+ ///////////////////////////////////
115
+
116
+ blockCheck(){
117
+ if(this.blocked){
118
+ this.recalcAfterBlock = true;
119
+ }
120
+
121
+ return this.blocked;
122
+ }
123
+
124
+ visibleRows(viewable, rows){
125
+ if(this.topRow){
126
+ rows.unshift(this.topRow);
127
+ }
128
+
129
+ if(this.botRow){
130
+ rows.push(this.botRow);
131
+ }
132
+
133
+ return rows;
134
+ }
135
+
136
+ rowsUpdated(row){
137
+ if(this.table.options.groupBy){
138
+ this.recalcRowGroup(row);
139
+ }else{
140
+ this.recalcActiveRows();
141
+ }
142
+ }
143
+
144
+ recalcActiveRowsRefresh(){
145
+ if(this.table.options.groupBy && this.table.options.dataTreeStartExpanded && this.table.options.dataTree){
146
+ this.recalcAll();
147
+ }else{
148
+ this.recalcActiveRows();
149
+ }
150
+ }
151
+
152
+ recalcActiveRows(){
153
+ this.recalc(this.table.rowManager.activeRows);
154
+ }
155
+
156
+ cellValueChanged(cell){
157
+ if(cell.column.definition.topCalc || cell.column.definition.bottomCalc){
158
+ if(this.table.options.groupBy){
159
+ if(this.table.options.columnCalcs == "table" || this.table.options.columnCalcs == "both"){
160
+ this.recalcActiveRows();
161
+ }
162
+
163
+ if(this.table.options.columnCalcs != "table"){
164
+ this.recalcRowGroup(cell.row);
165
+ }
166
+ }else{
167
+ this.recalcActiveRows();
168
+ }
169
+ }
170
+ }
171
+
172
+ initializeColumnCheck(column){
173
+ if(column.definition.topCalc || column.definition.bottomCalc){
174
+ this.initializeColumn(column);
175
+ }
176
+ }
177
+
178
+ //initialize column calcs
179
+ initializeColumn(column){
180
+ var def = column.definition;
181
+
182
+ var config = {
183
+ topCalcParams:def.topCalcParams || {},
184
+ botCalcParams:def.bottomCalcParams || {},
185
+ };
186
+
187
+ if(def.topCalc){
188
+
189
+ switch(typeof def.topCalc){
190
+ case "string":
191
+ if(ColumnCalcs.calculations[def.topCalc]){
192
+ config.topCalc = ColumnCalcs.calculations[def.topCalc];
193
+ }else{
194
+ console.warn("Column Calc Error - No such calculation found, ignoring: ", def.topCalc);
195
+ }
196
+ break;
197
+
198
+ case "function":
199
+ config.topCalc = def.topCalc;
200
+ break;
201
+
202
+ }
203
+
204
+ if(config.topCalc){
205
+ column.modules.columnCalcs = config;
206
+ this.topCalcs.push(column);
207
+
208
+ if(this.table.options.columnCalcs != "group"){
209
+ this.initializeTopRow();
210
+ }
211
+ }
212
+
213
+ }
214
+
215
+ if(def.bottomCalc){
216
+ switch(typeof def.bottomCalc){
217
+ case "string":
218
+ if(ColumnCalcs.calculations[def.bottomCalc]){
219
+ config.botCalc = ColumnCalcs.calculations[def.bottomCalc];
220
+ }else{
221
+ console.warn("Column Calc Error - No such calculation found, ignoring: ", def.bottomCalc);
222
+ }
223
+ break;
224
+
225
+ case "function":
226
+ config.botCalc = def.bottomCalc;
227
+ break;
228
+
229
+ }
230
+
231
+ if(config.botCalc){
232
+ column.modules.columnCalcs = config;
233
+ this.botCalcs.push(column);
234
+
235
+ if(this.table.options.columnCalcs != "group"){
236
+ this.initializeBottomRow();
237
+ }
238
+ }
239
+ }
240
+
241
+ }
242
+
243
+ //dummy functions to handle being mock column manager
244
+ registerColumnField(){}
245
+
246
+ removeCalcs(){
247
+ var changed = false;
248
+
249
+ if(this.topInitialized){
250
+ this.topInitialized = false;
251
+ this.topElement.parentNode.removeChild(this.topElement);
252
+ changed = true;
253
+ }
254
+
255
+ if(this.botInitialized){
256
+ this.botInitialized = false;
257
+ this.footerRemove(this.botElement);
258
+ changed = true;
259
+ }
260
+
261
+ if(changed){
262
+ this.table.rowManager.adjustTableSize();
263
+ }
264
+ }
265
+
266
+ reinitializeCalcs(){
267
+ if(this.topCalcs.length){
268
+ this.initializeTopRow();
269
+ }
270
+
271
+ if(this.botCalcs.length){
272
+ this.initializeBottomRow();
273
+ }
274
+ }
275
+
276
+ initializeTopRow(){
277
+ if(!this.topInitialized){
278
+ this.table.columnManager.getContentsElement().insertBefore(this.topElement, this.table.columnManager.headersElement.nextSibling);
279
+ this.topInitialized = true;
280
+ }
281
+ }
282
+
283
+ initializeBottomRow(){
284
+ if(!this.botInitialized){
285
+ this.footerPrepend(this.botElement);
286
+ this.botInitialized = true;
287
+ }
288
+ }
289
+
290
+ scrollHorizontal(left){
291
+ if(this.botInitialized && this.botRow){
292
+ this.botElement.scrollLeft = left;
293
+ }
294
+ }
295
+
296
+ recalc(rows){
297
+ var data, row;
298
+
299
+ if(!this.blockCheck()){
300
+ if(this.topInitialized || this.botInitialized){
301
+ data = this.rowsToData(rows);
302
+
303
+ if(this.topInitialized){
304
+ if(this.topRow){
305
+ this.topRow.deleteCells();
306
+ }
307
+
308
+ row = this.generateRow("top", data);
309
+ this.topRow = row;
310
+ while(this.topElement.firstChild) this.topElement.removeChild(this.topElement.firstChild);
311
+ this.topElement.appendChild(row.getElement());
312
+ row.initialize(true);
313
+ }
314
+
315
+ if(this.botInitialized){
316
+ if(this.botRow){
317
+ this.botRow.deleteCells();
318
+ }
319
+
320
+ row = this.generateRow("bottom", data);
321
+ this.botRow = row;
322
+ while(this.botElement.firstChild) this.botElement.removeChild(this.botElement.firstChild);
323
+ this.botElement.appendChild(row.getElement());
324
+ row.initialize(true);
325
+ }
326
+
327
+ this.table.rowManager.adjustTableSize();
328
+
329
+ //set resizable handles
330
+ if(this.table.modExists("frozenColumns")){
331
+ this.table.modules.frozenColumns.layout();
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ recalcRowGroup(row){
338
+ this.recalcGroup(this.table.modules.groupRows.getRowGroup(row));
339
+ }
340
+
341
+ recalcAll(){
342
+ if(this.topCalcs.length || this.botCalcs.length){
343
+ if(this.table.options.columnCalcs !== "group"){
344
+ this.recalcActiveRows();
345
+ }
346
+
347
+ if(this.table.options.groupBy && this.table.options.columnCalcs !== "table"){
348
+
349
+ var groups = this.table.modules.groupRows.getChildGroups();
350
+
351
+ groups.forEach((group) => {
352
+ this.recalcGroup(group);
353
+ });
354
+ }
355
+ }
356
+ }
357
+
358
+ recalcGroup(group){
359
+ var data, rowData;
360
+
361
+ if(!this.blockCheck()){
362
+ if(group){
363
+ if(group.calcs){
364
+ if(group.calcs.bottom){
365
+ data = this.rowsToData(group.rows);
366
+ rowData = this.generateRowData("bottom", data);
367
+
368
+ group.calcs.bottom.updateData(rowData);
369
+ group.calcs.bottom.reinitialize();
370
+ }
371
+
372
+ if(group.calcs.top){
373
+ data = this.rowsToData(group.rows);
374
+ rowData = this.generateRowData("top", data);
375
+
376
+ group.calcs.top.updateData(rowData);
377
+ group.calcs.top.reinitialize();
378
+ }
379
+ }
380
+ }
381
+ }
382
+ }
383
+
384
+ //generate top stats row
385
+ generateTopRow(rows){
386
+ return this.generateRow("top", this.rowsToData(rows));
387
+ }
388
+ //generate bottom stats row
389
+ generateBottomRow(rows){
390
+ return this.generateRow("bottom", this.rowsToData(rows));
391
+ }
392
+
393
+ rowsToData(rows){
394
+ var data = [];
395
+
396
+ rows.forEach((row) => {
397
+ data.push(row.getData());
398
+
399
+ if(this.table.options.dataTree && this.table.options.dataTreeChildColumnCalcs){
400
+ if(row.modules.dataTree && row.modules.dataTree.open){
401
+ var children = this.rowsToData(this.table.modules.dataTree.getFilteredTreeChildren(row));
402
+ data = data.concat(children);
403
+ }
404
+ }
405
+ });
406
+
407
+ return data;
408
+ }
409
+
410
+ //generate stats row
411
+ generateRow(pos, data){
412
+ var rowData = this.generateRowData(pos, data),
413
+ row;
414
+
415
+ if(this.table.modExists("mutator")){
416
+ this.table.modules.mutator.disable();
417
+ }
418
+
419
+ row = new Row(rowData, this, "calc");
420
+
421
+ if(this.table.modExists("mutator")){
422
+ this.table.modules.mutator.enable();
423
+ }
424
+
425
+ row.getElement().classList.add("tabulator-calcs", "tabulator-calcs-" + pos);
426
+
427
+ row.component = false;
428
+
429
+ row.getComponent = () => {
430
+ if(!row.component){
431
+ row.component = new CalcComponent(row);
432
+ }
433
+
434
+ return row.component;
435
+ };
436
+
437
+ row.generateCells = () => {
438
+
439
+ var cells = [];
440
+
441
+ this.table.columnManager.columnsByIndex.forEach((column) => {
442
+
443
+ //set field name of mock column
444
+ this.genColumn.setField(column.getField());
445
+ this.genColumn.hozAlign = column.hozAlign;
446
+
447
+ if(column.definition[pos + "CalcFormatter"] && this.table.modExists("format")){
448
+ this.genColumn.modules.format = {
449
+ formatter: this.table.modules.format.getFormatter(column.definition[pos + "CalcFormatter"]),
450
+ params: column.definition[pos + "CalcFormatterParams"] || {},
451
+ };
452
+ }else{
453
+ this.genColumn.modules.format = {
454
+ formatter: this.table.modules.format.getFormatter("plaintext"),
455
+ params:{}
456
+ };
457
+ }
458
+
459
+ //ensure css class definition is replicated to calculation cell
460
+ this.genColumn.definition.cssClass = column.definition.cssClass;
461
+
462
+ //generate cell and assign to correct column
463
+ var cell = new Cell(this.genColumn, row);
464
+ cell.getElement();
465
+ cell.column = column;
466
+ cell.setWidth();
467
+
468
+ column.cells.push(cell);
469
+ cells.push(cell);
470
+
471
+ if(!column.visible){
472
+ cell.hide();
473
+ }
474
+ });
475
+
476
+ row.cells = cells;
477
+ };
478
+
479
+ return row;
480
+ }
481
+
482
+ //generate stats row
483
+ generateRowData(pos, data){
484
+ var rowData = {},
485
+ calcs = pos == "top" ? this.topCalcs : this.botCalcs,
486
+ type = pos == "top" ? "topCalc" : "botCalc",
487
+ params, paramKey;
488
+
489
+ calcs.forEach(function(column){
490
+ var values = [];
491
+
492
+ if(column.modules.columnCalcs && column.modules.columnCalcs[type]){
493
+ data.forEach(function(item){
494
+ values.push(column.getFieldValue(item));
495
+ });
496
+
497
+ paramKey = type + "Params";
498
+ params = typeof column.modules.columnCalcs[paramKey] === "function" ? column.modules.columnCalcs[paramKey](values, data) : column.modules.columnCalcs[paramKey];
499
+
500
+ column.setFieldValue(rowData, column.modules.columnCalcs[type](values, data, params));
501
+ }
502
+ });
503
+
504
+ return rowData;
505
+ }
506
+
507
+ hasTopCalcs(){
508
+ return !!(this.topCalcs.length);
509
+ }
510
+
511
+ hasBottomCalcs(){
512
+ return !!(this.botCalcs.length);
513
+ }
514
+
515
+ //handle table redraw
516
+ redraw(){
517
+ if(this.topRow){
518
+ this.topRow.normalizeHeight(true);
519
+ }
520
+ if(this.botRow){
521
+ this.botRow.normalizeHeight(true);
522
+ }
523
+ }
524
+
525
+ //return the calculated
526
+ getResults(){
527
+ var results = {},
528
+ groups;
529
+
530
+ if(this.table.options.groupBy && this.table.modExists("groupRows")){
531
+ groups = this.table.modules.groupRows.getGroups(true);
532
+
533
+ groups.forEach((group) => {
534
+ results[group.getKey()] = this.getGroupResults(group);
535
+ });
536
+ }else{
537
+ results = {
538
+ top: this.topRow ? this.topRow.getData() : {},
539
+ bottom: this.botRow ? this.botRow.getData() : {},
540
+ };
541
+ }
542
+
543
+ return results;
544
+ }
545
+
546
+ //get results from a group
547
+ getGroupResults(group){
548
+ var groupObj = group._getSelf(),
549
+ subGroups = group.getSubGroups(),
550
+ subGroupResults = {},
551
+ results = {};
552
+
553
+ subGroups.forEach((subgroup) => {
554
+ subGroupResults[subgroup.getKey()] = this.getGroupResults(subgroup);
555
+ });
556
+
557
+ results = {
558
+ top: groupObj.calcs.top ? groupObj.calcs.top.getData() : {},
559
+ bottom: groupObj.calcs.bottom ? groupObj.calcs.bottom.getData() : {},
560
+ groups: subGroupResults,
561
+ };
562
+
563
+ return results;
564
+ }
565
+
566
+ adjustForScrollbar(width){
567
+ if(this.botRow){
568
+ if(this.table.rtl){
569
+ this.botElement.style.paddingLeft = width + "px";
570
+ }else{
571
+ this.botElement.style.paddingRight = width + "px";
572
+ }
573
+ }
574
+ }
575
+ }
576
+
577
+ ColumnCalcs.moduleName = "columnCalcs";
578
+
579
+ //load defaults
580
+ ColumnCalcs.calculations = defaultCalculations;
581
+
569
582
  export default ColumnCalcs;