【问题标题】:On Handsontable how can I disable the 'edit' action on updating a cell by 'setDataAtCell' inside from 'copyPaste' event在 Handsontable 上,如何通过“copyPaste”事件中的“setDataAtCell”禁用更新单元格的“编辑”操作
【发布时间】:2015-11-12 09:21:28
【问题描述】:

我正在使用带有 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']

第一个触发器用于“粘贴”操作,剩下的两个触发器用于“setDataAtCell”命令。这会延迟整个 copyPaste 操作。有时它卡在大数据复制粘贴中

任何人都想在这里跳过“编辑”循环。

【问题讨论】:

    标签: handsontable


    【解决方案1】:

    如果您仍在寻找解决方案,我认为这个解决方案会对您有所帮助。

    我遇到了像你这样的问题,我设法通过修改 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 上,您将获得您设置的值...

    【讨论】:

    • 感谢您的回复。我已经使用您在此处“beforeChange”中提到的相同方法解决了该问题。 :)
    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 2017-04-19
    • 2012-12-21
    • 2016-02-16
    • 2012-02-10
    • 2020-03-28
    • 2017-12-25
    • 2015-10-25
    相关资源
    最近更新 更多