在 Handsontable 上,如何通过 'copyPaste' 事件中的 'setDataAtCell' 禁用 'edit' 更新单元格的操作

On Handsontable how can I disable the 'edit' action on updating a cell by 'setDataAtCell' inside from 'copyPaste' event

我在 php 中使用 Handsontable 电子表格控件,数据保存在 mongodb 中。 当在控件上复制粘贴一堆数据时,'afterChage' 事件触发,源为 'paste'。在这里面,我试图使用函数 instance.setDataAtCell(rowIndex, 0, vRowId)

更新特定单元格 (0) 上的值 (RowID)
 afterChange: function(changes, source) {

   console.log('Trigrd>>');
   console.log('Source:'+source);
   console.log('Changes:'+changes);
   if (source  == 'paste' || source  == 'autofill' || (changes.length >1 )) {
     var minVal            = changes[0][0];
     var maxVal            = changes[chLength][0];

     for(var modifyRowIndex = minVal; modifyRowIndex <= maxVal ;modifyRowIndex++){
        var xrowId          = Math.random();
        instance.setDataAtCell(modifyRowIndex, 0, xrowId, 'program');
     }
   }

 }

如果我尝试在电子表格上粘贴两行数据,在控制台上我们可以看到 afterChange 函数被触发了 3 次。

Trigrd>>
Source:paste
Changes:[[0,1,'','xxxx'],[1,1,'','yyyy']]
Trigrd>>
Source:edit
Changes:[0,0,'','1232']
Trigrd>>
Source:edit
Changes:[1,0,'','23434']

第一个触发是针对操作 'paste',其余两个触发是由于命令 'setDataAtCell'。这会延迟整个复制粘贴操作。有时它会卡在大数据 copyPaste

任何人都可以在此处跳过 'edit' 循环。

如果您仍在寻找解决方案,我想这个可以帮到您。

我遇到了和你一样的问题,我设法通过在 beforeChange 而不是 afterChange 中进行修改来解决它:

beforeChange : function(changes, source){
    if (source  == 'paste'){
        var nrChanges = changes.length;
        for (var i = 0; i < nrChanges; i++)
            if (changes[i][1] == _CB) // get cell where you want to control
                changes[i][3] = false; // here you add your value
    }
}

afterChange 上,您将获得您设置的值 ...