找回密码
 立即注册

QQ登录

只需一步,快速开始

Dtttax

高级会员

235

主题

572

帖子

1849

积分

高级会员

积分
1849
Dtttax
高级会员   /  发表于:2023-5-8 11:45  /   查看:2633  /  回复: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;
  }
}

15 个回复

正序浏览
Joestar.XuSpreadJS 开发认证
超级版主   /  发表于:2024-1-24 09:22:23
16#
Dtttax 发表于 2024-1-23 18:15
加了这个自定义单元格后sheet.autoFitColumn(col)不生效了

您好,看上去该问题和您主题的问题关联不大,为了避免混淆,请您另开一个帖子,并在新帖中详细描述一下您的问题和需求,最好提供代码和可以复现的Demo,以帮助我们解决您的问题。
SpreadJS 17.0.8 | GcExcel 7.1.1 已发布~
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2024-1-23 18:15:51
15#
加了这个自定义单元格后sheet.autoFitColumn(col)不生效了
回复 使用道具 举报
JoestarXu
超级版主   /  发表于:2023-5-9 14:12:17
14#
不客气哈,那就先结贴了,后续有问题您随时提问。
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-9 13:56:07
13#
可以了谢谢
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-9 11:35:03
11#
明白了,如果想不输入就全部显示出来应该怎么处理。
回复 使用道具 举报
JoestarXu
超级版主   /  发表于:2023-5-9 11:29:49
10#
Dtttax 发表于 2023-5-9 11:23
还是不行啊,直接这样设置的celltype,但是不处理。
spread
          .getActiveSheet()

不处理是什么意思?是输入后没有反应吗?还是其他的表现?

image.png605274962.png

我这边是可以正常显示的。
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-9 11:23:00
9#
还是不行啊,直接这样设置的celltype,但是不处理。
spread
          .getActiveSheet()
          .getCell(13, 1)
          .cellType(new AutocompleteCellType(availableTags));
回复 使用道具 举报
JoestarXu
超级版主   /  发表于:2023-5-9 11:04:09
8#
您Demo中jQuery和jQuery-UI的版本有冲突,我把处理好的Demo发给您。

test2.rar (8.09 MB, 下载次数: 77)
回复 使用道具 举报
Dtttax
高级会员   /  发表于:2023-5-9 10:40:26
7#
添加了还是不行。

test2.zip

3.38 MB, 下载次数: 85

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

图片.png226804198.png
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部