我也有同样的问题,但我调整了TextCellType使用jQueryUI自动完成。
<div>
<input type='hidden' id="dropDownCellInfo" />
<div id="ss" style="height:500px;border:solid gray 1px;"/>
</div>
您可以参考jQuery UI documentation以了解有关使用自动填充小部件的更多信息。下面的代码创建一个TextCellType并覆盖其创建编辑器方法以创建一个文本元素并使用jQuery自动完成对其进行初始化。
我不得不使用隐藏文本元素来捕获行和列,在从列表中选择一个选项后,必须更新该值。可能有更好的办法,但这有效。
var cellType = new $.wijmo.wijspread.TextCellType();
cellType.createEditorElement = function(context)
{
var obj = jQuery('#dropDownCellInfo');
obj.data('sheet' , context.sheet);
obj.data('row', context.row);
obj.data('col', context.col);
console.log(context);
var $textarea = $('<input type="text" id="txtSearch" style="visible:false" />');
var editor = document.createElement("div");
$(editor).append($textarea);
$textarea.autocomplete({
minLength: 2,
autoFocus : true,
source: 'http://localhost/spreadjs/index.php',
focus: function(event, ui) {
$("#txtSearch").val(ui.item.inst_name);
return false;
},
select: function(event, ui) {
$("#txtSearch").val(ui.item.inst_name);
var obj = jQuery('#dropDownCellInfo');
var spd = jQuery("#ss").wijspread("spread").getActiveSheet().setActiveCell(obj.data('row'),obj.data('col'));
// We have to explicitly remove the list element from the DOM because some
// how the method creates a new list for each autocomplete request and does not deletes the list after onSelect event.
jQuery('ul.ui-autocomplete').remove();
return false;
}
})
.autocomplete("instance")._renderItem = function(ul, item) {
return $("<li>")
.append("<a>" + item.inst_name + "</a>")
.appendTo(ul);
};
return editor
};
sheet.getColumn(3).cellType(cellType);