tabulator-tables 6.5.0 → 6.5.1
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/dist/js/tabulator.js +1 -1
- package/dist/js/tabulator.min.js +1 -1
- package/dist/js/tabulator_esm.js +1 -1
- package/dist/js/tabulator_esm.min.js +1 -1
- package/dist/js/tabulator_esm.min.mjs +1 -1
- package/dist/js/tabulator_esm.mjs +1 -1
- package/package.json +2 -1
- package/src/js/builds/esm.js +16 -0
- package/src/js/builds/jquery_wrapper.js +63 -0
- package/src/js/builds/usd.js +1 -0
- package/src/js/core/ColumnManager.js +789 -0
- package/src/js/core/CoreFeature.js +140 -0
- package/src/js/core/FooterManager.js +102 -0
- package/src/js/core/Module.js +140 -0
- package/src/js/core/RowManager.js +1140 -0
- package/src/js/core/Tabulator.js +928 -0
- package/src/js/core/TabulatorFull.js +21 -0
- package/src/js/core/cell/Cell.js +299 -0
- package/src/js/core/cell/CellComponent.js +79 -0
- package/src/js/core/column/Column.js +978 -0
- package/src/js/core/column/ColumnComponent.js +151 -0
- package/src/js/core/column/defaults/options.js +18 -0
- package/src/js/core/defaults/options.js +66 -0
- package/src/js/core/modules/core.js +3 -0
- package/src/js/core/modules/optional.js +37 -0
- package/src/js/core/rendering/Renderer.js +204 -0
- package/src/js/core/rendering/renderers/BasicHorizontal.js +27 -0
- package/src/js/core/rendering/renderers/BasicVertical.js +103 -0
- package/src/js/core/rendering/renderers/VirtualDomHorizontal.js +587 -0
- package/src/js/core/rendering/renderers/VirtualDomVertical.js +642 -0
- package/src/js/core/row/PseudoRow.js +47 -0
- package/src/js/core/row/Row.js +487 -0
- package/src/js/core/row/RowComponent.js +94 -0
- package/src/js/core/tools/Alert.js +66 -0
- package/src/js/core/tools/ComponentFunctionBinder.js +32 -0
- package/src/js/core/tools/DataLoader.js +128 -0
- package/src/js/core/tools/DependencyRegistry.js +82 -0
- package/src/js/core/tools/DeprecationAdvisor.js +51 -0
- package/src/js/core/tools/ExternalEventBus.js +105 -0
- package/src/js/core/tools/Helpers.js +66 -0
- package/src/js/core/tools/InteractionMonitor.js +329 -0
- package/src/js/core/tools/InternalEventBus.js +162 -0
- package/src/js/core/tools/ModuleBinder.js +153 -0
- package/src/js/core/tools/OptionsList.js +45 -0
- package/src/js/core/tools/Popup.js +317 -0
- package/src/js/core/tools/TableRegistry.js +65 -0
- package/src/js/modules/Accessor/Accessor.js +115 -0
- package/src/js/modules/Accessor/defaults/accessors.js +5 -0
- package/src/js/modules/Ajax/Ajax.js +142 -0
- package/src/js/modules/Ajax/defaults/config.js +3 -0
- package/src/js/modules/Ajax/defaults/contentTypeFormatters.js +45 -0
- package/src/js/modules/Ajax/defaults/loaderPromise.js +87 -0
- package/src/js/modules/Ajax/defaults/urlGenerator.js +44 -0
- package/src/js/modules/Clipboard/Clipboard.js +282 -0
- package/src/js/modules/Clipboard/defaults/pasteActions.js +11 -0
- package/src/js/modules/Clipboard/defaults/pasteParsers.js +75 -0
- package/src/js/modules/Clipboard/extensions/extensions.js +9 -0
- package/src/js/modules/Clipboard/extensions/keybindings/actions.js +9 -0
- package/src/js/modules/Clipboard/extensions/keybindings/bindings.js +3 -0
- package/src/js/modules/ColumnCalcs/CalcComponent.js +46 -0
- package/src/js/modules/ColumnCalcs/ColumnCalcs.js +586 -0
- package/src/js/modules/ColumnCalcs/defaults/calculations.js +93 -0
- package/src/js/modules/Comms/Comms.js +49 -0
- package/src/js/modules/DataTree/DataTree.js +620 -0
- package/src/js/modules/Download/Download.js +146 -0
- package/src/js/modules/Download/defaults/downloaders/csv.js +61 -0
- package/src/js/modules/Download/defaults/downloaders/html.js +5 -0
- package/src/js/modules/Download/defaults/downloaders/json.js +34 -0
- package/src/js/modules/Download/defaults/downloaders/jsonLines.js +32 -0
- package/src/js/modules/Download/defaults/downloaders/pdf.js +113 -0
- package/src/js/modules/Download/defaults/downloaders/xlsx.js +103 -0
- package/src/js/modules/Download/defaults/downloaders.js +15 -0
- package/src/js/modules/Edit/Edit.js +845 -0
- package/src/js/modules/Edit/List.js +1060 -0
- package/src/js/modules/Edit/defaults/editors/adaptable.js +37 -0
- package/src/js/modules/Edit/defaults/editors/date.js +144 -0
- package/src/js/modules/Edit/defaults/editors/datetime.js +131 -0
- package/src/js/modules/Edit/defaults/editors/input.js +77 -0
- package/src/js/modules/Edit/defaults/editors/list.js +7 -0
- package/src/js/modules/Edit/defaults/editors/number.js +110 -0
- package/src/js/modules/Edit/defaults/editors/progress.js +127 -0
- package/src/js/modules/Edit/defaults/editors/range.js +81 -0
- package/src/js/modules/Edit/defaults/editors/star.js +146 -0
- package/src/js/modules/Edit/defaults/editors/textarea.js +123 -0
- package/src/js/modules/Edit/defaults/editors/tickCross.js +95 -0
- package/src/js/modules/Edit/defaults/editors/time.js +132 -0
- package/src/js/modules/Edit/defaults/editors.js +27 -0
- package/src/js/modules/Edit/inputMask.js +74 -0
- package/src/js/modules/Export/Export.js +654 -0
- package/src/js/modules/Export/ExportColumn.js +9 -0
- package/src/js/modules/Export/ExportRow.js +8 -0
- package/src/js/modules/Export/defaults/columnLookups.js +3 -0
- package/src/js/modules/Export/defaults/rowLookups.js +18 -0
- package/src/js/modules/Filter/Filter.js +902 -0
- package/src/js/modules/Filter/defaults/filters.js +215 -0
- package/src/js/modules/Format/Format.js +200 -0
- package/src/js/modules/Format/defaults/formatters/adaptable.js +32 -0
- package/src/js/modules/Format/defaults/formatters/array.js +30 -0
- package/src/js/modules/Format/defaults/formatters/buttonCross.js +3 -0
- package/src/js/modules/Format/defaults/formatters/buttonTick.js +3 -0
- package/src/js/modules/Format/defaults/formatters/color.js +4 -0
- package/src/js/modules/Format/defaults/formatters/datetime.js +39 -0
- package/src/js/modules/Format/defaults/formatters/datetimediff.js +43 -0
- package/src/js/modules/Format/defaults/formatters/handle.js +4 -0
- package/src/js/modules/Format/defaults/formatters/html.js +3 -0
- package/src/js/modules/Format/defaults/formatters/image.js +40 -0
- package/src/js/modules/Format/defaults/formatters/json.js +12 -0
- package/src/js/modules/Format/defaults/formatters/link.js +82 -0
- package/src/js/modules/Format/defaults/formatters/lookup.js +10 -0
- package/src/js/modules/Format/defaults/formatters/money.js +44 -0
- package/src/js/modules/Format/defaults/formatters/plaintext.js +3 -0
- package/src/js/modules/Format/defaults/formatters/progress.js +133 -0
- package/src/js/modules/Format/defaults/formatters/rownum.js +14 -0
- package/src/js/modules/Format/defaults/formatters/star.js +38 -0
- package/src/js/modules/Format/defaults/formatters/textarea.js +4 -0
- package/src/js/modules/Format/defaults/formatters/tickCross.js +22 -0
- package/src/js/modules/Format/defaults/formatters/toggle.js +48 -0
- package/src/js/modules/Format/defaults/formatters/traffic.js +47 -0
- package/src/js/modules/Format/defaults/formatters.js +47 -0
- package/src/js/modules/FrozenColumns/FrozenColumns.js +302 -0
- package/src/js/modules/FrozenRows/FrozenRows.js +175 -0
- package/src/js/modules/GroupRows/Group.js +615 -0
- package/src/js/modules/GroupRows/GroupComponent.js +69 -0
- package/src/js/modules/GroupRows/GroupRows.js +636 -0
- package/src/js/modules/History/History.js +172 -0
- package/src/js/modules/History/defaults/redoers.js +31 -0
- package/src/js/modules/History/defaults/undoers.js +33 -0
- package/src/js/modules/History/extensions/extensions.js +9 -0
- package/src/js/modules/History/extensions/keybindings/actions.js +27 -0
- package/src/js/modules/History/extensions/keybindings/bindings.js +4 -0
- package/src/js/modules/HtmlTableImport/HtmlTableImport.js +180 -0
- package/src/js/modules/Import/Import.js +303 -0
- package/src/js/modules/Import/defaults/importers/array.js +3 -0
- package/src/js/modules/Import/defaults/importers/csv.js +61 -0
- package/src/js/modules/Import/defaults/importers/json.js +8 -0
- package/src/js/modules/Import/defaults/importers/xlsx.js +7 -0
- package/src/js/modules/Import/defaults/importers.js +11 -0
- package/src/js/modules/Interaction/Interaction.js +339 -0
- package/src/js/modules/Keybindings/Keybindings.js +198 -0
- package/src/js/modules/Keybindings/defaults/actions.js +90 -0
- package/src/js/modules/Keybindings/defaults/bindings.js +12 -0
- package/src/js/modules/Layout/Layout.js +66 -0
- package/src/js/modules/Layout/defaults/modes/fitColumns.js +171 -0
- package/src/js/modules/Layout/defaults/modes/fitData.js +10 -0
- package/src/js/modules/Layout/defaults/modes/fitDataGeneral.js +10 -0
- package/src/js/modules/Layout/defaults/modes/fitDataStretch.js +40 -0
- package/src/js/modules/Layout/defaults/modes.js +12 -0
- package/src/js/modules/Localize/Localize.js +184 -0
- package/src/js/modules/Localize/defaults/langs.js +37 -0
- package/src/js/modules/Menu/Menu.js +302 -0
- package/src/js/modules/MoveColumns/MoveColumns.js +311 -0
- package/src/js/modules/MoveRows/MoveRows.js +604 -0
- package/src/js/modules/MoveRows/defaults/receivers.js +30 -0
- package/src/js/modules/MoveRows/defaults/senders.js +5 -0
- package/src/js/modules/Mutator/Mutator.js +164 -0
- package/src/js/modules/Mutator/defaults/mutators.js +1 -0
- package/src/js/modules/Page/Page.js +891 -0
- package/src/js/modules/Page/defaults/pageCounters/pages.js +33 -0
- package/src/js/modules/Page/defaults/pageCounters/rows.js +40 -0
- package/src/js/modules/Page/defaults/pageCounters.js +8 -0
- package/src/js/modules/Persistence/Persistence.js +473 -0
- package/src/js/modules/Persistence/defaults/readers.js +29 -0
- package/src/js/modules/Persistence/defaults/writers.js +13 -0
- package/src/js/modules/Popup/Popup.js +227 -0
- package/src/js/modules/Print/Print.js +136 -0
- package/src/js/modules/ReactiveData/ReactiveData.js +416 -0
- package/src/js/modules/ResizeColumns/ResizeColumns.js +365 -0
- package/src/js/modules/ResizeRows/ResizeRows.js +145 -0
- package/src/js/modules/ResizeTable/ResizeTable.js +158 -0
- package/src/js/modules/ResponsiveLayout/ResponsiveLayout.js +354 -0
- package/src/js/modules/ResponsiveLayout/extensions/extensions.js +9 -0
- package/src/js/modules/ResponsiveLayout/extensions/formatters/responsiveCollapse.js +44 -0
- package/src/js/modules/SelectRange/Range.js +366 -0
- package/src/js/modules/SelectRange/RangeComponent.js +91 -0
- package/src/js/modules/SelectRange/SelectRange.js +993 -0
- package/src/js/modules/SelectRange/extensions/clipboard/pasteActions.js +45 -0
- package/src/js/modules/SelectRange/extensions/clipboard/pasteParsers.js +57 -0
- package/src/js/modules/SelectRange/extensions/export/columnLookups.js +11 -0
- package/src/js/modules/SelectRange/extensions/export/rowLookups.js +5 -0
- package/src/js/modules/SelectRange/extensions/extensions.js +21 -0
- package/src/js/modules/SelectRange/extensions/keybindings/actions.js +38 -0
- package/src/js/modules/SelectRange/extensions/keybindings/bindings.js +14 -0
- package/src/js/modules/SelectRow/SelectRow.js +499 -0
- package/src/js/modules/SelectRow/extensions/extensions.js +9 -0
- package/src/js/modules/SelectRow/extensions/formatters/rowSelection.js +60 -0
- package/src/js/modules/Sort/Sort.js +480 -0
- package/src/js/modules/Sort/defaults/sorters/alphanum.js +44 -0
- package/src/js/modules/Sort/defaults/sorters/array.js +82 -0
- package/src/js/modules/Sort/defaults/sorters/boolean.js +7 -0
- package/src/js/modules/Sort/defaults/sorters/date.js +10 -0
- package/src/js/modules/Sort/defaults/sorters/datetime.js +48 -0
- package/src/js/modules/Sort/defaults/sorters/exists.js +7 -0
- package/src/js/modules/Sort/defaults/sorters/number.js +40 -0
- package/src/js/modules/Sort/defaults/sorters/string.js +34 -0
- package/src/js/modules/Sort/defaults/sorters/time.js +10 -0
- package/src/js/modules/Sort/defaults/sorters.js +21 -0
- package/src/js/modules/Spreadsheet/GridCalculator.js +64 -0
- package/src/js/modules/Spreadsheet/Sheet.js +243 -0
- package/src/js/modules/Spreadsheet/SheetComponent.js +59 -0
- package/src/js/modules/Spreadsheet/Spreadsheet.js +309 -0
- package/src/js/modules/Tooltip/Tooltip.js +128 -0
- package/src/js/modules/Validate/Validate.js +303 -0
- package/src/js/modules/Validate/defaults/validators.js +150 -0
- package/src/scss/tabulator.scss +1693 -0
- package/src/scss/themes/bootstrap/tabulator_bootstrap3.scss +302 -0
- package/src/scss/themes/bootstrap/tabulator_bootstrap4.scss +589 -0
- package/src/scss/themes/bootstrap/tabulator_bootstrap5.scss +979 -0
- package/src/scss/themes/bootstrap/variables3.scss +872 -0
- package/src/scss/themes/bootstrap/variables4.scss +1059 -0
- package/src/scss/themes/bootstrap/variables5.scss +1967 -0
- package/src/scss/themes/bulma/tabulator_bulma.scss +316 -0
- package/src/scss/themes/bulma/variables.scss +198 -0
- package/src/scss/themes/materialize/tabulator_materialize.scss +318 -0
- package/src/scss/themes/materialize/variables.scss +71 -0
- package/src/scss/themes/semanticui/tabulator_semanticui.scss +623 -0
- package/src/scss/themes/semanticui/variables.scss +843 -0
- package/src/scss/themes/semanticui/variables_table.scss +248 -0
- package/src/scss/themes/tabulator_midnight.scss +235 -0
- package/src/scss/themes/tabulator_modern.scss +308 -0
- package/src/scss/themes/tabulator_simple.scss +143 -0
- package/src/scss/themes/tabulator_site.scss +267 -0
- package/src/scss/themes/tabulator_site_dark.scss +496 -0
|
@@ -0,0 +1,1060 @@
|
|
|
1
|
+
import maskInput from './inputMask.js';
|
|
2
|
+
import urlBuilder from '../Ajax/defaults/urlGenerator.js';
|
|
3
|
+
|
|
4
|
+
export default class Edit{
|
|
5
|
+
constructor(editor, cell, onRendered, success, cancel, editorParams){
|
|
6
|
+
this.edit = editor;
|
|
7
|
+
this.table = editor.table;
|
|
8
|
+
this.cell = cell;
|
|
9
|
+
this.params = this._initializeParams(editorParams);
|
|
10
|
+
|
|
11
|
+
this.data = [];
|
|
12
|
+
this.displayItems = [];
|
|
13
|
+
this.currentItems = [];
|
|
14
|
+
this.focusedItem = null;
|
|
15
|
+
|
|
16
|
+
this.input = this._createInputElement();
|
|
17
|
+
this.listEl = this._createListElement();
|
|
18
|
+
|
|
19
|
+
this.initialValues = null;
|
|
20
|
+
|
|
21
|
+
this.isFilter = cell.getType() === "header";
|
|
22
|
+
|
|
23
|
+
this.filterTimeout = null;
|
|
24
|
+
this.filtered = false;
|
|
25
|
+
this.typing = false;
|
|
26
|
+
|
|
27
|
+
this.values = [];
|
|
28
|
+
this.popup = null;
|
|
29
|
+
|
|
30
|
+
this.listIteration = 0;
|
|
31
|
+
|
|
32
|
+
this.lastAction="";
|
|
33
|
+
this.filterTerm="";
|
|
34
|
+
|
|
35
|
+
this.blurable = true;
|
|
36
|
+
|
|
37
|
+
this.actions = {
|
|
38
|
+
success:success,
|
|
39
|
+
cancel:cancel
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
this._deprecatedOptionsCheck();
|
|
43
|
+
this._initializeValue();
|
|
44
|
+
|
|
45
|
+
onRendered(this._onRendered.bind(this));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_deprecatedOptionsCheck(){
|
|
49
|
+
// if(this.params.listItemFormatter){
|
|
50
|
+
// this.cell.getTable().deprecationAdvisor.msg("The listItemFormatter editor param has been deprecated, please see the latest editor documentation for updated options");
|
|
51
|
+
// }
|
|
52
|
+
|
|
53
|
+
// if(this.params.sortValuesList){
|
|
54
|
+
// this.cell.getTable().deprecationAdvisor.msg("The sortValuesList editor param has been deprecated, please see the latest editor documentation for updated options");
|
|
55
|
+
// }
|
|
56
|
+
|
|
57
|
+
// if(this.params.searchFunc){
|
|
58
|
+
// this.cell.getTable().deprecationAdvisor.msg("The searchFunc editor param has been deprecated, please see the latest editor documentation for updated options");
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// if(this.params.searchingPlaceholder){
|
|
62
|
+
// this.cell.getTable().deprecationAdvisor.msg("The searchingPlaceholder editor param has been deprecated, please see the latest editor documentation for updated options");
|
|
63
|
+
// }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_initializeValue(){
|
|
67
|
+
var initialValue = this.cell.getValue();
|
|
68
|
+
|
|
69
|
+
if(typeof initialValue === "undefined" && typeof this.params.defaultValue !== "undefined"){
|
|
70
|
+
initialValue = this.params.defaultValue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.initialValues = this.params.multiselect ? initialValue : [initialValue];
|
|
74
|
+
|
|
75
|
+
if(this.isFilter){
|
|
76
|
+
this.input.value = this.initialValues ? this.initialValues.join(",") : "";
|
|
77
|
+
this.headerFilterInitialListGen();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
_onRendered(){
|
|
82
|
+
var cellEl = this.cell.getElement();
|
|
83
|
+
|
|
84
|
+
function clickStop(e){
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if(!this.isFilter){
|
|
89
|
+
this.input.style.height = "100%";
|
|
90
|
+
this.input.focus({preventScroll: true});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
cellEl.addEventListener("click", clickStop);
|
|
95
|
+
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
cellEl.removeEventListener("click", clickStop);
|
|
98
|
+
}, 1000);
|
|
99
|
+
|
|
100
|
+
this.input.addEventListener("mousedown", this._preventPopupBlur.bind(this));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_createListElement(){
|
|
104
|
+
var listEl = document.createElement("div");
|
|
105
|
+
listEl.classList.add("tabulator-edit-list");
|
|
106
|
+
|
|
107
|
+
listEl.addEventListener("mousedown", this._preventBlur.bind(this));
|
|
108
|
+
listEl.addEventListener("keydown", this._inputKeyDown.bind(this));
|
|
109
|
+
|
|
110
|
+
return listEl;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_setListWidth(){
|
|
114
|
+
var element = this.isFilter ? this.input : this.cell.getElement();
|
|
115
|
+
|
|
116
|
+
this.listEl.style.minWidth = element.offsetWidth + "px";
|
|
117
|
+
|
|
118
|
+
if(this.params.maxWidth){
|
|
119
|
+
if(this.params.maxWidth === true){
|
|
120
|
+
this.listEl.style.maxWidth = element.offsetWidth + "px";
|
|
121
|
+
}else if(typeof this.params.maxWidth === "number"){
|
|
122
|
+
this.listEl.style.maxWidth = this.params.maxWidth + "px";
|
|
123
|
+
}else{
|
|
124
|
+
this.listEl.style.maxWidth = this.params.maxWidth;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
_createInputElement(){
|
|
131
|
+
var attribs = this.params.elementAttributes;
|
|
132
|
+
var input = document.createElement("input");
|
|
133
|
+
|
|
134
|
+
input.setAttribute("type", this.params.clearable ? "search" : "text");
|
|
135
|
+
|
|
136
|
+
input.style.padding = "4px";
|
|
137
|
+
input.style.width = "100%";
|
|
138
|
+
input.style.boxSizing = "border-box";
|
|
139
|
+
|
|
140
|
+
if(!this.params.autocomplete){
|
|
141
|
+
input.style.cursor = "default";
|
|
142
|
+
input.style.caretColor = "transparent";
|
|
143
|
+
// input.readOnly = (this.edit.currentCell != false);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if(attribs && typeof attribs == "object"){
|
|
147
|
+
for (let key in attribs){
|
|
148
|
+
if(key.charAt(0) == "+"){
|
|
149
|
+
key = key.slice(1);
|
|
150
|
+
input.setAttribute(key, input.getAttribute(key) + attribs["+" + key]);
|
|
151
|
+
}else{
|
|
152
|
+
input.setAttribute(key, attribs[key]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if(this.params.mask){
|
|
158
|
+
maskInput(input, this.params);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this._bindInputEvents(input);
|
|
162
|
+
|
|
163
|
+
return input;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_initializeParams(params){
|
|
167
|
+
var valueKeys = ["values", "valuesURL", "valuesLookup"],
|
|
168
|
+
valueCheck;
|
|
169
|
+
|
|
170
|
+
params = Object.assign({}, params);
|
|
171
|
+
|
|
172
|
+
params.verticalNavigation = params.verticalNavigation || "editor";
|
|
173
|
+
params.placeholderLoading = typeof params.placeholderLoading === "undefined" ? "Searching ..." : params.placeholderLoading;
|
|
174
|
+
params.placeholderEmpty = typeof params.placeholderEmpty === "undefined" ? "No Results Found" : params.placeholderEmpty;
|
|
175
|
+
params.filterDelay = typeof params.filterDelay === "undefined" ? 300 : params.filterDelay;
|
|
176
|
+
|
|
177
|
+
params.emptyValue = Object.keys(params).includes("emptyValue") ? params.emptyValue : "";
|
|
178
|
+
|
|
179
|
+
valueCheck = Object.keys(params).filter(key => valueKeys.includes(key)).length;
|
|
180
|
+
|
|
181
|
+
if(!valueCheck){
|
|
182
|
+
console.warn("list editor config error - either the values, valuesURL, or valuesLookup option must be set");
|
|
183
|
+
}else if(valueCheck > 1){
|
|
184
|
+
console.warn("list editor config error - only one of the values, valuesURL, or valuesLookup options can be set on the same editor");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if(params.autocomplete){
|
|
188
|
+
if(params.multiselect){
|
|
189
|
+
params.multiselect = false;
|
|
190
|
+
console.warn("list editor config error - multiselect option is not available when autocomplete is enabled");
|
|
191
|
+
}
|
|
192
|
+
}else{
|
|
193
|
+
if(params.freetext){
|
|
194
|
+
params.freetext = false;
|
|
195
|
+
console.warn("list editor config error - freetext option is only available when autocomplete is enabled");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if(params.filterFunc){
|
|
199
|
+
params.filterFunc = false;
|
|
200
|
+
console.warn("list editor config error - filterFunc option is only available when autocomplete is enabled");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if(params.filterRemote){
|
|
204
|
+
params.filterRemote = false;
|
|
205
|
+
console.warn("list editor config error - filterRemote option is only available when autocomplete is enabled");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if(params.mask){
|
|
209
|
+
params.mask = false;
|
|
210
|
+
console.warn("list editor config error - mask option is only available when autocomplete is enabled");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if(params.allowEmpty){
|
|
214
|
+
params.allowEmpty = false;
|
|
215
|
+
console.warn("list editor config error - allowEmpty option is only available when autocomplete is enabled");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if(params.listOnEmpty){
|
|
219
|
+
params.listOnEmpty = false;
|
|
220
|
+
console.warn("list editor config error - listOnEmpty option is only available when autocomplete is enabled");
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if(params.filterRemote && !(typeof params.valuesLookup === "function" || params.valuesURL)){
|
|
225
|
+
params.filterRemote = false;
|
|
226
|
+
console.warn("list editor config error - filterRemote option should only be used when values list is populated from a remote source");
|
|
227
|
+
}
|
|
228
|
+
return params;
|
|
229
|
+
}
|
|
230
|
+
//////////////////////////////////////
|
|
231
|
+
////////// Event Handling ////////////
|
|
232
|
+
//////////////////////////////////////
|
|
233
|
+
|
|
234
|
+
_bindInputEvents(input){
|
|
235
|
+
input.addEventListener("focus", this._inputFocus.bind(this));
|
|
236
|
+
input.addEventListener("click", this._inputClick.bind(this));
|
|
237
|
+
input.addEventListener("blur", this._inputBlur.bind(this));
|
|
238
|
+
input.addEventListener("keydown", this._inputKeyDown.bind(this));
|
|
239
|
+
input.addEventListener("search", this._inputSearch.bind(this));
|
|
240
|
+
|
|
241
|
+
if(this.params.autocomplete){
|
|
242
|
+
input.addEventListener("keyup", this._inputKeyUp.bind(this));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
_inputFocus(e){
|
|
248
|
+
this.rebuildOptionsList();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
_filter(){
|
|
252
|
+
if(this.params.filterRemote){
|
|
253
|
+
clearTimeout(this.filterTimeout);
|
|
254
|
+
|
|
255
|
+
this.filterTimeout = setTimeout(() => {
|
|
256
|
+
this.rebuildOptionsList();
|
|
257
|
+
}, this.params.filterDelay);
|
|
258
|
+
}else{
|
|
259
|
+
this._filterList();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
_inputClick(e){
|
|
264
|
+
e.stopPropagation();
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
_inputBlur(e){
|
|
268
|
+
if(this.blurable){
|
|
269
|
+
if(this.popup){
|
|
270
|
+
this.popup.hide();
|
|
271
|
+
}else{
|
|
272
|
+
this._resolveValue(true);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
_inputSearch(){
|
|
278
|
+
this._clearChoices();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
_inputKeyDown(e){
|
|
282
|
+
switch(e.key){
|
|
283
|
+
|
|
284
|
+
case "ArrowUp":
|
|
285
|
+
this._keyUp(e);
|
|
286
|
+
break;
|
|
287
|
+
|
|
288
|
+
case "ArrowDown":
|
|
289
|
+
this._keyDown(e);
|
|
290
|
+
break;
|
|
291
|
+
|
|
292
|
+
case "ArrowLeft":
|
|
293
|
+
case "ArrowRight":
|
|
294
|
+
this._keySide(e);
|
|
295
|
+
break;
|
|
296
|
+
|
|
297
|
+
case "Enter":
|
|
298
|
+
this._keyEnter();
|
|
299
|
+
break;
|
|
300
|
+
|
|
301
|
+
case "Escape":
|
|
302
|
+
this._keyEsc();
|
|
303
|
+
break;
|
|
304
|
+
|
|
305
|
+
case "Home":
|
|
306
|
+
case "End":
|
|
307
|
+
this._keyHomeEnd(e);
|
|
308
|
+
break;
|
|
309
|
+
|
|
310
|
+
case "Tab":
|
|
311
|
+
this._keyTab(e);
|
|
312
|
+
break;
|
|
313
|
+
|
|
314
|
+
default:
|
|
315
|
+
this._keySelectLetter(e);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
_inputKeyUp(e){
|
|
320
|
+
switch(e.key){
|
|
321
|
+
case "ArrowUp":
|
|
322
|
+
case "ArrowLeft":
|
|
323
|
+
case "ArrowRight":
|
|
324
|
+
case "ArrowDown":
|
|
325
|
+
case "Enter":
|
|
326
|
+
case "Escape":
|
|
327
|
+
break;
|
|
328
|
+
|
|
329
|
+
default:
|
|
330
|
+
this._keyAutoCompLetter(e);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
_preventPopupBlur(){
|
|
335
|
+
if(this.popup){
|
|
336
|
+
this.popup.blockHide();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
setTimeout(() =>{
|
|
340
|
+
if(this.popup){
|
|
341
|
+
this.popup.restoreHide();
|
|
342
|
+
}
|
|
343
|
+
}, 10);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
_preventBlur(){
|
|
347
|
+
this.blurable = false;
|
|
348
|
+
|
|
349
|
+
setTimeout(() =>{
|
|
350
|
+
this.blurable = true;
|
|
351
|
+
}, 10);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
//////////////////////////////////////
|
|
355
|
+
//////// Keyboard Navigation /////////
|
|
356
|
+
//////////////////////////////////////
|
|
357
|
+
|
|
358
|
+
_keyTab(e){
|
|
359
|
+
if(this.params.autocomplete && this.lastAction === "typing"){
|
|
360
|
+
this._resolveValue(true);
|
|
361
|
+
}else{
|
|
362
|
+
if(this.focusedItem){
|
|
363
|
+
this._chooseItem(this.focusedItem, true);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
_keyUp(e){
|
|
369
|
+
var index = this.displayItems.indexOf(this.focusedItem);
|
|
370
|
+
|
|
371
|
+
if(this.params.verticalNavigation == "editor" || (this.params.verticalNavigation == "hybrid" && index)){
|
|
372
|
+
e.stopImmediatePropagation();
|
|
373
|
+
e.stopPropagation();
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
|
|
376
|
+
if(index > 0){
|
|
377
|
+
this._focusItem(this.displayItems[index - 1]);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
_keyDown(e){
|
|
383
|
+
var index = this.displayItems.indexOf(this.focusedItem);
|
|
384
|
+
|
|
385
|
+
if(this.params.verticalNavigation == "editor" || (this.params.verticalNavigation == "hybrid" && index < this.displayItems.length - 1)){
|
|
386
|
+
e.stopImmediatePropagation();
|
|
387
|
+
e.stopPropagation();
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
|
|
390
|
+
if(index < this.displayItems.length - 1){
|
|
391
|
+
if(index == -1){
|
|
392
|
+
this._focusItem(this.displayItems[0]);
|
|
393
|
+
}else{
|
|
394
|
+
this._focusItem(this.displayItems[index + 1]);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
_keySide(e){
|
|
401
|
+
if(!this.params.autocomplete){
|
|
402
|
+
e.stopImmediatePropagation();
|
|
403
|
+
e.stopPropagation();
|
|
404
|
+
e.preventDefault();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
_keyEnter(e){
|
|
409
|
+
if(this.params.autocomplete && this.lastAction === "typing"){
|
|
410
|
+
this._resolveValue(true);
|
|
411
|
+
}else{
|
|
412
|
+
if(this.focusedItem){
|
|
413
|
+
this._chooseItem(this.focusedItem);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
_keyEsc(e){
|
|
419
|
+
this._cancel();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
_keyHomeEnd(e){
|
|
423
|
+
if(this.params.autocomplete){
|
|
424
|
+
//prevent table navigation while using input element
|
|
425
|
+
e.stopImmediatePropagation();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
_keySelectLetter(e){
|
|
430
|
+
if(!this.params.autocomplete){
|
|
431
|
+
// if(this.edit.currentCell === false){
|
|
432
|
+
e.preventDefault();
|
|
433
|
+
// }
|
|
434
|
+
|
|
435
|
+
if(e.key.length === 1){
|
|
436
|
+
this._scrollToValue(e.key.toUpperCase().charCodeAt(0));
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
_keyAutoCompLetter(e){
|
|
442
|
+
this._filter();
|
|
443
|
+
this.lastAction = "typing";
|
|
444
|
+
this.typing = true;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
_scrollToValue(char){
|
|
449
|
+
clearTimeout(this.filterTimeout);
|
|
450
|
+
|
|
451
|
+
var character = String.fromCharCode(char).toLowerCase();
|
|
452
|
+
this.filterTerm += character.toLowerCase();
|
|
453
|
+
|
|
454
|
+
var match = this.displayItems.find((item) => {
|
|
455
|
+
return typeof item.label !== "undefined" && item.label.toLowerCase().startsWith(this.filterTerm);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
if(match){
|
|
459
|
+
this._focusItem(match);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
this.filterTimeout = setTimeout(() => {
|
|
463
|
+
this.filterTerm = "";
|
|
464
|
+
}, 800);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
_focusItem(item){
|
|
468
|
+
this.lastAction = "focus";
|
|
469
|
+
|
|
470
|
+
if(this.focusedItem && this.focusedItem.element){
|
|
471
|
+
this.focusedItem.element.classList.remove("focused");
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
this.focusedItem = item;
|
|
475
|
+
|
|
476
|
+
if(item && item.element){
|
|
477
|
+
item.element.classList.add("focused");
|
|
478
|
+
item.element.scrollIntoView({behavior: 'smooth', block: 'nearest', inline: 'start'});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
//////////////////////////////////////
|
|
484
|
+
/////// Data List Generation /////////
|
|
485
|
+
//////////////////////////////////////
|
|
486
|
+
headerFilterInitialListGen(){
|
|
487
|
+
this._generateOptions(true);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
rebuildOptionsList(){
|
|
491
|
+
this._generateOptions()
|
|
492
|
+
.then(this._sortOptions.bind(this))
|
|
493
|
+
.then(this._buildList.bind(this))
|
|
494
|
+
.then(this._showList.bind(this))
|
|
495
|
+
.catch((e) => {
|
|
496
|
+
if(!Number.isInteger(e)){
|
|
497
|
+
console.error("List generation error", e);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
_filterList(){
|
|
503
|
+
this._buildList(this._filterOptions());
|
|
504
|
+
this._showList();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
_generateOptions(silent){
|
|
508
|
+
var values = [];
|
|
509
|
+
var iteration = ++ this.listIteration;
|
|
510
|
+
|
|
511
|
+
this.filtered = false;
|
|
512
|
+
|
|
513
|
+
if(this.params.values){
|
|
514
|
+
values = this.params.values;
|
|
515
|
+
}else if (this.params.valuesURL){
|
|
516
|
+
values = this._ajaxRequest(this.params.valuesURL, this.input.value);
|
|
517
|
+
}else{
|
|
518
|
+
if(typeof this.params.valuesLookup === "function"){
|
|
519
|
+
values = this.params.valuesLookup(this.cell, this.input.value);
|
|
520
|
+
}else if(this.params.valuesLookup){
|
|
521
|
+
values = this._uniqueColumnValues(this.params.valuesLookupField);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if(values instanceof Promise){
|
|
526
|
+
if(!silent){
|
|
527
|
+
this._addPlaceholder(this.params.placeholderLoading);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return values.then()
|
|
531
|
+
.then((responseValues) => {
|
|
532
|
+
if(this.listIteration === iteration){
|
|
533
|
+
return this._parseList(responseValues);
|
|
534
|
+
}else{
|
|
535
|
+
return Promise.reject(iteration);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
}else{
|
|
539
|
+
return Promise.resolve(this._parseList(values));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
_addPlaceholder(contents){
|
|
544
|
+
var placeholder = document.createElement("div");
|
|
545
|
+
|
|
546
|
+
if(typeof contents === "function"){
|
|
547
|
+
contents = contents(this.cell.getComponent(), this.listEl);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if(contents){
|
|
551
|
+
this._clearList();
|
|
552
|
+
|
|
553
|
+
if(contents instanceof HTMLElement){
|
|
554
|
+
placeholder = contents;
|
|
555
|
+
}else{
|
|
556
|
+
placeholder.classList.add("tabulator-edit-list-placeholder");
|
|
557
|
+
placeholder.innerHTML = contents;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
this.listEl.appendChild(placeholder);
|
|
561
|
+
|
|
562
|
+
this._showList();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
_ajaxRequest(url, term){
|
|
567
|
+
var params = this.params.filterRemote ? {term:term} : {};
|
|
568
|
+
url = urlBuilder(url, {}, params);
|
|
569
|
+
|
|
570
|
+
return fetch(url)
|
|
571
|
+
.then((response)=>{
|
|
572
|
+
if(response.ok) {
|
|
573
|
+
return response.json()
|
|
574
|
+
.catch((error)=>{
|
|
575
|
+
console.warn("List Ajax Load Error - Invalid JSON returned", error);
|
|
576
|
+
return Promise.reject(error);
|
|
577
|
+
});
|
|
578
|
+
}else{
|
|
579
|
+
console.error("List Ajax Load Error - Connection Error: " + response.status, response.statusText);
|
|
580
|
+
return Promise.reject(response);
|
|
581
|
+
}
|
|
582
|
+
})
|
|
583
|
+
.catch((error)=>{
|
|
584
|
+
console.error("List Ajax Load Error - Connection Error: ", error);
|
|
585
|
+
return Promise.reject(error);
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
_uniqueColumnValues(field){
|
|
590
|
+
var output = {},
|
|
591
|
+
data = this.table.getData(this.params.valuesLookup),
|
|
592
|
+
column;
|
|
593
|
+
|
|
594
|
+
if(field){
|
|
595
|
+
column = this.table.columnManager.getColumnByField(field);
|
|
596
|
+
}else{
|
|
597
|
+
column = this.cell.getColumn()._getSelf();
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if(column){
|
|
601
|
+
data.forEach((row) => {
|
|
602
|
+
var val = column.getFieldValue(row);
|
|
603
|
+
|
|
604
|
+
if(!this._emptyValueCheck(val)){
|
|
605
|
+
if(this.params.multiselect && Array.isArray(val)){
|
|
606
|
+
val.forEach((item) => {
|
|
607
|
+
if(!this._emptyValueCheck(item)){
|
|
608
|
+
output[item] = true;
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
}else{
|
|
612
|
+
output[val] = true;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
}else{
|
|
618
|
+
console.warn("unable to find matching column to create select lookup list:", field);
|
|
619
|
+
output = [];
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return Object.keys(output);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
_emptyValueCheck(value){
|
|
626
|
+
return value === null || typeof value === "undefined" || value === "";
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
_parseList(inputValues){
|
|
630
|
+
var data = [];
|
|
631
|
+
|
|
632
|
+
if(!Array.isArray(inputValues)){
|
|
633
|
+
inputValues = Object.entries(inputValues).map(([key, value]) => {
|
|
634
|
+
return {
|
|
635
|
+
label:value,
|
|
636
|
+
value:key,
|
|
637
|
+
};
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
inputValues.forEach((value) => {
|
|
642
|
+
if(typeof value !== "object"){
|
|
643
|
+
value = {
|
|
644
|
+
label:value,
|
|
645
|
+
value:value,
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
this._parseListItem(value, data, 0);
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
if(!this.currentItems.length && this.params.freetext){
|
|
653
|
+
this.input.value = this.initialValues;
|
|
654
|
+
this.typing = true;
|
|
655
|
+
this.lastAction = "typing";
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
this.data = data;
|
|
659
|
+
|
|
660
|
+
return data;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
_parseListItem(option, data, level){
|
|
664
|
+
var item = {};
|
|
665
|
+
|
|
666
|
+
if(option.options){
|
|
667
|
+
item = this._parseListGroup(option, level + 1);
|
|
668
|
+
}else{
|
|
669
|
+
item = {
|
|
670
|
+
label:option.label,
|
|
671
|
+
value:option.value,
|
|
672
|
+
itemParams:option.itemParams,
|
|
673
|
+
elementAttributes: option.elementAttributes,
|
|
674
|
+
element:false,
|
|
675
|
+
selected:false,
|
|
676
|
+
visible:true,
|
|
677
|
+
level:level,
|
|
678
|
+
original:option,
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
if(this.initialValues && this.initialValues.indexOf(option.value) > -1){
|
|
682
|
+
this._chooseItem(item, true);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
data.push(item);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
_parseListGroup(option, level){
|
|
690
|
+
var item = {
|
|
691
|
+
label:option.label,
|
|
692
|
+
group:true,
|
|
693
|
+
itemParams:option.itemParams,
|
|
694
|
+
elementAttributes:option.elementAttributes,
|
|
695
|
+
element:false,
|
|
696
|
+
visible:true,
|
|
697
|
+
level:level,
|
|
698
|
+
options:[],
|
|
699
|
+
original:option,
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
option.options.forEach((child) => {
|
|
703
|
+
this._parseListItem(child, item.options, level);
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
return item;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
_sortOptions(options){
|
|
710
|
+
var sorter;
|
|
711
|
+
|
|
712
|
+
if(this.params.sort){
|
|
713
|
+
sorter = typeof this.params.sort === "function" ? this.params.sort : this._defaultSortFunction.bind(this);
|
|
714
|
+
|
|
715
|
+
this._sortGroup(sorter, options);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
return options;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
_sortGroup(sorter, options){
|
|
722
|
+
options.sort((a,b) => {
|
|
723
|
+
return sorter(a.label, b.label, a.value, b.value, a.original, b.original);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
options.forEach((option) => {
|
|
727
|
+
if(option.group){
|
|
728
|
+
this._sortGroup(sorter, option.options);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
_defaultSortFunction(as, bs){
|
|
734
|
+
var a, b, a1, b1, i= 0, L, rx = /(\d+)|(\D+)/g, rd = /\d/;
|
|
735
|
+
var emptyAlign = 0;
|
|
736
|
+
|
|
737
|
+
if(this.params.sort === "desc"){
|
|
738
|
+
[as, bs] = [bs, as];
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
//handle empty values
|
|
742
|
+
if(!as && as!== 0){
|
|
743
|
+
emptyAlign = !bs && bs!== 0 ? 0 : -1;
|
|
744
|
+
}else if(!bs && bs!== 0){
|
|
745
|
+
emptyAlign = 1;
|
|
746
|
+
}else{
|
|
747
|
+
if(isFinite(as) && isFinite(bs)) return as - bs;
|
|
748
|
+
a = String(as).toLowerCase();
|
|
749
|
+
b = String(bs).toLowerCase();
|
|
750
|
+
if(a === b) return 0;
|
|
751
|
+
if(!(rd.test(a) && rd.test(b))) return a > b ? 1 : -1;
|
|
752
|
+
a = a.match(rx);
|
|
753
|
+
b = b.match(rx);
|
|
754
|
+
L = a.length > b.length ? b.length : a.length;
|
|
755
|
+
while(i < L){
|
|
756
|
+
a1= a[i];
|
|
757
|
+
b1= b[i++];
|
|
758
|
+
if(a1 !== b1){
|
|
759
|
+
if(isFinite(a1) && isFinite(b1)){
|
|
760
|
+
if(a1.charAt(0) === "0") a1 = "." + a1;
|
|
761
|
+
if(b1.charAt(0) === "0") b1 = "." + b1;
|
|
762
|
+
return a1 - b1;
|
|
763
|
+
}
|
|
764
|
+
else return a1 > b1 ? 1 : -1;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return a.length > b.length;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
return emptyAlign;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
_filterOptions(){
|
|
775
|
+
var filterFunc = this.params.filterFunc || this._defaultFilterFunc,
|
|
776
|
+
term = this.input.value;
|
|
777
|
+
|
|
778
|
+
if(term){
|
|
779
|
+
this.filtered = true;
|
|
780
|
+
|
|
781
|
+
this.data.forEach((item) => {
|
|
782
|
+
this._filterItem(filterFunc, term, item);
|
|
783
|
+
});
|
|
784
|
+
}else{
|
|
785
|
+
this.filtered = false;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
return this.data;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
_filterItem(func, term, item){
|
|
792
|
+
var matches = false;
|
|
793
|
+
|
|
794
|
+
if(!item.group){
|
|
795
|
+
item.visible = func(term, item.label, item.value, item.original);
|
|
796
|
+
}else{
|
|
797
|
+
item.options.forEach((option) => {
|
|
798
|
+
if(this._filterItem(func, term, option)){
|
|
799
|
+
matches = true;
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
|
|
803
|
+
item.visible = matches;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
return item.visible;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
_defaultFilterFunc(term, label, value, item){
|
|
810
|
+
term = String(term).toLowerCase();
|
|
811
|
+
|
|
812
|
+
if(label !== null && typeof label !== "undefined"){
|
|
813
|
+
if(String(label).toLowerCase().indexOf(term) > -1 || String(value).toLowerCase().indexOf(term) > -1){
|
|
814
|
+
return true;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
//////////////////////////////////////
|
|
822
|
+
/////////// Display List /////////////
|
|
823
|
+
//////////////////////////////////////
|
|
824
|
+
|
|
825
|
+
_clearList(){
|
|
826
|
+
while(this.listEl.firstChild) this.listEl.removeChild(this.listEl.firstChild);
|
|
827
|
+
|
|
828
|
+
this.displayItems = [];
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
_buildList(data){
|
|
832
|
+
this._clearList();
|
|
833
|
+
|
|
834
|
+
data.forEach((option) => {
|
|
835
|
+
this._buildItem(option);
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
if(!this.displayItems.length){
|
|
839
|
+
this._addPlaceholder(this.params.placeholderEmpty);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
_buildItem(item){
|
|
844
|
+
var el = item.element,
|
|
845
|
+
contents;
|
|
846
|
+
|
|
847
|
+
if(!this.filtered || item.visible){
|
|
848
|
+
|
|
849
|
+
if(!el){
|
|
850
|
+
el = document.createElement("div");
|
|
851
|
+
el.tabIndex = 0;
|
|
852
|
+
|
|
853
|
+
contents = this.params.itemFormatter ? this.params.itemFormatter(item.label, item.value, item.original, el) : item.label;
|
|
854
|
+
|
|
855
|
+
if(contents instanceof HTMLElement){
|
|
856
|
+
el.appendChild(contents);
|
|
857
|
+
}else{
|
|
858
|
+
el.innerHTML = contents;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if(item.group){
|
|
862
|
+
el.classList.add("tabulator-edit-list-group");
|
|
863
|
+
}else{
|
|
864
|
+
el.classList.add("tabulator-edit-list-item");
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
el.classList.add("tabulator-edit-list-group-level-" + item.level);
|
|
868
|
+
|
|
869
|
+
if(item.elementAttributes && typeof item.elementAttributes == "object"){
|
|
870
|
+
for (let key in item.elementAttributes){
|
|
871
|
+
if(key.charAt(0) == "+"){
|
|
872
|
+
key = key.slice(1);
|
|
873
|
+
el.setAttribute(key, this.input.getAttribute(key) + item.elementAttributes["+" + key]);
|
|
874
|
+
}else{
|
|
875
|
+
el.setAttribute(key, item.elementAttributes[key]);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
if(item.group){
|
|
881
|
+
el.addEventListener("click", this._groupClick.bind(this, item));
|
|
882
|
+
}else{
|
|
883
|
+
el.addEventListener("click", this._itemClick.bind(this, item));
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
el.addEventListener("mousedown", this._preventBlur.bind(this));
|
|
887
|
+
|
|
888
|
+
item.element = el;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
this._styleItem(item);
|
|
892
|
+
|
|
893
|
+
this.listEl.appendChild(el);
|
|
894
|
+
|
|
895
|
+
if(item.group){
|
|
896
|
+
item.options.forEach((option) => {
|
|
897
|
+
this._buildItem(option);
|
|
898
|
+
});
|
|
899
|
+
}else{
|
|
900
|
+
this.displayItems.push(item);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
_showList(){
|
|
906
|
+
var startVis = this.popup && this.popup.isVisible();
|
|
907
|
+
|
|
908
|
+
if(this.input.parentNode){
|
|
909
|
+
if(this.params.autocomplete && this.input.value === "" && !this.params.listOnEmpty){
|
|
910
|
+
if(this.popup){
|
|
911
|
+
this.popup.hide(true);
|
|
912
|
+
}
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
this._setListWidth();
|
|
917
|
+
|
|
918
|
+
if(!this.popup){
|
|
919
|
+
this.popup = this.edit.popup(this.listEl);
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
this.popup.show(this.cell.getElement(), "bottom");
|
|
923
|
+
|
|
924
|
+
if(!startVis){
|
|
925
|
+
setTimeout(() => {
|
|
926
|
+
this.popup.hideOnBlur(this._resolveValue.bind(this, true));
|
|
927
|
+
}, 10);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
_styleItem(item){
|
|
933
|
+
if(item && item.element){
|
|
934
|
+
if(item.selected){
|
|
935
|
+
item.element.classList.add("active");
|
|
936
|
+
}else{
|
|
937
|
+
item.element.classList.remove("active");
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
//////////////////////////////////////
|
|
943
|
+
///////// User Interaction ///////////
|
|
944
|
+
//////////////////////////////////////
|
|
945
|
+
|
|
946
|
+
_itemClick(item, e){
|
|
947
|
+
e.stopPropagation();
|
|
948
|
+
|
|
949
|
+
this._chooseItem(item);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
_groupClick(item, e){
|
|
953
|
+
e.stopPropagation();
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
//////////////////////////////////////
|
|
958
|
+
////// Current Item Management ///////
|
|
959
|
+
//////////////////////////////////////
|
|
960
|
+
|
|
961
|
+
_cancel(){
|
|
962
|
+
this.popup.hide(true);
|
|
963
|
+
this.actions.cancel();
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
_clearChoices(){
|
|
967
|
+
this.typing = true;
|
|
968
|
+
|
|
969
|
+
this.currentItems.forEach((item) => {
|
|
970
|
+
item.selected = false;
|
|
971
|
+
this._styleItem(item);
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
this.currentItems = [];
|
|
975
|
+
|
|
976
|
+
this.focusedItem = null;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
_chooseItem(item, silent){
|
|
980
|
+
var index;
|
|
981
|
+
|
|
982
|
+
this.typing = false;
|
|
983
|
+
|
|
984
|
+
if(this.params.multiselect){
|
|
985
|
+
index = this.currentItems.indexOf(item);
|
|
986
|
+
|
|
987
|
+
if(index > -1){
|
|
988
|
+
this.currentItems.splice(index, 1);
|
|
989
|
+
item.selected = false;
|
|
990
|
+
}else{
|
|
991
|
+
this.currentItems.push(item);
|
|
992
|
+
item.selected = true;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
this.input.value = this.currentItems.map(item => item.label).join(",");
|
|
996
|
+
|
|
997
|
+
this._styleItem(item);
|
|
998
|
+
|
|
999
|
+
}else{
|
|
1000
|
+
this.currentItems = [item];
|
|
1001
|
+
item.selected = true;
|
|
1002
|
+
|
|
1003
|
+
this.input.value = item.label;
|
|
1004
|
+
|
|
1005
|
+
this._styleItem(item);
|
|
1006
|
+
|
|
1007
|
+
if(!silent){
|
|
1008
|
+
this._resolveValue();
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
this._focusItem(item);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
_resolveValue(blur){
|
|
1016
|
+
var output, initialValue;
|
|
1017
|
+
|
|
1018
|
+
if(this.popup){
|
|
1019
|
+
this.popup.hide(true);
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if(this.params.multiselect){
|
|
1023
|
+
output = this.currentItems.map(item => item.value);
|
|
1024
|
+
}else{
|
|
1025
|
+
if(blur && this.params.autocomplete && this.typing){
|
|
1026
|
+
if(this.params.freetext || (this.params.allowEmpty && this.input.value === "")){
|
|
1027
|
+
output = this.input.value;
|
|
1028
|
+
}else{
|
|
1029
|
+
this.actions.cancel();
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
}else{
|
|
1033
|
+
if(this.currentItems[0]){
|
|
1034
|
+
output = this.currentItems[0].value;
|
|
1035
|
+
}else{
|
|
1036
|
+
initialValue = Array.isArray(this.initialValues) ? this.initialValues[0] : this.initialValues;
|
|
1037
|
+
|
|
1038
|
+
if(initialValue === null || typeof initialValue === "undefined" || initialValue === ""){
|
|
1039
|
+
output = initialValue;
|
|
1040
|
+
}else{
|
|
1041
|
+
output = this.params.emptyValue;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
if(output === ""){
|
|
1049
|
+
output = this.params.emptyValue;
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
this.actions.success(output);
|
|
1053
|
+
|
|
1054
|
+
if(this.isFilter){
|
|
1055
|
+
this.initialValues = output && !Array.isArray(output) ? [output] : output;
|
|
1056
|
+
this.currentItems = [];
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
}
|