tabulator-tables 5.4.2 → 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.
- package/.babelrc.json +3 -3
- package/.editorconfig +6 -6
- package/.eslintignore +3 -3
- package/.eslintrc.js +28 -28
- package/.github/ISSUE_TEMPLATE/bug_report.md +58 -58
- package/.github/ISSUE_TEMPLATE/documentation.md +14 -14
- package/.github/ISSUE_TEMPLATE/feature_request.md +24 -24
- package/.github/ISSUE_TEMPLATE/question.md +12 -12
- package/.github/workflows/bad-files-check.yml +39 -39
- package/.github/workflows/lint-and-test.yml +30 -30
- package/CODE_OF_CONDUCT.md +46 -46
- package/CONTRIBUTING.md +22 -22
- package/LICENSE +20 -20
- package/README.md +76 -76
- package/bower.json +40 -40
- package/build/Bundler.js +185 -185
- package/build/rollup.js +6 -6
- package/dist/css/tabulator.css +1 -5
- package/dist/css/tabulator.css.map +1 -1
- package/dist/css/tabulator.min.css +1 -1
- package/dist/css/tabulator.min.css.map +1 -1
- package/dist/css/tabulator_bootstrap3.css +1 -5
- package/dist/css/tabulator_bootstrap3.css.map +1 -1
- package/dist/css/tabulator_bootstrap3.min.css +1 -1
- package/dist/css/tabulator_bootstrap3.min.css.map +1 -1
- package/dist/css/tabulator_bootstrap4.css +1 -5
- package/dist/css/tabulator_bootstrap4.css.map +1 -1
- package/dist/css/tabulator_bootstrap4.min.css +1 -1
- package/dist/css/tabulator_bootstrap4.min.css.map +1 -1
- package/dist/css/tabulator_bootstrap5.css +1 -5
- package/dist/css/tabulator_bootstrap5.css.map +1 -1
- package/dist/css/tabulator_bootstrap5.min.css +1 -1
- package/dist/css/tabulator_bootstrap5.min.css.map +1 -1
- package/dist/css/tabulator_bulma.css +1 -5
- package/dist/css/tabulator_bulma.css.map +1 -1
- package/dist/css/tabulator_bulma.min.css +1 -1
- package/dist/css/tabulator_bulma.min.css.map +1 -1
- package/dist/css/tabulator_materialize.css +1 -5
- package/dist/css/tabulator_materialize.css.map +1 -1
- package/dist/css/tabulator_materialize.min.css +1 -1
- package/dist/css/tabulator_materialize.min.css.map +1 -1
- package/dist/css/tabulator_midnight.css +1 -5
- package/dist/css/tabulator_midnight.css.map +1 -1
- package/dist/css/tabulator_midnight.min.css +1 -1
- package/dist/css/tabulator_midnight.min.css.map +1 -1
- package/dist/css/tabulator_modern.css +1 -5
- package/dist/css/tabulator_modern.css.map +1 -1
- package/dist/css/tabulator_modern.min.css +1 -1
- package/dist/css/tabulator_modern.min.css.map +1 -1
- package/dist/css/tabulator_semanticui.css +103 -107
- package/dist/css/tabulator_semanticui.css.map +1 -1
- package/dist/css/tabulator_semanticui.min.css +1 -1
- package/dist/css/tabulator_semanticui.min.css.map +1 -1
- package/dist/css/tabulator_simple.css +1 -5
- package/dist/css/tabulator_simple.css.map +1 -1
- package/dist/css/tabulator_simple.min.css +1 -1
- package/dist/css/tabulator_simple.min.css.map +1 -1
- package/dist/css/tabulator_site.css +1 -5
- package/dist/css/tabulator_site.css.map +1 -1
- package/dist/css/tabulator_site.min.css +1 -1
- package/dist/css/tabulator_site.min.css.map +1 -1
- package/dist/js/jquery_wrapper.js +55 -55
- package/dist/js/tabulator.js +25847 -25653
- package/dist/js/tabulator.js.map +1 -1
- package/dist/js/tabulator.min.js +2 -2
- package/dist/js/tabulator.min.js.map +1 -1
- package/dist/js/tabulator_esm.js +25926 -25732
- package/dist/js/tabulator_esm.js.map +1 -1
- package/dist/js/tabulator_esm.min.js +2 -2
- package/dist/js/tabulator_esm.min.js.map +1 -1
- package/package.json +65 -65
- package/src/js/builds/esm.js +14 -14
- package/src/js/builds/jquery_wrapper.js +55 -55
- package/src/js/core/ColumnManager.js +730 -730
- package/src/js/core/CoreFeature.js +138 -138
- package/src/js/core/FooterManager.js +101 -101
- package/src/js/core/Module.js +141 -141
- package/src/js/core/RowManager.js +1112 -1082
- package/src/js/core/Tabulator.js +895 -893
- package/src/js/core/TabulatorFull.js +10 -10
- package/src/js/core/cell/Cell.js +295 -295
- package/src/js/core/cell/CellComponent.js +76 -76
- package/src/js/core/column/Column.js +949 -949
- package/src/js/core/column/ColumnComponent.js +152 -152
- package/src/js/core/column/defaults/options.js +17 -17
- package/src/js/core/defaults/options.js +65 -65
- package/src/js/core/modules/core.js +2 -2
- package/src/js/core/modules/optional.js +34 -34
- package/src/js/core/rendering/Renderer.js +203 -203
- package/src/js/core/rendering/renderers/BasicHorizontal.js +19 -19
- package/src/js/core/rendering/renderers/BasicVertical.js +79 -78
- package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +577 -577
- package/src/js/core/rendering/renderers/VirtualDomVertical.js +579 -579
- package/src/js/core/row/PseudoRow.js +44 -44
- package/src/js/core/row/Row.js +457 -457
- package/src/js/core/row/RowComponent.js +93 -93
- package/src/js/core/tools/Alert.js +61 -61
- package/src/js/core/tools/ComponentFunctionBinder.js +32 -32
- package/src/js/core/tools/DataLoader.js +119 -119
- package/src/js/core/tools/DeprecationAdvisor.js +46 -46
- package/src/js/core/tools/ExternalEventBus.js +104 -104
- package/src/js/core/tools/Helpers.js +46 -46
- package/src/js/core/tools/InteractionMonitor.js +321 -321
- package/src/js/core/tools/InternalEventBus.js +161 -161
- package/src/js/core/tools/ModuleBinder.js +104 -104
- package/src/js/core/tools/OptionsList.js +44 -40
- package/src/js/core/tools/Popup.js +304 -304
- package/src/js/core/tools/TableRegistry.js +61 -61
- package/src/js/modules/Accessor/Accessor.js +115 -115
- package/src/js/modules/Ajax/Ajax.js +143 -143
- package/src/js/modules/Ajax/defaults/config.js +2 -2
- package/src/js/modules/Ajax/defaults/contentTypeFormatters.js +44 -44
- package/src/js/modules/Ajax/defaults/loaderPromise.js +86 -86
- package/src/js/modules/Ajax/defaults/urlGenerator.js +43 -43
- package/src/js/modules/Clipboard/Clipboard.js +279 -279
- package/src/js/modules/Clipboard/defaults/pasteActions.js +10 -10
- package/src/js/modules/Clipboard/defaults/pasteParsers.js +74 -74
- package/src/js/modules/ColumnCalcs/CalcComponent.js +47 -47
- package/src/js/modules/ColumnCalcs/ColumnCalcs.js +581 -568
- package/src/js/modules/ColumnCalcs/defaults/calculations.js +85 -85
- package/src/js/modules/Comms/Comms.js +51 -51
- package/src/js/modules/DataTree/DataTree.js +603 -603
- package/src/js/modules/Download/Download.js +148 -148
- package/src/js/modules/Download/defaults/downloaders/csv.js +61 -61
- package/src/js/modules/Download/defaults/downloaders/html.js +4 -4
- package/src/js/modules/Download/defaults/downloaders/json.js +33 -33
- package/src/js/modules/Download/defaults/downloaders/jsonLines.js +31 -31
- package/src/js/modules/Download/defaults/downloaders/pdf.js +111 -111
- package/src/js/modules/Download/defaults/downloaders/xlsx.js +98 -98
- package/src/js/modules/Download/defaults/downloaders.js +14 -14
- package/src/js/modules/Edit/Edit.js +735 -736
- package/src/js/modules/Edit/List.js +1037 -1033
- package/src/js/modules/Edit/defaults/editors/autocomplete.js +11 -11
- package/src/js/modules/Edit/defaults/editors/date.js +138 -110
- package/src/js/modules/Edit/defaults/editors/datetime.js +125 -97
- package/src/js/modules/Edit/defaults/editors/input.js +76 -74
- package/src/js/modules/Edit/defaults/editors/list.js +6 -6
- package/src/js/modules/Edit/defaults/editors/number.js +109 -107
- package/src/js/modules/Edit/defaults/editors/progress.js +126 -126
- package/src/js/modules/Edit/defaults/editors/range.js +80 -78
- package/src/js/modules/Edit/defaults/editors/select.js +9 -9
- package/src/js/modules/Edit/defaults/editors/star.js +145 -145
- package/src/js/modules/Edit/defaults/editors/textarea.js +122 -120
- package/src/js/modules/Edit/defaults/editors/tickCross.js +94 -96
- package/src/js/modules/Edit/defaults/editors/time.js +126 -98
- package/src/js/modules/Edit/defaults/editors.js +28 -28
- package/src/js/modules/Edit/inputMask.js +73 -73
- package/src/js/modules/Export/Export.js +623 -617
- package/src/js/modules/Export/ExportColumn.js +10 -10
- package/src/js/modules/Export/ExportRow.js +9 -9
- package/src/js/modules/Filter/Filter.js +892 -889
- package/src/js/modules/Filter/defaults/filters.js +107 -107
- package/src/js/modules/Format/Format.js +212 -212
- package/src/js/modules/Format/defaults/formatters/buttonCross.js +2 -2
- package/src/js/modules/Format/defaults/formatters/buttonTick.js +2 -2
- package/src/js/modules/Format/defaults/formatters/color.js +3 -3
- package/src/js/modules/Format/defaults/formatters/datetime.js +36 -36
- package/src/js/modules/Format/defaults/formatters/datetimediff.js +40 -40
- package/src/js/modules/Format/defaults/formatters/handle.js +3 -3
- package/src/js/modules/Format/defaults/formatters/html.js +2 -2
- package/src/js/modules/Format/defaults/formatters/image.js +39 -39
- package/src/js/modules/Format/defaults/formatters/link.js +77 -77
- package/src/js/modules/Format/defaults/formatters/lookup.js +9 -9
- package/src/js/modules/Format/defaults/formatters/money.js +36 -36
- package/src/js/modules/Format/defaults/formatters/plaintext.js +2 -2
- package/src/js/modules/Format/defaults/formatters/progress.js +132 -132
- package/src/js/modules/Format/defaults/formatters/responsiveCollapse.js +43 -43
- package/src/js/modules/Format/defaults/formatters/rowSelection.js +59 -59
- package/src/js/modules/Format/defaults/formatters/rownum.js +9 -9
- package/src/js/modules/Format/defaults/formatters/star.js +37 -37
- package/src/js/modules/Format/defaults/formatters/textarea.js +3 -3
- package/src/js/modules/Format/defaults/formatters/tickCross.js +21 -21
- package/src/js/modules/Format/defaults/formatters/traffic.js +46 -46
- package/src/js/modules/Format/defaults/formatters.js +42 -42
- package/src/js/modules/FrozenColumns/FrozenColumns.js +299 -299
- package/src/js/modules/FrozenRows/FrozenRows.js +169 -159
- package/src/js/modules/GroupRows/Group.js +597 -595
- package/src/js/modules/GroupRows/GroupComponent.js +66 -66
- package/src/js/modules/GroupRows/GroupRows.js +639 -623
- package/src/js/modules/History/History.js +171 -171
- package/src/js/modules/History/defaults/redoers.js +24 -24
- package/src/js/modules/History/defaults/undoers.js +24 -24
- package/src/js/modules/HtmlTableImport/HtmlTableImport.js +181 -181
- package/src/js/modules/Import/Import.js +193 -193
- package/src/js/modules/Import/defaults/importers/array.js +4 -4
- package/src/js/modules/Import/defaults/importers/csv.js +62 -62
- package/src/js/modules/Import/defaults/importers/json.js +7 -7
- package/src/js/modules/Import/defaults/importers.js +8 -8
- package/src/js/modules/Interaction/Interaction.js +325 -325
- package/src/js/modules/Keybindings/Keybindings.js +172 -172
- package/src/js/modules/Keybindings/defaults/actions.js +118 -118
- package/src/js/modules/Keybindings/defaults/bindings.js +12 -12
- package/src/js/modules/Layout/Layout.js +49 -49
- package/src/js/modules/Layout/defaults/modes/fitColumns.js +171 -171
- package/src/js/modules/Layout/defaults/modes/fitData.js +9 -9
- package/src/js/modules/Layout/defaults/modes/fitDataGeneral.js +9 -9
- package/src/js/modules/Layout/defaults/modes/fitDataStretch.js +39 -39
- package/src/js/modules/Layout/defaults/modes.js +11 -11
- package/src/js/modules/Localize/Localize.js +185 -194
- package/src/js/modules/Localize/defaults/langs.js +36 -36
- package/src/js/modules/Menu/Menu.js +302 -302
- package/src/js/modules/MoveColumns/MoveColumns.js +299 -299
- package/src/js/modules/MoveRows/MoveRows.js +635 -635
- package/src/js/modules/Mutator/Mutator.js +161 -161
- package/src/js/modules/Page/Page.js +881 -881
- package/src/js/modules/Page/defaults/pageCounters/pages.js +32 -32
- package/src/js/modules/Page/defaults/pageCounters/rows.js +39 -39
- package/src/js/modules/Page/defaults/pageCounters.js +7 -7
- package/src/js/modules/Persistence/Persistence.js +458 -458
- package/src/js/modules/Persistence/defaults/readers.js +29 -29
- package/src/js/modules/Persistence/defaults/writers.js +12 -12
- package/src/js/modules/Popup/Popup.js +231 -231
- package/src/js/modules/Print/Print.js +137 -124
- package/src/js/modules/ReactiveData/ReactiveData.js +408 -408
- package/src/js/modules/ResizeColumns/ResizeColumns.js +309 -309
- package/src/js/modules/ResizeRows/ResizeRows.js +111 -111
- package/src/js/modules/ResizeTable/ResizeTable.js +159 -159
- package/src/js/modules/ResponsiveLayout/ResponsiveLayout.js +345 -345
- package/src/js/modules/SelectRow/SelectRow.js +446 -436
- package/src/js/modules/Sort/Sort.js +470 -470
- package/src/js/modules/Sort/defaults/sorters/alphanum.js +43 -43
- package/src/js/modules/Sort/defaults/sorters/array.js +53 -53
- package/src/js/modules/Sort/defaults/sorters/boolean.js +6 -6
- package/src/js/modules/Sort/defaults/sorters/date.js +9 -9
- package/src/js/modules/Sort/defaults/sorters/datetime.js +43 -43
- package/src/js/modules/Sort/defaults/sorters/exists.js +6 -6
- package/src/js/modules/Sort/defaults/sorters/number.js +39 -39
- package/src/js/modules/Sort/defaults/sorters/string.js +33 -33
- package/src/js/modules/Sort/defaults/sorters/time.js +9 -9
- package/src/js/modules/Sort/defaults/sorters.js +20 -20
- package/src/js/modules/Tooltip/Tooltip.js +130 -130
- package/src/js/modules/Validate/Validate.js +305 -305
- package/src/js/modules/Validate/defaults/validators.js +138 -138
- package/src/scss/tabulator.scss +1464 -1466
- package/src/scss/themes/bootstrap/functions4.scss +118 -118
- package/src/scss/themes/bootstrap/functions5.scss +302 -302
- package/src/scss/themes/bootstrap/tabulator_bootstrap3.scss +284 -284
- package/src/scss/themes/bootstrap/tabulator_bootstrap4.scss +544 -544
- package/src/scss/themes/bootstrap/tabulator_bootstrap5.scss +574 -574
- package/src/scss/themes/bootstrap/variables3.scss +870 -870
- package/src/scss/themes/bootstrap/variables4.scss +930 -930
- package/src/scss/themes/bootstrap/variables5.scss +1641 -1641
- package/src/scss/themes/bulma/tabulator_bulma.scss +252 -252
- package/src/scss/themes/bulma/variables.scss +197 -197
- package/src/scss/themes/materialize/tabulator_materialize.scss +265 -265
- package/src/scss/themes/materialize/variables.scss +70 -70
- package/src/scss/themes/semanticui/tabulator_semanticui.scss +561 -561
- package/src/scss/themes/semanticui/variables.scss +839 -839
- package/src/scss/themes/semanticui/variables_table.scss +247 -247
- package/src/scss/themes/tabulator_midnight.scss +158 -158
- package/src/scss/themes/tabulator_modern.scss +231 -231
- package/src/scss/themes/tabulator_simple.scss +102 -102
- 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.
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if(
|
|
272
|
-
this.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
this.
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
this.
|
|
309
|
-
|
|
310
|
-
this.
|
|
311
|
-
row.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if(this.
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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;
|