【发布时间】:2020-12-09 09:37:51
【问题描述】:
我使用 tabulator.js 库。我的目标 - 使用从 API 返回的值创建自动完成编辑器。我尝试按照custom editiors 部分的文档中的说明实现此功能。
我的 JS 代码:
function AutocompleteEditor(cell, onRendered, success, cancel, editorParams) {
var editor = document.createElement("input");
editor.setAttribute("type", "text");
editor.setAttribute("autocomplete", "off");
editor.style.width = "100%";
// editor.style.height = "100%";
editor.style.boxSizing = "border-box";
if (cell.getValue()) {
editor.value = cell.getValue();
}
$(editor).autoComplete({
minLength: 1,
resolverSettings: {
url: apiBaseUrl + 'ItemMatching/ItemCode',
},
formatResult: function (item) {
return {
value: item.vendorCode,
text: item.vendorCode + " - " + item.vendorName,
};
},
});
$(editor).on('autocomplete.select', function (event, item) {
if (item) {
selectedManufacturer = item;
$(editor).value(item.vendorName);
}
});
onRendered(function () {
console.log($(editor));
editor.focus();
editor.style.css = "100%";
});
function successFunc() {
success(selectedManufacturer.vendorCode);
}
editor.addEventListener("change", successFunc);
editor.addEventListener("blur", successFunc);
return editor;
}
当自动完成部分被单元格“隐藏”时,我得到了行为。 如果我使用像 date 这样的标准 html 输入类型 - 没问题。 请看附图。
需要如何解决或实施此问题(单元格附近的自动完成部分)的任何建议?
PS 我使用 bootsrap-autocomplete bootstrap-autocomplete
【问题讨论】:
-
Tabulator 中已经内置了一个可与 Ajax 配合使用的自动完成编辑器。
标签: javascript css autocomplete tabulator