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.
- 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 +0 -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 +0 -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 +0 -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 +0 -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 +0 -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 +0 -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 +0 -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 +0 -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 +102 -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 +0 -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 +0 -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 -25711
- 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 -25790
- 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 -1101
- package/src/js/core/Tabulator.js +895 -892
- 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 -623
- 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 -892
- 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 -598
- package/src/js/modules/GroupRows/GroupComponent.js +66 -66
- package/src/js/modules/GroupRows/GroupRows.js +639 -639
- 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 -185
- 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 -137
- 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 -444
- 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 -1467
- 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,1101 +1,1112 @@
|
|
|
1
|
-
import CoreFeature from './CoreFeature.js';
|
|
2
|
-
import Row from './row/Row.js';
|
|
3
|
-
import RowComponent from './row/RowComponent.js';
|
|
4
|
-
import Helpers from './tools/Helpers.js';
|
|
5
|
-
|
|
6
|
-
import RendererBasicVertical from './rendering/renderers/BasicVertical.js';
|
|
7
|
-
import RendererVirtualDomVertical from './rendering/renderers/VirtualDomVertical.js';
|
|
8
|
-
|
|
9
|
-
export default class RowManager extends CoreFeature{
|
|
10
|
-
|
|
11
|
-
constructor(table){
|
|
12
|
-
super(table);
|
|
13
|
-
|
|
14
|
-
this.element = this.createHolderElement(); //containing element
|
|
15
|
-
this.tableElement = this.createTableElement(); //table element
|
|
16
|
-
this.heightFixer = this.createTableElement(); //table element
|
|
17
|
-
this.placeholder = null; //placeholder element
|
|
18
|
-
this.placeholderContents = null; //placeholder element
|
|
19
|
-
|
|
20
|
-
this.firstRender = false; //handle first render
|
|
21
|
-
this.renderMode = "virtual"; //current rendering mode
|
|
22
|
-
this.fixedHeight = false; //current rendering mode
|
|
23
|
-
|
|
24
|
-
this.rows = []; //hold row data objects
|
|
25
|
-
this.activeRowsPipeline = []; //hold calculation of active rows
|
|
26
|
-
this.activeRows = []; //rows currently available to on display in the table
|
|
27
|
-
this.activeRowsCount = 0; //count of active rows
|
|
28
|
-
|
|
29
|
-
this.displayRows = []; //rows currently on display in the table
|
|
30
|
-
this.displayRowsCount = 0; //count of display rows
|
|
31
|
-
|
|
32
|
-
this.scrollTop = 0;
|
|
33
|
-
this.scrollLeft = 0;
|
|
34
|
-
|
|
35
|
-
this.redrawBlock = false; //prevent redraws to allow multiple data manipulations before continuing
|
|
36
|
-
this.redrawBlockRestoreConfig = false; //store latest redraw function calls for when redraw is needed
|
|
37
|
-
this.redrawBlockRenderInPosition = false; //store latest redraw function calls for when redraw is needed
|
|
38
|
-
|
|
39
|
-
this.dataPipeline = []; //hold data pipeline tasks
|
|
40
|
-
this.displayPipeline = []; //hold data display pipeline tasks
|
|
41
|
-
|
|
42
|
-
this.scrollbarWidth = 0;
|
|
43
|
-
|
|
44
|
-
this.renderer = null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//////////////// Setup Functions /////////////////
|
|
48
|
-
|
|
49
|
-
createHolderElement (){
|
|
50
|
-
var el = document.createElement("div");
|
|
51
|
-
|
|
52
|
-
el.classList.add("tabulator-tableholder");
|
|
53
|
-
el.setAttribute("tabindex", 0);
|
|
54
|
-
// el.setAttribute("role", "rowgroup");
|
|
55
|
-
|
|
56
|
-
return el;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
createTableElement (){
|
|
60
|
-
var el = document.createElement("div");
|
|
61
|
-
|
|
62
|
-
el.classList.add("tabulator-table");
|
|
63
|
-
el.setAttribute("role", "rowgroup");
|
|
64
|
-
|
|
65
|
-
return el;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
initializePlaceholder(){
|
|
69
|
-
var placeholder = this.table.options.placeholder;
|
|
70
|
-
|
|
71
|
-
//configure placeholder element
|
|
72
|
-
if(placeholder){
|
|
73
|
-
let el = document.createElement("div");
|
|
74
|
-
el.classList.add("tabulator-placeholder");
|
|
75
|
-
|
|
76
|
-
if(typeof placeholder == "string"){
|
|
77
|
-
let contents = document.createElement("div");
|
|
78
|
-
contents.classList.add("tabulator-placeholder-contents");
|
|
79
|
-
contents.innerHTML = placeholder;
|
|
80
|
-
|
|
81
|
-
el.appendChild(contents);
|
|
82
|
-
|
|
83
|
-
this.placeholderContents = contents;
|
|
84
|
-
|
|
85
|
-
}else if(typeof HTMLElement !== "undefined" && placeholder instanceof HTMLElement){
|
|
86
|
-
|
|
87
|
-
el.appendChild(placeholder);
|
|
88
|
-
this.placeholderContents = placeholder;
|
|
89
|
-
}else{
|
|
90
|
-
console.warn("Invalid placeholder provided, must be string or HTML Element", placeholder);
|
|
91
|
-
|
|
92
|
-
this.el = null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this.placeholder = el;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
//return containing element
|
|
100
|
-
getElement(){
|
|
101
|
-
return this.element;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
//return table element
|
|
105
|
-
getTableElement(){
|
|
106
|
-
return this.tableElement;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
initialize(){
|
|
110
|
-
this.initializePlaceholder();
|
|
111
|
-
this.initializeRenderer();
|
|
112
|
-
|
|
113
|
-
//initialize manager
|
|
114
|
-
this.element.appendChild(this.tableElement);
|
|
115
|
-
|
|
116
|
-
this.firstRender = true;
|
|
117
|
-
|
|
118
|
-
//scroll header along with table body
|
|
119
|
-
this.element.addEventListener("scroll", () => {
|
|
120
|
-
var left = this.element.scrollLeft,
|
|
121
|
-
leftDir = this.scrollLeft > left,
|
|
122
|
-
top = this.element.scrollTop,
|
|
123
|
-
topDir = this.scrollTop > top;
|
|
124
|
-
|
|
125
|
-
//handle horizontal scrolling
|
|
126
|
-
if(this.scrollLeft != left){
|
|
127
|
-
this.scrollLeft = left;
|
|
128
|
-
|
|
129
|
-
this.dispatch("scroll-horizontal", left, leftDir);
|
|
130
|
-
this.dispatchExternal("scrollHorizontal", left, leftDir);
|
|
131
|
-
|
|
132
|
-
this._positionPlaceholder();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
//handle vertical scrolling
|
|
136
|
-
if(this.scrollTop != top){
|
|
137
|
-
this.scrollTop = top;
|
|
138
|
-
|
|
139
|
-
this.renderer.scrollRows(top, topDir);
|
|
140
|
-
|
|
141
|
-
this.dispatch("scroll-vertical", top, topDir);
|
|
142
|
-
this.dispatchExternal("scrollVertical", top, topDir);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
////////////////// Row Manipulation //////////////////
|
|
148
|
-
findRow(subject){
|
|
149
|
-
if(typeof subject == "object"){
|
|
150
|
-
if(subject instanceof Row){
|
|
151
|
-
//subject is row element
|
|
152
|
-
return subject;
|
|
153
|
-
}else if(subject instanceof RowComponent){
|
|
154
|
-
//subject is public row component
|
|
155
|
-
return subject._getSelf() || false;
|
|
156
|
-
}else if(typeof HTMLElement !== "undefined" && subject instanceof HTMLElement){
|
|
157
|
-
//subject is a HTML element of the row
|
|
158
|
-
let match = this.rows.find((row) => {
|
|
159
|
-
return row.getElement() === subject;
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
return match || false;
|
|
163
|
-
}else if(subject === null){
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
}else if(typeof subject == "undefined"){
|
|
167
|
-
return false;
|
|
168
|
-
}else{
|
|
169
|
-
//subject should be treated as the index of the row
|
|
170
|
-
let match = this.rows.find((row) => {
|
|
171
|
-
return row.data[this.table.options.index] == subject;
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return match || false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//catch all for any other type of input
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
getRowFromDataObject(data){
|
|
182
|
-
var match = this.rows.find((row) => {
|
|
183
|
-
return row.data === data;
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
return match || false;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
getRowFromPosition(position){
|
|
190
|
-
return this.getDisplayRows().find((row) => {
|
|
191
|
-
return row.getPosition() === position && row.isDisplayed();
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
scrollToRow(row, position, ifVisible){
|
|
196
|
-
return this.renderer.scrollToRowPosition(row, position, ifVisible);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
////////////////// Data Handling //////////////////
|
|
200
|
-
setData(data, renderInPosition, columnsChanged){
|
|
201
|
-
return new Promise((resolve, reject)=>{
|
|
202
|
-
if(renderInPosition && this.getDisplayRows().length){
|
|
203
|
-
if(this.table.options.pagination){
|
|
204
|
-
this._setDataActual(data, true);
|
|
205
|
-
}else{
|
|
206
|
-
this.reRenderInPosition(() => {
|
|
207
|
-
this._setDataActual(data);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
}else{
|
|
211
|
-
if(this.table.options.autoColumns && columnsChanged && this.table.initialized){
|
|
212
|
-
this.table.columnManager.generateColumnsFromRowData(data);
|
|
213
|
-
}
|
|
214
|
-
this.resetScroll();
|
|
215
|
-
|
|
216
|
-
this._setDataActual(data);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
resolve();
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
_setDataActual(data, renderInPosition){
|
|
224
|
-
this.dispatchExternal("dataProcessing", data);
|
|
225
|
-
|
|
226
|
-
this._wipeElements();
|
|
227
|
-
|
|
228
|
-
if(Array.isArray(data)){
|
|
229
|
-
this.dispatch("data-processing", data);
|
|
230
|
-
|
|
231
|
-
data.forEach((def, i) => {
|
|
232
|
-
if(def && typeof def === "object"){
|
|
233
|
-
var row = new Row(def, this);
|
|
234
|
-
this.rows.push(row);
|
|
235
|
-
}else{
|
|
236
|
-
console.warn("Data Loading Warning - Invalid row data detected and ignored, expecting object but received:", def);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
this.refreshActiveData(false, false, renderInPosition);
|
|
241
|
-
|
|
242
|
-
this.dispatch("data-processed", data);
|
|
243
|
-
this.dispatchExternal("dataProcessed", data);
|
|
244
|
-
}else{
|
|
245
|
-
console.error("Data Loading Error - Unable to process data due to invalid data type \nExpecting: array \nReceived: ", typeof data, "\nData: ", data);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
_wipeElements(){
|
|
250
|
-
this.dispatch("rows-wipe");
|
|
251
|
-
|
|
252
|
-
this.destroy();
|
|
253
|
-
|
|
254
|
-
this.adjustTableSize();
|
|
255
|
-
|
|
256
|
-
this.dispatch("rows-wiped");
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
destroy(){
|
|
260
|
-
this.rows.forEach((row) => {
|
|
261
|
-
row.wipe();
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
this.rows = [];
|
|
265
|
-
this.activeRows = [];
|
|
266
|
-
this.activeRowsPipeline = [];
|
|
267
|
-
this.activeRowsCount = 0;
|
|
268
|
-
this.displayRows = [];
|
|
269
|
-
this.displayRowsCount = 0;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
deleteRow(row, blockRedraw){
|
|
273
|
-
var allIndex = this.rows.indexOf(row),
|
|
274
|
-
activeIndex = this.activeRows.indexOf(row);
|
|
275
|
-
|
|
276
|
-
if(activeIndex > -1){
|
|
277
|
-
this.activeRows.splice(activeIndex, 1);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if(allIndex > -1){
|
|
281
|
-
this.rows.splice(allIndex, 1);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
this.setActiveRows(this.activeRows);
|
|
285
|
-
|
|
286
|
-
this.displayRowIterator((rows) => {
|
|
287
|
-
var displayIndex = rows.indexOf(row);
|
|
288
|
-
|
|
289
|
-
if(displayIndex > -1){
|
|
290
|
-
rows.splice(displayIndex, 1);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
if(!blockRedraw){
|
|
295
|
-
this.reRenderInPosition();
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
this.regenerateRowPositions();
|
|
299
|
-
|
|
300
|
-
this.dispatchExternal("rowDeleted", row.getComponent());
|
|
301
|
-
|
|
302
|
-
if(!this.displayRowsCount){
|
|
303
|
-
this.
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if(this.subscribedExternal("dataChanged")){
|
|
307
|
-
this.dispatchExternal("dataChanged", this.getData());
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
addRow(data, pos, index, blockRedraw){
|
|
312
|
-
var row = this.addRowActual(data, pos, index, blockRedraw);
|
|
313
|
-
return row;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
//add multiple rows
|
|
317
|
-
addRows(data, pos, index, refreshDisplayOnly){
|
|
318
|
-
var rows = [];
|
|
319
|
-
|
|
320
|
-
return new Promise((resolve, reject) => {
|
|
321
|
-
pos = this.findAddRowPos(pos);
|
|
322
|
-
|
|
323
|
-
if(!Array.isArray(data)){
|
|
324
|
-
data = [data];
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if((typeof index == "undefined" && pos) || (typeof index !== "undefined" && !pos)){
|
|
328
|
-
data.reverse();
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
data.forEach((item, i) => {
|
|
332
|
-
var row = this.addRow(item, pos, index, true);
|
|
333
|
-
rows.push(row);
|
|
334
|
-
this.dispatch("row-added", row,
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
this.refreshActiveData(refreshDisplayOnly ? "displayPipeline" : false, false, true);
|
|
338
|
-
|
|
339
|
-
this.regenerateRowPositions();
|
|
340
|
-
|
|
341
|
-
if(rows.length){
|
|
342
|
-
this._clearPlaceholder();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
resolve(rows);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
findAddRowPos(pos){
|
|
350
|
-
if(typeof pos === "undefined"){
|
|
351
|
-
pos = this.table.options.addRowPos;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if(pos === "pos"){
|
|
355
|
-
pos = true;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if(pos === "bottom"){
|
|
359
|
-
pos = false;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return pos;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
addRowActual(data, pos, index, blockRedraw){
|
|
366
|
-
var row = data instanceof Row ? data : new Row(data || {}, this),
|
|
367
|
-
top = this.findAddRowPos(pos),
|
|
368
|
-
allIndex = -1,
|
|
369
|
-
activeIndex, chainResult;
|
|
370
|
-
|
|
371
|
-
if(!index){
|
|
372
|
-
chainResult = this.chain("row-adding-position", [row, top], null, {index, top});
|
|
373
|
-
|
|
374
|
-
index = chainResult.index;
|
|
375
|
-
top = chainResult.top;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
if(typeof index !== "undefined"){
|
|
379
|
-
index = this.findRow(index);
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
index = this.chain("row-adding-index", [row, index, top], null, index);
|
|
383
|
-
|
|
384
|
-
if(index){
|
|
385
|
-
allIndex = this.rows.indexOf(index);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
if(index && allIndex > -1){
|
|
389
|
-
activeIndex = this.activeRows.indexOf(index);
|
|
390
|
-
|
|
391
|
-
this.displayRowIterator(function(rows){
|
|
392
|
-
var displayIndex = rows.indexOf(index);
|
|
393
|
-
|
|
394
|
-
if(displayIndex > -1){
|
|
395
|
-
rows.splice((top ? displayIndex : displayIndex + 1), 0, row);
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
if(activeIndex > -1){
|
|
400
|
-
this.activeRows.splice((top ? activeIndex : activeIndex + 1), 0, row);
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
this.rows.splice((top ? allIndex : allIndex + 1), 0, row);
|
|
404
|
-
|
|
405
|
-
}else{
|
|
406
|
-
|
|
407
|
-
if(top){
|
|
408
|
-
|
|
409
|
-
this.displayRowIterator(function(rows){
|
|
410
|
-
rows.unshift(row);
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
this.activeRows.unshift(row);
|
|
414
|
-
this.rows.unshift(row);
|
|
415
|
-
}else{
|
|
416
|
-
this.displayRowIterator(function(rows){
|
|
417
|
-
rows.push(row);
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
this.activeRows.push(row);
|
|
421
|
-
this.rows.push(row);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
this.setActiveRows(this.activeRows);
|
|
426
|
-
|
|
427
|
-
this.dispatchExternal("rowAdded", row.getComponent());
|
|
428
|
-
|
|
429
|
-
if(this.subscribedExternal("dataChanged")){
|
|
430
|
-
this.dispatchExternal("dataChanged", this.table.rowManager.getData());
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if(!blockRedraw){
|
|
434
|
-
this.reRenderInPosition();
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return row;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
moveRow(from, to, after){
|
|
441
|
-
this.dispatch("row-move", from, to, after);
|
|
442
|
-
|
|
443
|
-
this.moveRowActual(from, to, after);
|
|
444
|
-
|
|
445
|
-
this.regenerateRowPositions();
|
|
446
|
-
|
|
447
|
-
this.dispatch("row-moved", from, to, after);
|
|
448
|
-
this.dispatchExternal("rowMoved", from.getComponent());
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
moveRowActual(from, to, after){
|
|
452
|
-
this.moveRowInArray(this.rows, from, to, after);
|
|
453
|
-
this.moveRowInArray(this.activeRows, from, to, after);
|
|
454
|
-
|
|
455
|
-
this.displayRowIterator((rows) => {
|
|
456
|
-
this.moveRowInArray(rows, from, to, after);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
this.dispatch("row-moving", from, to, after);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
moveRowInArray(rows, from, to, after){
|
|
463
|
-
var fromIndex, toIndex, start, end;
|
|
464
|
-
|
|
465
|
-
if(from !== to){
|
|
466
|
-
|
|
467
|
-
fromIndex = rows.indexOf(from);
|
|
468
|
-
|
|
469
|
-
if (fromIndex > -1) {
|
|
470
|
-
|
|
471
|
-
rows.splice(fromIndex, 1);
|
|
472
|
-
|
|
473
|
-
toIndex = rows.indexOf(to);
|
|
474
|
-
|
|
475
|
-
if (toIndex > -1) {
|
|
476
|
-
|
|
477
|
-
if(after){
|
|
478
|
-
rows.splice(toIndex+1, 0, from);
|
|
479
|
-
}else{
|
|
480
|
-
rows.splice(toIndex, 0, from);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
}else{
|
|
484
|
-
rows.splice(fromIndex, 0, from);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
//restyle rows
|
|
489
|
-
if(rows === this.getDisplayRows()){
|
|
490
|
-
|
|
491
|
-
start = fromIndex < toIndex ? fromIndex : toIndex;
|
|
492
|
-
end = toIndex > fromIndex ? toIndex : fromIndex +1;
|
|
493
|
-
|
|
494
|
-
for(let i = start; i <= end; i++){
|
|
495
|
-
if(rows[i]){
|
|
496
|
-
this.styleRow(rows[i], i);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
clearData(){
|
|
504
|
-
this.setData([]);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
getRowIndex(row){
|
|
508
|
-
return this.findRowIndex(row, this.rows);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
getDisplayRowIndex(row){
|
|
512
|
-
var index = this.getDisplayRows().indexOf(row);
|
|
513
|
-
return index > -1 ? index : false;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
nextDisplayRow(row, rowOnly){
|
|
517
|
-
var index = this.getDisplayRowIndex(row),
|
|
518
|
-
nextRow = false;
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
if(index !== false && index < this.displayRowsCount -1){
|
|
522
|
-
nextRow = this.getDisplayRows()[index+1];
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
if(nextRow && (!(nextRow instanceof Row) || nextRow.type != "row")){
|
|
526
|
-
return this.nextDisplayRow(nextRow, rowOnly);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return nextRow;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
prevDisplayRow(row, rowOnly){
|
|
533
|
-
var index = this.getDisplayRowIndex(row),
|
|
534
|
-
prevRow = false;
|
|
535
|
-
|
|
536
|
-
if(index){
|
|
537
|
-
prevRow = this.getDisplayRows()[index-1];
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
if(rowOnly && prevRow && (!(prevRow instanceof Row) || prevRow.type != "row")){
|
|
541
|
-
return this.prevDisplayRow(prevRow, rowOnly);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
return prevRow;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
findRowIndex(row, list){
|
|
548
|
-
var rowIndex;
|
|
549
|
-
|
|
550
|
-
row = this.findRow(row);
|
|
551
|
-
|
|
552
|
-
if(row){
|
|
553
|
-
rowIndex = list.indexOf(row);
|
|
554
|
-
|
|
555
|
-
if(rowIndex > -1){
|
|
556
|
-
return rowIndex;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
return false;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
getData(active, transform){
|
|
564
|
-
var output = [],
|
|
565
|
-
rows = this.getRows(active);
|
|
566
|
-
|
|
567
|
-
rows.forEach(function(row){
|
|
568
|
-
if(row.type == "row"){
|
|
569
|
-
output.push(row.getData(transform || "data"));
|
|
570
|
-
}
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return output;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
getComponents(active){
|
|
577
|
-
var output = [],
|
|
578
|
-
rows = this.getRows(active);
|
|
579
|
-
|
|
580
|
-
rows.forEach(function(row){
|
|
581
|
-
output.push(row.getComponent());
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
return output;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
getDataCount(active){
|
|
588
|
-
var rows = this.getRows(active);
|
|
589
|
-
|
|
590
|
-
return rows.length;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
scrollHorizontal(left){
|
|
594
|
-
this.scrollLeft = left;
|
|
595
|
-
this.element.scrollLeft = left;
|
|
596
|
-
|
|
597
|
-
this.dispatch("scroll-horizontal", left);
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
registerDataPipelineHandler(handler, priority){
|
|
601
|
-
if(typeof priority !== "undefined"){
|
|
602
|
-
this.dataPipeline.push({handler, priority});
|
|
603
|
-
this.dataPipeline.sort((a, b) => {
|
|
604
|
-
return a.priority - b.priority;
|
|
605
|
-
});
|
|
606
|
-
}else{
|
|
607
|
-
console.error("Data pipeline handlers must have a priority in order to be registered");
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
registerDisplayPipelineHandler(handler, priority){
|
|
612
|
-
if(typeof priority !== "undefined"){
|
|
613
|
-
this.displayPipeline.push({handler, priority});
|
|
614
|
-
this.displayPipeline.sort((a, b) => {
|
|
615
|
-
return a.priority - b.priority;
|
|
616
|
-
});
|
|
617
|
-
}else{
|
|
618
|
-
console.error("Display pipeline handlers must have a priority in order to be registered");
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
//set active data set
|
|
623
|
-
refreshActiveData(handler, skipStage, renderInPosition){
|
|
624
|
-
var table = this.table,
|
|
625
|
-
stage = "",
|
|
626
|
-
index = 0,
|
|
627
|
-
cascadeOrder = ["all", "dataPipeline", "display", "displayPipeline", "end"];
|
|
628
|
-
|
|
629
|
-
if(!this.table.destroyed){
|
|
630
|
-
if(typeof handler === "function"){
|
|
631
|
-
index = this.dataPipeline.findIndex((item) => {
|
|
632
|
-
return item.handler === handler;
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
if(index > -1){
|
|
636
|
-
stage = "dataPipeline";
|
|
637
|
-
|
|
638
|
-
if(skipStage){
|
|
639
|
-
if(index == this.dataPipeline.length - 1){
|
|
640
|
-
stage = "display";
|
|
641
|
-
}else{
|
|
642
|
-
index++;
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}else{
|
|
646
|
-
index = this.displayPipeline.findIndex((item) => {
|
|
647
|
-
return item.handler === handler;
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
if(index > -1){
|
|
651
|
-
stage = "displayPipeline";
|
|
652
|
-
|
|
653
|
-
if(skipStage){
|
|
654
|
-
if(index == this.displayPipeline.length - 1){
|
|
655
|
-
stage = "end";
|
|
656
|
-
}else{
|
|
657
|
-
index++;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}else{
|
|
661
|
-
console.error("Unable to refresh data, invalid handler provided", handler);
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}else{
|
|
666
|
-
stage = handler || "all";
|
|
667
|
-
index = 0;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
if(this.redrawBlock){
|
|
671
|
-
if(!this.redrawBlockRestoreConfig || (this.redrawBlockRestoreConfig && ((this.redrawBlockRestoreConfig.stage === stage && index < this.redrawBlockRestoreConfig.index) || (cascadeOrder.indexOf(stage) < cascadeOrder.indexOf(this.redrawBlockRestoreConfig.stage))))){
|
|
672
|
-
this.redrawBlockRestoreConfig = {
|
|
673
|
-
handler: handler,
|
|
674
|
-
skipStage: skipStage,
|
|
675
|
-
renderInPosition: renderInPosition,
|
|
676
|
-
stage:stage,
|
|
677
|
-
index:index,
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
return;
|
|
682
|
-
}else{
|
|
683
|
-
if(Helpers.elVisible(this.element)){
|
|
684
|
-
if(renderInPosition){
|
|
685
|
-
this.reRenderInPosition(this.refreshPipelines.bind(this, handler, stage, index, renderInPosition));
|
|
686
|
-
}else{
|
|
687
|
-
this.refreshPipelines(handler, stage, index, renderInPosition);
|
|
688
|
-
|
|
689
|
-
if(!handler){
|
|
690
|
-
this.table.columnManager.renderer.renderColumns();
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
this.renderTable();
|
|
694
|
-
|
|
695
|
-
if(table.options.layoutColumnsOnNewData){
|
|
696
|
-
this.table.columnManager.redraw(true);
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}else{
|
|
700
|
-
this.refreshPipelines(handler, stage, index, renderInPosition);
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
this.dispatch("data-refreshed");
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
refreshPipelines(handler, stage, index, renderInPosition){
|
|
709
|
-
this.dispatch("data-refreshing");
|
|
710
|
-
|
|
711
|
-
if(!handler){
|
|
712
|
-
this.activeRowsPipeline[0] = this.rows.slice(0);
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
//cascade through data refresh stages
|
|
716
|
-
switch(stage){
|
|
717
|
-
case "all":
|
|
718
|
-
//handle case where all data needs refreshing
|
|
719
|
-
|
|
720
|
-
case "dataPipeline":
|
|
721
|
-
|
|
722
|
-
for(let i = index; i < this.dataPipeline.length; i++){
|
|
723
|
-
let result = this.dataPipeline[i].handler(this.activeRowsPipeline[i].slice(0));
|
|
724
|
-
|
|
725
|
-
this.activeRowsPipeline[i + 1] = result || this.activeRowsPipeline[i].slice(0);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
this.setActiveRows(this.activeRowsPipeline[this.dataPipeline.length]);
|
|
729
|
-
|
|
730
|
-
case "display":
|
|
731
|
-
index = 0;
|
|
732
|
-
this.resetDisplayRows();
|
|
733
|
-
|
|
734
|
-
case "displayPipeline":
|
|
735
|
-
for(let i = index; i < this.displayPipeline.length; i++){
|
|
736
|
-
let result = this.displayPipeline[i].handler((i ? this.getDisplayRows(i - 1) : this.activeRows).slice(0), renderInPosition);
|
|
737
|
-
|
|
738
|
-
this.setDisplayRows(result || this.getDisplayRows(i - 1).slice(0), i);
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
case "end":
|
|
742
|
-
//case to handle scenario when trying to skip past end stage
|
|
743
|
-
this.regenerateRowPositions();
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
if(this.getDisplayRows().length){
|
|
747
|
-
this._clearPlaceholder();
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
//regenerate row positions
|
|
752
|
-
regenerateRowPositions(){
|
|
753
|
-
var rows = this.getDisplayRows();
|
|
754
|
-
var index = 1;
|
|
755
|
-
|
|
756
|
-
rows.forEach((row) => {
|
|
757
|
-
if (row.type === "row"){
|
|
758
|
-
row.setPosition(index);
|
|
759
|
-
index++;
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
setActiveRows(activeRows){
|
|
765
|
-
this.activeRows = activeRows;
|
|
766
|
-
this.activeRowsCount = this.activeRows.length;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
//reset display rows array
|
|
770
|
-
resetDisplayRows(){
|
|
771
|
-
this.displayRows = [];
|
|
772
|
-
|
|
773
|
-
this.displayRows.push(this.activeRows.slice(0));
|
|
774
|
-
|
|
775
|
-
this.displayRowsCount = this.displayRows[0].length;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
//set display row pipeline data
|
|
779
|
-
setDisplayRows(displayRows, index){
|
|
780
|
-
this.displayRows[index] = displayRows;
|
|
781
|
-
|
|
782
|
-
if(index == this.displayRows.length -1){
|
|
783
|
-
this.displayRowsCount = this.displayRows[this.displayRows.length -1].length;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
getDisplayRows(index){
|
|
788
|
-
if(typeof index == "undefined"){
|
|
789
|
-
return this.displayRows.length ? this.displayRows[this.displayRows.length -1] : [];
|
|
790
|
-
}else{
|
|
791
|
-
return this.displayRows[index] || [];
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
getVisibleRows(chain, viewable){
|
|
796
|
-
var rows = Object.assign([], this.renderer.visibleRows(!viewable));
|
|
797
|
-
|
|
798
|
-
if(chain){
|
|
799
|
-
rows = this.chain("rows-visible", [viewable], rows, rows);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return rows;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
//repeat action across display rows
|
|
806
|
-
displayRowIterator(callback){
|
|
807
|
-
this.activeRowsPipeline.forEach(callback);
|
|
808
|
-
this.displayRows.forEach(callback);
|
|
809
|
-
|
|
810
|
-
this.displayRowsCount = this.displayRows[this.displayRows.length -1].length;
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
//return only actual rows (not group headers etc)
|
|
814
|
-
getRows(type){
|
|
815
|
-
var rows = [];
|
|
816
|
-
|
|
817
|
-
switch(type){
|
|
818
|
-
case "active":
|
|
819
|
-
rows = this.activeRows;
|
|
820
|
-
break;
|
|
821
|
-
|
|
822
|
-
case "display":
|
|
823
|
-
rows = this.table.rowManager.getDisplayRows();
|
|
824
|
-
break;
|
|
825
|
-
|
|
826
|
-
case "visible":
|
|
827
|
-
rows = this.getVisibleRows(false, true);
|
|
828
|
-
break;
|
|
829
|
-
|
|
830
|
-
default:
|
|
831
|
-
rows = this.chain("rows-retrieve", type, null, this.rows) || this.rows;
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
return rows;
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
///////////////// Table Rendering /////////////////
|
|
838
|
-
//trigger rerender of table in current position
|
|
839
|
-
reRenderInPosition(callback){
|
|
840
|
-
if(this.redrawBlock){
|
|
841
|
-
if(callback){
|
|
842
|
-
callback();
|
|
843
|
-
}else{
|
|
844
|
-
this.redrawBlockRenderInPosition = true;
|
|
845
|
-
}
|
|
846
|
-
}else{
|
|
847
|
-
this.dispatchExternal("renderStarted");
|
|
848
|
-
|
|
849
|
-
this.renderer.rerenderRows(callback);
|
|
850
|
-
|
|
851
|
-
if(!this.fixedHeight){
|
|
852
|
-
this.adjustTableSize();
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
this.scrollBarCheck();
|
|
856
|
-
|
|
857
|
-
this.dispatchExternal("renderComplete");
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
scrollBarCheck(){
|
|
862
|
-
var scrollbarWidth = 0;
|
|
863
|
-
|
|
864
|
-
//adjust for vertical scrollbar moving table when present
|
|
865
|
-
if(this.element.scrollHeight > this.element.clientHeight){
|
|
866
|
-
scrollbarWidth = this.element.offsetWidth - this.element.clientWidth;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
if(scrollbarWidth !== this.scrollbarWidth){
|
|
870
|
-
this.scrollbarWidth = scrollbarWidth;
|
|
871
|
-
this.dispatch("scrollbar-vertical", scrollbarWidth);
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
initializeRenderer(){
|
|
876
|
-
var renderClass;
|
|
877
|
-
|
|
878
|
-
var renderers = {
|
|
879
|
-
"virtual": RendererVirtualDomVertical,
|
|
880
|
-
"basic": RendererBasicVertical,
|
|
881
|
-
};
|
|
882
|
-
|
|
883
|
-
if(typeof this.table.options.renderVertical === "string"){
|
|
884
|
-
renderClass = renderers[this.table.options.renderVertical];
|
|
885
|
-
}else{
|
|
886
|
-
renderClass = this.table.options.renderVertical;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
if(renderClass){
|
|
890
|
-
this.renderMode = this.table.options.renderVertical;
|
|
891
|
-
|
|
892
|
-
this.renderer = new renderClass(this.table, this.element, this.tableElement);
|
|
893
|
-
this.renderer.initialize();
|
|
894
|
-
|
|
895
|
-
if((this.table.element.clientHeight || this.table.options.height)){
|
|
896
|
-
this.fixedHeight = true;
|
|
897
|
-
}else{
|
|
898
|
-
this.fixedHeight = false;
|
|
899
|
-
}
|
|
900
|
-
}else{
|
|
901
|
-
console.error("Unable to find matching renderer:", this.table.options.renderVertical);
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
getRenderMode(){
|
|
906
|
-
return this.renderMode;
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
renderTable(){
|
|
910
|
-
this.dispatchExternal("renderStarted");
|
|
911
|
-
|
|
912
|
-
this.element.scrollTop = 0;
|
|
913
|
-
|
|
914
|
-
this._clearTable();
|
|
915
|
-
|
|
916
|
-
if(this.displayRowsCount){
|
|
917
|
-
this.renderer.renderRows();
|
|
918
|
-
|
|
919
|
-
if(this.firstRender){
|
|
920
|
-
this.firstRender = false;
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
this.
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
this.
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
this.
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
this.
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
this.
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1
|
+
import CoreFeature from './CoreFeature.js';
|
|
2
|
+
import Row from './row/Row.js';
|
|
3
|
+
import RowComponent from './row/RowComponent.js';
|
|
4
|
+
import Helpers from './tools/Helpers.js';
|
|
5
|
+
|
|
6
|
+
import RendererBasicVertical from './rendering/renderers/BasicVertical.js';
|
|
7
|
+
import RendererVirtualDomVertical from './rendering/renderers/VirtualDomVertical.js';
|
|
8
|
+
|
|
9
|
+
export default class RowManager extends CoreFeature{
|
|
10
|
+
|
|
11
|
+
constructor(table){
|
|
12
|
+
super(table);
|
|
13
|
+
|
|
14
|
+
this.element = this.createHolderElement(); //containing element
|
|
15
|
+
this.tableElement = this.createTableElement(); //table element
|
|
16
|
+
this.heightFixer = this.createTableElement(); //table element
|
|
17
|
+
this.placeholder = null; //placeholder element
|
|
18
|
+
this.placeholderContents = null; //placeholder element
|
|
19
|
+
|
|
20
|
+
this.firstRender = false; //handle first render
|
|
21
|
+
this.renderMode = "virtual"; //current rendering mode
|
|
22
|
+
this.fixedHeight = false; //current rendering mode
|
|
23
|
+
|
|
24
|
+
this.rows = []; //hold row data objects
|
|
25
|
+
this.activeRowsPipeline = []; //hold calculation of active rows
|
|
26
|
+
this.activeRows = []; //rows currently available to on display in the table
|
|
27
|
+
this.activeRowsCount = 0; //count of active rows
|
|
28
|
+
|
|
29
|
+
this.displayRows = []; //rows currently on display in the table
|
|
30
|
+
this.displayRowsCount = 0; //count of display rows
|
|
31
|
+
|
|
32
|
+
this.scrollTop = 0;
|
|
33
|
+
this.scrollLeft = 0;
|
|
34
|
+
|
|
35
|
+
this.redrawBlock = false; //prevent redraws to allow multiple data manipulations before continuing
|
|
36
|
+
this.redrawBlockRestoreConfig = false; //store latest redraw function calls for when redraw is needed
|
|
37
|
+
this.redrawBlockRenderInPosition = false; //store latest redraw function calls for when redraw is needed
|
|
38
|
+
|
|
39
|
+
this.dataPipeline = []; //hold data pipeline tasks
|
|
40
|
+
this.displayPipeline = []; //hold data display pipeline tasks
|
|
41
|
+
|
|
42
|
+
this.scrollbarWidth = 0;
|
|
43
|
+
|
|
44
|
+
this.renderer = null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//////////////// Setup Functions /////////////////
|
|
48
|
+
|
|
49
|
+
createHolderElement (){
|
|
50
|
+
var el = document.createElement("div");
|
|
51
|
+
|
|
52
|
+
el.classList.add("tabulator-tableholder");
|
|
53
|
+
el.setAttribute("tabindex", 0);
|
|
54
|
+
// el.setAttribute("role", "rowgroup");
|
|
55
|
+
|
|
56
|
+
return el;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
createTableElement (){
|
|
60
|
+
var el = document.createElement("div");
|
|
61
|
+
|
|
62
|
+
el.classList.add("tabulator-table");
|
|
63
|
+
el.setAttribute("role", "rowgroup");
|
|
64
|
+
|
|
65
|
+
return el;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
initializePlaceholder(){
|
|
69
|
+
var placeholder = this.table.options.placeholder;
|
|
70
|
+
|
|
71
|
+
//configure placeholder element
|
|
72
|
+
if(placeholder){
|
|
73
|
+
let el = document.createElement("div");
|
|
74
|
+
el.classList.add("tabulator-placeholder");
|
|
75
|
+
|
|
76
|
+
if(typeof placeholder == "string"){
|
|
77
|
+
let contents = document.createElement("div");
|
|
78
|
+
contents.classList.add("tabulator-placeholder-contents");
|
|
79
|
+
contents.innerHTML = placeholder;
|
|
80
|
+
|
|
81
|
+
el.appendChild(contents);
|
|
82
|
+
|
|
83
|
+
this.placeholderContents = contents;
|
|
84
|
+
|
|
85
|
+
}else if(typeof HTMLElement !== "undefined" && placeholder instanceof HTMLElement){
|
|
86
|
+
|
|
87
|
+
el.appendChild(placeholder);
|
|
88
|
+
this.placeholderContents = placeholder;
|
|
89
|
+
}else{
|
|
90
|
+
console.warn("Invalid placeholder provided, must be string or HTML Element", placeholder);
|
|
91
|
+
|
|
92
|
+
this.el = null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.placeholder = el;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//return containing element
|
|
100
|
+
getElement(){
|
|
101
|
+
return this.element;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//return table element
|
|
105
|
+
getTableElement(){
|
|
106
|
+
return this.tableElement;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
initialize(){
|
|
110
|
+
this.initializePlaceholder();
|
|
111
|
+
this.initializeRenderer();
|
|
112
|
+
|
|
113
|
+
//initialize manager
|
|
114
|
+
this.element.appendChild(this.tableElement);
|
|
115
|
+
|
|
116
|
+
this.firstRender = true;
|
|
117
|
+
|
|
118
|
+
//scroll header along with table body
|
|
119
|
+
this.element.addEventListener("scroll", () => {
|
|
120
|
+
var left = this.element.scrollLeft,
|
|
121
|
+
leftDir = this.scrollLeft > left,
|
|
122
|
+
top = this.element.scrollTop,
|
|
123
|
+
topDir = this.scrollTop > top;
|
|
124
|
+
|
|
125
|
+
//handle horizontal scrolling
|
|
126
|
+
if(this.scrollLeft != left){
|
|
127
|
+
this.scrollLeft = left;
|
|
128
|
+
|
|
129
|
+
this.dispatch("scroll-horizontal", left, leftDir);
|
|
130
|
+
this.dispatchExternal("scrollHorizontal", left, leftDir);
|
|
131
|
+
|
|
132
|
+
this._positionPlaceholder();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//handle vertical scrolling
|
|
136
|
+
if(this.scrollTop != top){
|
|
137
|
+
this.scrollTop = top;
|
|
138
|
+
|
|
139
|
+
this.renderer.scrollRows(top, topDir);
|
|
140
|
+
|
|
141
|
+
this.dispatch("scroll-vertical", top, topDir);
|
|
142
|
+
this.dispatchExternal("scrollVertical", top, topDir);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
////////////////// Row Manipulation //////////////////
|
|
148
|
+
findRow(subject){
|
|
149
|
+
if(typeof subject == "object"){
|
|
150
|
+
if(subject instanceof Row){
|
|
151
|
+
//subject is row element
|
|
152
|
+
return subject;
|
|
153
|
+
}else if(subject instanceof RowComponent){
|
|
154
|
+
//subject is public row component
|
|
155
|
+
return subject._getSelf() || false;
|
|
156
|
+
}else if(typeof HTMLElement !== "undefined" && subject instanceof HTMLElement){
|
|
157
|
+
//subject is a HTML element of the row
|
|
158
|
+
let match = this.rows.find((row) => {
|
|
159
|
+
return row.getElement() === subject;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return match || false;
|
|
163
|
+
}else if(subject === null){
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}else if(typeof subject == "undefined"){
|
|
167
|
+
return false;
|
|
168
|
+
}else{
|
|
169
|
+
//subject should be treated as the index of the row
|
|
170
|
+
let match = this.rows.find((row) => {
|
|
171
|
+
return row.data[this.table.options.index] == subject;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return match || false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//catch all for any other type of input
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
getRowFromDataObject(data){
|
|
182
|
+
var match = this.rows.find((row) => {
|
|
183
|
+
return row.data === data;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return match || false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
getRowFromPosition(position){
|
|
190
|
+
return this.getDisplayRows().find((row) => {
|
|
191
|
+
return row.getPosition() === position && row.isDisplayed();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
scrollToRow(row, position, ifVisible){
|
|
196
|
+
return this.renderer.scrollToRowPosition(row, position, ifVisible);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
////////////////// Data Handling //////////////////
|
|
200
|
+
setData(data, renderInPosition, columnsChanged){
|
|
201
|
+
return new Promise((resolve, reject)=>{
|
|
202
|
+
if(renderInPosition && this.getDisplayRows().length){
|
|
203
|
+
if(this.table.options.pagination){
|
|
204
|
+
this._setDataActual(data, true);
|
|
205
|
+
}else{
|
|
206
|
+
this.reRenderInPosition(() => {
|
|
207
|
+
this._setDataActual(data);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}else{
|
|
211
|
+
if(this.table.options.autoColumns && columnsChanged && this.table.initialized){
|
|
212
|
+
this.table.columnManager.generateColumnsFromRowData(data);
|
|
213
|
+
}
|
|
214
|
+
this.resetScroll();
|
|
215
|
+
|
|
216
|
+
this._setDataActual(data);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
resolve();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
_setDataActual(data, renderInPosition){
|
|
224
|
+
this.dispatchExternal("dataProcessing", data);
|
|
225
|
+
|
|
226
|
+
this._wipeElements();
|
|
227
|
+
|
|
228
|
+
if(Array.isArray(data)){
|
|
229
|
+
this.dispatch("data-processing", data);
|
|
230
|
+
|
|
231
|
+
data.forEach((def, i) => {
|
|
232
|
+
if(def && typeof def === "object"){
|
|
233
|
+
var row = new Row(def, this);
|
|
234
|
+
this.rows.push(row);
|
|
235
|
+
}else{
|
|
236
|
+
console.warn("Data Loading Warning - Invalid row data detected and ignored, expecting object but received:", def);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
this.refreshActiveData(false, false, renderInPosition);
|
|
241
|
+
|
|
242
|
+
this.dispatch("data-processed", data);
|
|
243
|
+
this.dispatchExternal("dataProcessed", data);
|
|
244
|
+
}else{
|
|
245
|
+
console.error("Data Loading Error - Unable to process data due to invalid data type \nExpecting: array \nReceived: ", typeof data, "\nData: ", data);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
_wipeElements(){
|
|
250
|
+
this.dispatch("rows-wipe");
|
|
251
|
+
|
|
252
|
+
this.destroy();
|
|
253
|
+
|
|
254
|
+
this.adjustTableSize();
|
|
255
|
+
|
|
256
|
+
this.dispatch("rows-wiped");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
destroy(){
|
|
260
|
+
this.rows.forEach((row) => {
|
|
261
|
+
row.wipe();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
this.rows = [];
|
|
265
|
+
this.activeRows = [];
|
|
266
|
+
this.activeRowsPipeline = [];
|
|
267
|
+
this.activeRowsCount = 0;
|
|
268
|
+
this.displayRows = [];
|
|
269
|
+
this.displayRowsCount = 0;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
deleteRow(row, blockRedraw){
|
|
273
|
+
var allIndex = this.rows.indexOf(row),
|
|
274
|
+
activeIndex = this.activeRows.indexOf(row);
|
|
275
|
+
|
|
276
|
+
if(activeIndex > -1){
|
|
277
|
+
this.activeRows.splice(activeIndex, 1);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if(allIndex > -1){
|
|
281
|
+
this.rows.splice(allIndex, 1);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
this.setActiveRows(this.activeRows);
|
|
285
|
+
|
|
286
|
+
this.displayRowIterator((rows) => {
|
|
287
|
+
var displayIndex = rows.indexOf(row);
|
|
288
|
+
|
|
289
|
+
if(displayIndex > -1){
|
|
290
|
+
rows.splice(displayIndex, 1);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
if(!blockRedraw){
|
|
295
|
+
this.reRenderInPosition();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
this.regenerateRowPositions();
|
|
299
|
+
|
|
300
|
+
this.dispatchExternal("rowDeleted", row.getComponent());
|
|
301
|
+
|
|
302
|
+
if(!this.displayRowsCount){
|
|
303
|
+
this.tableEmpty();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if(this.subscribedExternal("dataChanged")){
|
|
307
|
+
this.dispatchExternal("dataChanged", this.getData());
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
addRow(data, pos, index, blockRedraw){
|
|
312
|
+
var row = this.addRowActual(data, pos, index, blockRedraw);
|
|
313
|
+
return row;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
//add multiple rows
|
|
317
|
+
addRows(data, pos, index, refreshDisplayOnly){
|
|
318
|
+
var rows = [];
|
|
319
|
+
|
|
320
|
+
return new Promise((resolve, reject) => {
|
|
321
|
+
pos = this.findAddRowPos(pos);
|
|
322
|
+
|
|
323
|
+
if(!Array.isArray(data)){
|
|
324
|
+
data = [data];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if((typeof index == "undefined" && pos) || (typeof index !== "undefined" && !pos)){
|
|
328
|
+
data.reverse();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
data.forEach((item, i) => {
|
|
332
|
+
var row = this.addRow(item, pos, index, true);
|
|
333
|
+
rows.push(row);
|
|
334
|
+
this.dispatch("row-added", row, item, pos, index);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
this.refreshActiveData(refreshDisplayOnly ? "displayPipeline" : false, false, true);
|
|
338
|
+
|
|
339
|
+
this.regenerateRowPositions();
|
|
340
|
+
|
|
341
|
+
if(rows.length){
|
|
342
|
+
this._clearPlaceholder();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
resolve(rows);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
findAddRowPos(pos){
|
|
350
|
+
if(typeof pos === "undefined"){
|
|
351
|
+
pos = this.table.options.addRowPos;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if(pos === "pos"){
|
|
355
|
+
pos = true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if(pos === "bottom"){
|
|
359
|
+
pos = false;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return pos;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
addRowActual(data, pos, index, blockRedraw){
|
|
366
|
+
var row = data instanceof Row ? data : new Row(data || {}, this),
|
|
367
|
+
top = this.findAddRowPos(pos),
|
|
368
|
+
allIndex = -1,
|
|
369
|
+
activeIndex, chainResult;
|
|
370
|
+
|
|
371
|
+
if(!index){
|
|
372
|
+
chainResult = this.chain("row-adding-position", [row, top], null, {index, top});
|
|
373
|
+
|
|
374
|
+
index = chainResult.index;
|
|
375
|
+
top = chainResult.top;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if(typeof index !== "undefined"){
|
|
379
|
+
index = this.findRow(index);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
index = this.chain("row-adding-index", [row, index, top], null, index);
|
|
383
|
+
|
|
384
|
+
if(index){
|
|
385
|
+
allIndex = this.rows.indexOf(index);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if(index && allIndex > -1){
|
|
389
|
+
activeIndex = this.activeRows.indexOf(index);
|
|
390
|
+
|
|
391
|
+
this.displayRowIterator(function(rows){
|
|
392
|
+
var displayIndex = rows.indexOf(index);
|
|
393
|
+
|
|
394
|
+
if(displayIndex > -1){
|
|
395
|
+
rows.splice((top ? displayIndex : displayIndex + 1), 0, row);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
if(activeIndex > -1){
|
|
400
|
+
this.activeRows.splice((top ? activeIndex : activeIndex + 1), 0, row);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
this.rows.splice((top ? allIndex : allIndex + 1), 0, row);
|
|
404
|
+
|
|
405
|
+
}else{
|
|
406
|
+
|
|
407
|
+
if(top){
|
|
408
|
+
|
|
409
|
+
this.displayRowIterator(function(rows){
|
|
410
|
+
rows.unshift(row);
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
this.activeRows.unshift(row);
|
|
414
|
+
this.rows.unshift(row);
|
|
415
|
+
}else{
|
|
416
|
+
this.displayRowIterator(function(rows){
|
|
417
|
+
rows.push(row);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
this.activeRows.push(row);
|
|
421
|
+
this.rows.push(row);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
this.setActiveRows(this.activeRows);
|
|
426
|
+
|
|
427
|
+
this.dispatchExternal("rowAdded", row.getComponent());
|
|
428
|
+
|
|
429
|
+
if(this.subscribedExternal("dataChanged")){
|
|
430
|
+
this.dispatchExternal("dataChanged", this.table.rowManager.getData());
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if(!blockRedraw){
|
|
434
|
+
this.reRenderInPosition();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return row;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
moveRow(from, to, after){
|
|
441
|
+
this.dispatch("row-move", from, to, after);
|
|
442
|
+
|
|
443
|
+
this.moveRowActual(from, to, after);
|
|
444
|
+
|
|
445
|
+
this.regenerateRowPositions();
|
|
446
|
+
|
|
447
|
+
this.dispatch("row-moved", from, to, after);
|
|
448
|
+
this.dispatchExternal("rowMoved", from.getComponent());
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
moveRowActual(from, to, after){
|
|
452
|
+
this.moveRowInArray(this.rows, from, to, after);
|
|
453
|
+
this.moveRowInArray(this.activeRows, from, to, after);
|
|
454
|
+
|
|
455
|
+
this.displayRowIterator((rows) => {
|
|
456
|
+
this.moveRowInArray(rows, from, to, after);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
this.dispatch("row-moving", from, to, after);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
moveRowInArray(rows, from, to, after){
|
|
463
|
+
var fromIndex, toIndex, start, end;
|
|
464
|
+
|
|
465
|
+
if(from !== to){
|
|
466
|
+
|
|
467
|
+
fromIndex = rows.indexOf(from);
|
|
468
|
+
|
|
469
|
+
if (fromIndex > -1) {
|
|
470
|
+
|
|
471
|
+
rows.splice(fromIndex, 1);
|
|
472
|
+
|
|
473
|
+
toIndex = rows.indexOf(to);
|
|
474
|
+
|
|
475
|
+
if (toIndex > -1) {
|
|
476
|
+
|
|
477
|
+
if(after){
|
|
478
|
+
rows.splice(toIndex+1, 0, from);
|
|
479
|
+
}else{
|
|
480
|
+
rows.splice(toIndex, 0, from);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
}else{
|
|
484
|
+
rows.splice(fromIndex, 0, from);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
//restyle rows
|
|
489
|
+
if(rows === this.getDisplayRows()){
|
|
490
|
+
|
|
491
|
+
start = fromIndex < toIndex ? fromIndex : toIndex;
|
|
492
|
+
end = toIndex > fromIndex ? toIndex : fromIndex +1;
|
|
493
|
+
|
|
494
|
+
for(let i = start; i <= end; i++){
|
|
495
|
+
if(rows[i]){
|
|
496
|
+
this.styleRow(rows[i], i);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
clearData(){
|
|
504
|
+
this.setData([]);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
getRowIndex(row){
|
|
508
|
+
return this.findRowIndex(row, this.rows);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
getDisplayRowIndex(row){
|
|
512
|
+
var index = this.getDisplayRows().indexOf(row);
|
|
513
|
+
return index > -1 ? index : false;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
nextDisplayRow(row, rowOnly){
|
|
517
|
+
var index = this.getDisplayRowIndex(row),
|
|
518
|
+
nextRow = false;
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
if(index !== false && index < this.displayRowsCount -1){
|
|
522
|
+
nextRow = this.getDisplayRows()[index+1];
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if(nextRow && (!(nextRow instanceof Row) || nextRow.type != "row")){
|
|
526
|
+
return this.nextDisplayRow(nextRow, rowOnly);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return nextRow;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
prevDisplayRow(row, rowOnly){
|
|
533
|
+
var index = this.getDisplayRowIndex(row),
|
|
534
|
+
prevRow = false;
|
|
535
|
+
|
|
536
|
+
if(index){
|
|
537
|
+
prevRow = this.getDisplayRows()[index-1];
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if(rowOnly && prevRow && (!(prevRow instanceof Row) || prevRow.type != "row")){
|
|
541
|
+
return this.prevDisplayRow(prevRow, rowOnly);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return prevRow;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
findRowIndex(row, list){
|
|
548
|
+
var rowIndex;
|
|
549
|
+
|
|
550
|
+
row = this.findRow(row);
|
|
551
|
+
|
|
552
|
+
if(row){
|
|
553
|
+
rowIndex = list.indexOf(row);
|
|
554
|
+
|
|
555
|
+
if(rowIndex > -1){
|
|
556
|
+
return rowIndex;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return false;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
getData(active, transform){
|
|
564
|
+
var output = [],
|
|
565
|
+
rows = this.getRows(active);
|
|
566
|
+
|
|
567
|
+
rows.forEach(function(row){
|
|
568
|
+
if(row.type == "row"){
|
|
569
|
+
output.push(row.getData(transform || "data"));
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
return output;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
getComponents(active){
|
|
577
|
+
var output = [],
|
|
578
|
+
rows = this.getRows(active);
|
|
579
|
+
|
|
580
|
+
rows.forEach(function(row){
|
|
581
|
+
output.push(row.getComponent());
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
return output;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
getDataCount(active){
|
|
588
|
+
var rows = this.getRows(active);
|
|
589
|
+
|
|
590
|
+
return rows.length;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
scrollHorizontal(left){
|
|
594
|
+
this.scrollLeft = left;
|
|
595
|
+
this.element.scrollLeft = left;
|
|
596
|
+
|
|
597
|
+
this.dispatch("scroll-horizontal", left);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
registerDataPipelineHandler(handler, priority){
|
|
601
|
+
if(typeof priority !== "undefined"){
|
|
602
|
+
this.dataPipeline.push({handler, priority});
|
|
603
|
+
this.dataPipeline.sort((a, b) => {
|
|
604
|
+
return a.priority - b.priority;
|
|
605
|
+
});
|
|
606
|
+
}else{
|
|
607
|
+
console.error("Data pipeline handlers must have a priority in order to be registered");
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
registerDisplayPipelineHandler(handler, priority){
|
|
612
|
+
if(typeof priority !== "undefined"){
|
|
613
|
+
this.displayPipeline.push({handler, priority});
|
|
614
|
+
this.displayPipeline.sort((a, b) => {
|
|
615
|
+
return a.priority - b.priority;
|
|
616
|
+
});
|
|
617
|
+
}else{
|
|
618
|
+
console.error("Display pipeline handlers must have a priority in order to be registered");
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
//set active data set
|
|
623
|
+
refreshActiveData(handler, skipStage, renderInPosition){
|
|
624
|
+
var table = this.table,
|
|
625
|
+
stage = "",
|
|
626
|
+
index = 0,
|
|
627
|
+
cascadeOrder = ["all", "dataPipeline", "display", "displayPipeline", "end"];
|
|
628
|
+
|
|
629
|
+
if(!this.table.destroyed){
|
|
630
|
+
if(typeof handler === "function"){
|
|
631
|
+
index = this.dataPipeline.findIndex((item) => {
|
|
632
|
+
return item.handler === handler;
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
if(index > -1){
|
|
636
|
+
stage = "dataPipeline";
|
|
637
|
+
|
|
638
|
+
if(skipStage){
|
|
639
|
+
if(index == this.dataPipeline.length - 1){
|
|
640
|
+
stage = "display";
|
|
641
|
+
}else{
|
|
642
|
+
index++;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}else{
|
|
646
|
+
index = this.displayPipeline.findIndex((item) => {
|
|
647
|
+
return item.handler === handler;
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
if(index > -1){
|
|
651
|
+
stage = "displayPipeline";
|
|
652
|
+
|
|
653
|
+
if(skipStage){
|
|
654
|
+
if(index == this.displayPipeline.length - 1){
|
|
655
|
+
stage = "end";
|
|
656
|
+
}else{
|
|
657
|
+
index++;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}else{
|
|
661
|
+
console.error("Unable to refresh data, invalid handler provided", handler);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}else{
|
|
666
|
+
stage = handler || "all";
|
|
667
|
+
index = 0;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if(this.redrawBlock){
|
|
671
|
+
if(!this.redrawBlockRestoreConfig || (this.redrawBlockRestoreConfig && ((this.redrawBlockRestoreConfig.stage === stage && index < this.redrawBlockRestoreConfig.index) || (cascadeOrder.indexOf(stage) < cascadeOrder.indexOf(this.redrawBlockRestoreConfig.stage))))){
|
|
672
|
+
this.redrawBlockRestoreConfig = {
|
|
673
|
+
handler: handler,
|
|
674
|
+
skipStage: skipStage,
|
|
675
|
+
renderInPosition: renderInPosition,
|
|
676
|
+
stage:stage,
|
|
677
|
+
index:index,
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
return;
|
|
682
|
+
}else{
|
|
683
|
+
if(Helpers.elVisible(this.element)){
|
|
684
|
+
if(renderInPosition){
|
|
685
|
+
this.reRenderInPosition(this.refreshPipelines.bind(this, handler, stage, index, renderInPosition));
|
|
686
|
+
}else{
|
|
687
|
+
this.refreshPipelines(handler, stage, index, renderInPosition);
|
|
688
|
+
|
|
689
|
+
if(!handler){
|
|
690
|
+
this.table.columnManager.renderer.renderColumns();
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
this.renderTable();
|
|
694
|
+
|
|
695
|
+
if(table.options.layoutColumnsOnNewData){
|
|
696
|
+
this.table.columnManager.redraw(true);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}else{
|
|
700
|
+
this.refreshPipelines(handler, stage, index, renderInPosition);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
this.dispatch("data-refreshed");
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
refreshPipelines(handler, stage, index, renderInPosition){
|
|
709
|
+
this.dispatch("data-refreshing");
|
|
710
|
+
|
|
711
|
+
if(!handler){
|
|
712
|
+
this.activeRowsPipeline[0] = this.rows.slice(0);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
//cascade through data refresh stages
|
|
716
|
+
switch(stage){
|
|
717
|
+
case "all":
|
|
718
|
+
//handle case where all data needs refreshing
|
|
719
|
+
|
|
720
|
+
case "dataPipeline":
|
|
721
|
+
|
|
722
|
+
for(let i = index; i < this.dataPipeline.length; i++){
|
|
723
|
+
let result = this.dataPipeline[i].handler(this.activeRowsPipeline[i].slice(0));
|
|
724
|
+
|
|
725
|
+
this.activeRowsPipeline[i + 1] = result || this.activeRowsPipeline[i].slice(0);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
this.setActiveRows(this.activeRowsPipeline[this.dataPipeline.length]);
|
|
729
|
+
|
|
730
|
+
case "display":
|
|
731
|
+
index = 0;
|
|
732
|
+
this.resetDisplayRows();
|
|
733
|
+
|
|
734
|
+
case "displayPipeline":
|
|
735
|
+
for(let i = index; i < this.displayPipeline.length; i++){
|
|
736
|
+
let result = this.displayPipeline[i].handler((i ? this.getDisplayRows(i - 1) : this.activeRows).slice(0), renderInPosition);
|
|
737
|
+
|
|
738
|
+
this.setDisplayRows(result || this.getDisplayRows(i - 1).slice(0), i);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
case "end":
|
|
742
|
+
//case to handle scenario when trying to skip past end stage
|
|
743
|
+
this.regenerateRowPositions();
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
if(this.getDisplayRows().length){
|
|
747
|
+
this._clearPlaceholder();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
//regenerate row positions
|
|
752
|
+
regenerateRowPositions(){
|
|
753
|
+
var rows = this.getDisplayRows();
|
|
754
|
+
var index = 1;
|
|
755
|
+
|
|
756
|
+
rows.forEach((row) => {
|
|
757
|
+
if (row.type === "row"){
|
|
758
|
+
row.setPosition(index);
|
|
759
|
+
index++;
|
|
760
|
+
}
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
setActiveRows(activeRows){
|
|
765
|
+
this.activeRows = this.activeRows = Object.assign([], activeRows);
|
|
766
|
+
this.activeRowsCount = this.activeRows.length;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
//reset display rows array
|
|
770
|
+
resetDisplayRows(){
|
|
771
|
+
this.displayRows = [];
|
|
772
|
+
|
|
773
|
+
this.displayRows.push(this.activeRows.slice(0));
|
|
774
|
+
|
|
775
|
+
this.displayRowsCount = this.displayRows[0].length;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
//set display row pipeline data
|
|
779
|
+
setDisplayRows(displayRows, index){
|
|
780
|
+
this.displayRows[index] = displayRows;
|
|
781
|
+
|
|
782
|
+
if(index == this.displayRows.length -1){
|
|
783
|
+
this.displayRowsCount = this.displayRows[this.displayRows.length -1].length;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
getDisplayRows(index){
|
|
788
|
+
if(typeof index == "undefined"){
|
|
789
|
+
return this.displayRows.length ? this.displayRows[this.displayRows.length -1] : [];
|
|
790
|
+
}else{
|
|
791
|
+
return this.displayRows[index] || [];
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
getVisibleRows(chain, viewable){
|
|
796
|
+
var rows = Object.assign([], this.renderer.visibleRows(!viewable));
|
|
797
|
+
|
|
798
|
+
if(chain){
|
|
799
|
+
rows = this.chain("rows-visible", [viewable], rows, rows);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return rows;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
//repeat action across display rows
|
|
806
|
+
displayRowIterator(callback){
|
|
807
|
+
this.activeRowsPipeline.forEach(callback);
|
|
808
|
+
this.displayRows.forEach(callback);
|
|
809
|
+
|
|
810
|
+
this.displayRowsCount = this.displayRows[this.displayRows.length -1].length;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
//return only actual rows (not group headers etc)
|
|
814
|
+
getRows(type){
|
|
815
|
+
var rows = [];
|
|
816
|
+
|
|
817
|
+
switch(type){
|
|
818
|
+
case "active":
|
|
819
|
+
rows = this.activeRows;
|
|
820
|
+
break;
|
|
821
|
+
|
|
822
|
+
case "display":
|
|
823
|
+
rows = this.table.rowManager.getDisplayRows();
|
|
824
|
+
break;
|
|
825
|
+
|
|
826
|
+
case "visible":
|
|
827
|
+
rows = this.getVisibleRows(false, true);
|
|
828
|
+
break;
|
|
829
|
+
|
|
830
|
+
default:
|
|
831
|
+
rows = this.chain("rows-retrieve", type, null, this.rows) || this.rows;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
return rows;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
///////////////// Table Rendering /////////////////
|
|
838
|
+
//trigger rerender of table in current position
|
|
839
|
+
reRenderInPosition(callback){
|
|
840
|
+
if(this.redrawBlock){
|
|
841
|
+
if(callback){
|
|
842
|
+
callback();
|
|
843
|
+
}else{
|
|
844
|
+
this.redrawBlockRenderInPosition = true;
|
|
845
|
+
}
|
|
846
|
+
}else{
|
|
847
|
+
this.dispatchExternal("renderStarted");
|
|
848
|
+
|
|
849
|
+
this.renderer.rerenderRows(callback);
|
|
850
|
+
|
|
851
|
+
if(!this.fixedHeight){
|
|
852
|
+
this.adjustTableSize();
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
this.scrollBarCheck();
|
|
856
|
+
|
|
857
|
+
this.dispatchExternal("renderComplete");
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
scrollBarCheck(){
|
|
862
|
+
var scrollbarWidth = 0;
|
|
863
|
+
|
|
864
|
+
//adjust for vertical scrollbar moving table when present
|
|
865
|
+
if(this.element.scrollHeight > this.element.clientHeight){
|
|
866
|
+
scrollbarWidth = this.element.offsetWidth - this.element.clientWidth;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if(scrollbarWidth !== this.scrollbarWidth){
|
|
870
|
+
this.scrollbarWidth = scrollbarWidth;
|
|
871
|
+
this.dispatch("scrollbar-vertical", scrollbarWidth);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
initializeRenderer(){
|
|
876
|
+
var renderClass;
|
|
877
|
+
|
|
878
|
+
var renderers = {
|
|
879
|
+
"virtual": RendererVirtualDomVertical,
|
|
880
|
+
"basic": RendererBasicVertical,
|
|
881
|
+
};
|
|
882
|
+
|
|
883
|
+
if(typeof this.table.options.renderVertical === "string"){
|
|
884
|
+
renderClass = renderers[this.table.options.renderVertical];
|
|
885
|
+
}else{
|
|
886
|
+
renderClass = this.table.options.renderVertical;
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
if(renderClass){
|
|
890
|
+
this.renderMode = this.table.options.renderVertical;
|
|
891
|
+
|
|
892
|
+
this.renderer = new renderClass(this.table, this.element, this.tableElement);
|
|
893
|
+
this.renderer.initialize();
|
|
894
|
+
|
|
895
|
+
if((this.table.element.clientHeight || this.table.options.height) && !(this.table.options.minHeight && this.table.options.maxHeight)){
|
|
896
|
+
this.fixedHeight = true;
|
|
897
|
+
}else{
|
|
898
|
+
this.fixedHeight = false;
|
|
899
|
+
}
|
|
900
|
+
}else{
|
|
901
|
+
console.error("Unable to find matching renderer:", this.table.options.renderVertical);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
getRenderMode(){
|
|
906
|
+
return this.renderMode;
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
renderTable(){
|
|
910
|
+
this.dispatchExternal("renderStarted");
|
|
911
|
+
|
|
912
|
+
this.element.scrollTop = 0;
|
|
913
|
+
|
|
914
|
+
this._clearTable();
|
|
915
|
+
|
|
916
|
+
if(this.displayRowsCount){
|
|
917
|
+
this.renderer.renderRows();
|
|
918
|
+
|
|
919
|
+
if(this.firstRender){
|
|
920
|
+
this.firstRender = false;
|
|
921
|
+
|
|
922
|
+
if(!this.fixedHeight){
|
|
923
|
+
this.adjustTableSize();
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
this.layoutRefresh(true);
|
|
927
|
+
}
|
|
928
|
+
}else{
|
|
929
|
+
this.renderEmptyScroll();
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
if(!this.fixedHeight){
|
|
933
|
+
this.adjustTableSize();
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
this.dispatch("table-layout");
|
|
937
|
+
|
|
938
|
+
if(!this.displayRowsCount){
|
|
939
|
+
this._showPlaceholder();
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
this.scrollBarCheck();
|
|
943
|
+
|
|
944
|
+
this.dispatchExternal("renderComplete");
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
//show scrollbars on empty table div
|
|
948
|
+
renderEmptyScroll(){
|
|
949
|
+
if(this.placeholder){
|
|
950
|
+
this.tableElement.style.display = "none";
|
|
951
|
+
}else{
|
|
952
|
+
this.tableElement.style.minWidth = this.table.columnManager.getWidth() + "px";
|
|
953
|
+
// this.tableElement.style.minHeight = "1px";
|
|
954
|
+
// this.tableElement.style.visibility = "hidden";
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
_clearTable(){
|
|
959
|
+
this._clearPlaceholder();
|
|
960
|
+
|
|
961
|
+
this.scrollTop = 0;
|
|
962
|
+
this.scrollLeft = 0;
|
|
963
|
+
|
|
964
|
+
this.renderer.clearRows();
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
tableEmpty(){
|
|
968
|
+
this.renderEmptyScroll();
|
|
969
|
+
this._showPlaceholder();
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
_showPlaceholder(){
|
|
973
|
+
if(this.placeholder){
|
|
974
|
+
this.placeholder.setAttribute("tabulator-render-mode", this.renderMode);
|
|
975
|
+
|
|
976
|
+
this.getElement().appendChild(this.placeholder);
|
|
977
|
+
this._positionPlaceholder();
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
_clearPlaceholder(){
|
|
982
|
+
if(this.placeholder && this.placeholder.parentNode){
|
|
983
|
+
this.placeholder.parentNode.removeChild(this.placeholder);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// clear empty table placeholder min
|
|
987
|
+
this.tableElement.style.minWidth = "";
|
|
988
|
+
this.tableElement.style.display = "";
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
_positionPlaceholder(){
|
|
992
|
+
if(this.placeholder && this.placeholder.parentNode){
|
|
993
|
+
this.placeholder.style.width = this.table.columnManager.getWidth() + "px";
|
|
994
|
+
this.placeholderContents.style.width = this.table.rowManager.element.clientWidth + "px";
|
|
995
|
+
this.placeholderContents.style.marginLeft = this.scrollLeft + "px";
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
styleRow(row, index){
|
|
1000
|
+
var rowEl = row.getElement();
|
|
1001
|
+
|
|
1002
|
+
if(index % 2){
|
|
1003
|
+
rowEl.classList.add("tabulator-row-even");
|
|
1004
|
+
rowEl.classList.remove("tabulator-row-odd");
|
|
1005
|
+
}else{
|
|
1006
|
+
rowEl.classList.add("tabulator-row-odd");
|
|
1007
|
+
rowEl.classList.remove("tabulator-row-even");
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
//normalize height of active rows
|
|
1012
|
+
normalizeHeight(){
|
|
1013
|
+
this.activeRows.forEach(function(row){
|
|
1014
|
+
row.normalizeHeight();
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
//adjust the height of the table holder to fit in the Tabulator element
|
|
1019
|
+
adjustTableSize(){
|
|
1020
|
+
var initialHeight = this.element.clientHeight, minHeight;
|
|
1021
|
+
|
|
1022
|
+
if(this.renderer.verticalFillMode === "fill"){
|
|
1023
|
+
let otherHeight = Math.floor(this.table.columnManager.getElement().getBoundingClientRect().height + (this.table.footerManager && this.table.footerManager.active && !this.table.footerManager.external ? this.table.footerManager.getElement().getBoundingClientRect().height : 0));
|
|
1024
|
+
|
|
1025
|
+
if(this.fixedHeight){
|
|
1026
|
+
minHeight = isNaN(this.table.options.minHeight) ? this.table.options.minHeight : this.table.options.minHeight + "px";
|
|
1027
|
+
|
|
1028
|
+
this.element.style.minHeight = minHeight || "calc(100% - " + otherHeight + "px)";
|
|
1029
|
+
this.element.style.height = "calc(100% - " + otherHeight + "px)";
|
|
1030
|
+
this.element.style.maxHeight = "calc(100% - " + otherHeight + "px)";
|
|
1031
|
+
}else{
|
|
1032
|
+
this.element.style.height = "";
|
|
1033
|
+
this.element.style.height = (this.table.element.clientHeight - otherHeight) + "px";
|
|
1034
|
+
this.element.scrollTop = this.scrollTop;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
this.renderer.resize();
|
|
1038
|
+
|
|
1039
|
+
//check if the table has changed size when dealing with variable height tables
|
|
1040
|
+
if(!this.fixedHeight && initialHeight != this.element.clientHeight){
|
|
1041
|
+
if(this.subscribed("table-resize")){
|
|
1042
|
+
this.dispatch("table-resize");
|
|
1043
|
+
}else{
|
|
1044
|
+
this.redraw();
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
this.scrollBarCheck();
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
this._positionPlaceholder();
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
//reinitialize all rows
|
|
1055
|
+
reinitialize(){
|
|
1056
|
+
this.rows.forEach(function(row){
|
|
1057
|
+
row.reinitialize(true);
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
//prevent table from being redrawn
|
|
1062
|
+
blockRedraw (){
|
|
1063
|
+
this.redrawBlock = true;
|
|
1064
|
+
this.redrawBlockRestoreConfig = false;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
//restore table redrawing
|
|
1068
|
+
restoreRedraw (){
|
|
1069
|
+
this.redrawBlock = false;
|
|
1070
|
+
|
|
1071
|
+
if(this.redrawBlockRestoreConfig){
|
|
1072
|
+
this.refreshActiveData(this.redrawBlockRestoreConfig.handler, this.redrawBlockRestoreConfig.skipStage, this.redrawBlockRestoreConfig.renderInPosition);
|
|
1073
|
+
|
|
1074
|
+
this.redrawBlockRestoreConfig = false;
|
|
1075
|
+
}else{
|
|
1076
|
+
if(this.redrawBlockRenderInPosition){
|
|
1077
|
+
this.reRenderInPosition();
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
this.redrawBlockRenderInPosition = false;
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
//redraw table
|
|
1085
|
+
redraw (force){
|
|
1086
|
+
var left = this.scrollLeft;
|
|
1087
|
+
|
|
1088
|
+
this.adjustTableSize();
|
|
1089
|
+
|
|
1090
|
+
this.table.tableWidth = this.table.element.clientWidth;
|
|
1091
|
+
|
|
1092
|
+
if(!force){
|
|
1093
|
+
this.reRenderInPosition();
|
|
1094
|
+
this.scrollHorizontal(left);
|
|
1095
|
+
}else{
|
|
1096
|
+
this.renderTable();
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
resetScroll(){
|
|
1101
|
+
this.element.scrollLeft = 0;
|
|
1102
|
+
this.element.scrollTop = 0;
|
|
1103
|
+
|
|
1104
|
+
if(this.table.browser === "ie"){
|
|
1105
|
+
var event = document.createEvent("Event");
|
|
1106
|
+
event.initEvent("scroll", false, true);
|
|
1107
|
+
this.element.dispatchEvent(event);
|
|
1108
|
+
}else{
|
|
1109
|
+
this.element.dispatchEvent(new Event('scroll'));
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
}
|