javascript - 在 handsontable 中创建 onEdit 回调

标签 javascript jquery handsontable

我正在使用 handsontable图书馆,当我发现 there isn't an onEdit callback 时我感到非常惊讶.

我尝试使用 that same issue 中一位用户提供的脚本来创建它但它似乎适用于旧版本并且不再有效。

我试图弄清楚如何添加一个钩子(Hook),但是关于它的文档从 handsontable 来看非常差。 有人知道如何为 handsontable 创建这样的回调吗?

最佳答案

仅捕获双击是不够的,因为用户可能会使用 EnterF1 键进一步进入编辑模式。

缺少 onEdit 回调的一个解决方案是注册一个自定义编辑器。这样它就可以很好地适应所有的编辑-保存-退出生命周期(例如 Esc 键关闭编辑器并丢失所有更改)。这是一个非常简化的编辑器,它扩展了内置和默认的 TextEditor:

var LoggingEditor = Handsontable.editors.TextEditor.prototype.extend();

LoggingEditor.prototype.getValue = function() {
    console.log('User finished editing the cell, the value will be set to: '
                + this.TEXTAREA.value);
    return this.TEXTAREA.value;
};

LoggingEditor.prototype.setValue = function(newValue){
    console.log('User started editing the cell, value shown in cell is: '
                + newValue);
    this.TEXTAREA.value = newValue;
};

但是,这个解决方案并不通用,因为如果使用了多个编辑器,它也必须被替换。不过,它应该适用于简单的情况。完整示例可在 this fiddle 中找到.

关于javascript - 在 handsontable 中创建 onEdit 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29654330/

相关文章:

javascript - 如何.fnDestroy(),columnFilter();两者都会起作用..有什么办法可以做到吗?目前只有 .fnDestroy 正在工作

jquery - 动手摧毁和创造

css - 这个伪元素应用于什么?

javascript - 处理多个 "else if"语句。降低圈复杂度

javascript - 基本 Karma Angular 1.5 组件测试

Javascript 将选择器的文本内容分配给表单输入值

javascript - 计算数组中不同元素的数量

javascript - 隐藏各种div -jquery

javascript - JavaScript 中的 [[ param1, param2 ... ]] 结构是什么?

javascript - 启用 SHIFT 键