找回密码
 立即注册

QQ登录

只需一步,快速开始

Dtttax

高级会员

235

主题

571

帖子

1846

积分

高级会员

积分
1846
Dtttax
高级会员   /  发表于:2023-5-8 11:45  /   查看:2456  /  回复:15
1金币
https://demo.grapecity.com.cn/Sp ... /demos/autoComplete


给单元格加入celltye,不显示下拉框,如图:

image.png886673278.png


参考了上面demo的代码,如下代码:
let availableTags=["CSSd"];
cell.cellType(new AutocompleteCellType(availableTags));



export class AutocompleteCellType extends GC.Spread.Sheets.CellTypes.Base {
  constructor(itemNames) {
    super()
    this.itemNames = [];
    if (itemNames && itemNames.length) {
        this.itemNames = itemNames;
    }
  }

  createEditorElement(context){
    return document.createElement("input");
  }

  activateEditor(editorContext, cellStyle, cellRect, context){
    var $editor = $(editorContext);
    GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.call(this, editorContext, cellStyle, cellRect, context);
    $editor.css("position", "absolute");
    $editor.css("font", cellStyle.font);
    $editor.css("color", cellStyle.foreColor);
    $editor.css("border-bottom", "none");
    $editor.css("border-left", "1px solid white");
    $editor.css("border-top", "1px solid white");
    $editor.attr("gcUIElement", "gcEditingInput");
    $editor.autocomplete({
        source: this.itemNames
    }); // initialize autocomplete widget
    $editor.autocomplete("widget").attr("gcUIElement", "gcEditingInput"); // keep focus when mouse down on dropdown
    return $editor;
  }

  deactivateEditor(editorContext, context){
    if (editorContext) {
        var $editor = $(editorContext);
        // $editor.autocomplete("hide");
        $editor.autocomplete("destroy");
    }
    GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.call(this, editorContext, context);
  }

  setEditorValue(editorContext, value, context){
    $(editorContext).val(value);
  }
  getEditorValue(editorContext, context){
    return $(editorContext).val();
  }
  updateEditor(editorContext, cellStyle, cellRect, context){
    if (editorContext) {
        var $editor = $(editorContext);
        $editor.css("width", cellRect.width);
        $editor.css("height", cellRect.height);
    }
  }
  isReservedKey(event, context){
    if (context.isEditing && (event.keyCode == 40 || event.keyCode == 38)) {
        return true;
    }
    return false;
  }
}

最佳答案

查看完整内容

activateEditor(editorContext, cellStyle, cellRect, context) { var $editor = $(editorContext); GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.call( this, editorContext, cellStyle, cellRect, context ); $editor.css("position", "absolute"); $editor.css("font", cellStyle.font); $ ...

15 个回复

倒序浏览
最佳答案
最佳答案
JoestarXu
超级版主   /  发表于:2023-5-8 11:45:15
来自 12#
      activateEditor(editorContext, cellStyle, cellRect, context) {
        var $editor = $(editorContext);
        GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.call(
          this,
          editorContext,
          cellStyle,
          cellRect,
          context
        );
        $editor.css("position", "absolute");
        $editor.css("font", cellStyle.font);
        $editor.css("color", cellStyle.foreColor);
        $editor.css("border-bottom", "none");
        $editor.css("border-left", "1px solid white");
        $editor.css("border-top", "1px solid white");
        $editor.attr("gcUIElement", "gcEditingInput");
        $editor.autocomplete({
          minLength : 0,
          source: this.itemNames,
        }).focus(function () {
          $(this).autocomplete('search', $(this).val())
        }); // initialize autocomplete widget
        $editor.autocomplete("widget").attr("gcUIElement", "gcEditingInput"); // keep focus when mouse down on dropdown
        if ($editor.val() == "") {
          $editor.autocomplete("search", "");
        }
        return $editor;
      }

用上面这段代码替换activateEditor这个方法就可以了。
回复 使用道具 举报
MillionDream
注册会员   /  发表于:2023-5-8 11:51:32
2#
您好,可以提供一个能运行的Demo吗?只看代码的话很难定位问题在哪。
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-8 14:09:29
3#
andout.html:163 Uncaught TypeError: $editor.autocomplete is not a function

这个地方错误, 不知道怎么改。

test.zip

3.22 MB, 下载次数: 77

回复 使用道具 举报
MillionDream
注册会员   /  发表于:2023-5-8 16:11:22
4#
Dtttax 发表于 2023-5-8 14:09
andout.html:163 Uncaught TypeError: $editor.autocomplete is not a function

这个地方错误, 不知 ...

您这个错误是怎么触发的呢?我看到你给我的Demo里面有1个json和2个ssjson,我应该打开哪一个才能复现你说的这个错误?
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-8 16:34:18
5#
只打开那个html文件就可以了。
        spread.getActiveSheet().getCell(13,1).cellType(new AutocompleteCellType(availableTags));

双击14行第二列就重现了。
回复 使用道具 举报
JoestarXu
超级版主   /  发表于:2023-5-8 17:58:20
6#
autoComplete是jquery-ui这个包里面的东西,您的Demo里面并没有安装这个包,所以才会导致找不到autoComplete这个方法。

图片.png226804198.png
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-9 10:40:26
7#
添加了还是不行。

test2.zip

3.38 MB, 下载次数: 85

回复 使用道具 举报
JoestarXu
超级版主   /  发表于:2023-5-9 11:04:09
8#
您Demo中jQuery和jQuery-UI的版本有冲突,我把处理好的Demo发给您。

test2.rar (8.09 MB, 下载次数: 77)
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-9 11:23:00
9#
还是不行啊,直接这样设置的celltype,但是不处理。
spread
          .getActiveSheet()
          .getCell(13, 1)
          .cellType(new AutocompleteCellType(availableTags));
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部