Handsontable -在粘贴到单元格时禁用自动向上滚动

Handsontable - Disable auto scroll up when pasting into a cell

本文关键字:滚动 单元格 Handsontable      更新时间:2023-09-26

当我在handsontable表格中粘贴到接近页面顶部的单元格时,页面会自动向上滚动到单元格窗口的中心。

我试图在jquery.handsontable.full.js中找到导致此问题的代码,希望禁用它,但没有成功。

如果有人帮忙,我将不胜感激!

我在过去的几个星期里一直在努力解决同样的问题,直到今天,我设法在不编辑库的情况下修复它。

在初始化handsontable的地方,我添加了以下内容:

$(document).ready(function () {
    var position_Y_before = null;
    $(".handsontable").handsontable({
        //some code here for initializing the table and its functions
        //Then I added this callback function
        beforeKeyDown: function(e) {
            position_Y_before = window.pageYOffset || 0;
        };
    });
    //Here we prevent from scrolling to top of page after pasting to handsontable with cmd+v or ctrl+v
    $(window).scroll(function(){
        if(position_Y_before != null){
            window.scrollTo(0, position_Y_before);
            position_Y_before = null;
        }
    });
});

这至少对我有用,希望它也能帮助你!

请参阅wiwade对该问题的评论

也许这是一个黑客的修复,但工作得很好,我在谷歌chrome版本37.0.2062.120(64位)

改变
style.top = '-10000px';
style.left = '-10000px';

style.top = '0px';
style.left = '0px';
style.zIndex = '-99999';

在copypaste.js, jquery.handsontable.full.js或jquery.handsontable.js