【问题标题】:Multiple editors in handsontableHandsontable 中的多个编辑器
【发布时间】:2015-06-27 11:31:12
【问题描述】:

我想知道如何在 handsontable.js 库中使用多个编辑器。

我使用columns 选项来指定每个列的属性。 其中一些显示了一个包含单元格可能选项的列表:

{
    data: 3,
    type: 'autocomplete',
    source: function (query, process) {
        response = JSON.parse($('#options').val());
        process(response);
    },
    strict: false,
    allowInvalid: true,
},

在这种情况下,它将在source 选项中生成选项列表。

现在,我想根据this other issue 添加另一个编辑器,但我注意到如果我在列声明中添加它,那么我会丢失生成自动完成列表的源选项:

{
    //START
    data: 3,
    type: 'autocomplete',
    source: function (query, process) {
        response = JSON.parse($('#start_array').val());
        process(response);
    },
    strict: false,
    allowInvalid: true,
    editor: LoggingEditor //added here
}

有什么解决办法吗?

Reproduction of the issue

【问题讨论】:

    标签: javascript handsontable


    【解决方案1】:

    Handsontable 正在使用cascading configuration,这是为整个表格、其列或特定单元格提供配置选项的方式。

    在您的情况下,指定type 属性(您提到它here)胜过顶级editor: LoggingEditor 属性。要使用自定义编辑器,您必须要么不指定类型(因为默认为文本),要么将 editor 属性添加到所有列定义。我已经编辑了您的示例以使用this fiddle 中的两种方法(请注意,自动完成字段不起作用,但您应该添加另一个自定义编辑器而不是使用文本编辑器)。

    【讨论】:

    • 那么,有没有办法在使用编辑器的同时使用type: autocomplete
    • 我创建了问题here 的复制品。如您所见,我对每一列都使用了editortype 属性。然而,自动完成功能不起作用。
    • 如果您从 AutocompleteEditor 扩展 type: 'autocomplete' 列,则为 will work。查看 HOT wiki 上的 custom editors 页面和 editor implementations
    猜你喜欢
    • 2012-10-19
    • 2017-12-25
    • 2019-02-04
    • 2017-03-05
    • 1970-01-01
    • 2015-10-25
    • 2016-06-03
    • 1970-01-01
    • 2013-08-23
    相关资源
    最近更新 更多