- function AutocompleteCellType(source) {
- if (typeof source !== 'function') {
- console.error("AutocompleteCellType TypeError!!!")
- return false
- }
- this.source = source;
- }
- AutocompleteCellType.prototype = new GC.Spread.Sheets.CellTypes.Base;
- AutocompleteCellType.prototype.createEditorElement = function (context) {
- return document.createElement("input");
- };
- AutocompleteCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
- var $editor = jQuery(editorContext);
- GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.call(this, editorContext, cellStyle, cellRect, context);
- $editor.css("position", "absolute");
- $editor.attr("gcUIElement", "gcEditingInput");
- $editor.autocomplete({
- source: this.source,
- minLength: 1
- }); // initialize autocomplete widget
- $editor.autocomplete("widget").attr("gcUIElement", "gcEditingInput"); // keep focus when mouse down on dropdown
- return $editor;
- };
- AutocompleteCellType.prototype.deactivateEditor = function (editorContext, context) {
- if (editorContext) {
- var $editor = jQuery(editorContext);
- // $editor.autocomplete("hide");
- $editor.autocomplete("destroy");
- }
- GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.call(this, editorContext, context);
- };
- AutocompleteCellType.prototype.setEditorValue = function (editorContext, value, context) {
- jQuery(editorContext).val(value);
- };
- AutocompleteCellType.prototype.getEditorValue = function (editorContext, context) {
- return jQuery(editorContext).val();
- };
- AutocompleteCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
- if (editorContext) {
- var $editor = jQuery(editorContext);
- $editor.css("width", cellRect.width);
- $editor.css("height", cellRect.height);
- }
- };
- AutocompleteCellType.prototype.isReservedKey = function (event, context) {
- if (context.isEditing && (event.keyCode == 40 || event.keyCode == 38)) {
- return true;
- }
- return false;
- };
复制代码
- function sourceFn(param, prop) {
- return function (req, resp) {
- param.name = req.term;
- resp([{label: "加载中...", value: ""}])
- $.post(ctx + "appa/appaAssiAppa/listQueryAssiAppa", param, function (data) {
- if (data.code == 0) {
- resp($.map(data.rows, item => item[prop]));
- } else {
- resp([{label: "无数据", value: ""}])
- return false
- }
- });
- }
- }
复制代码 |