如何获取剑道网格的滚动位置

时间:2017-10-24 18:09:38

标签: javascript jquery kendo-grid

我正在尝试从我的kendo网格中收集scrollLeft / scrollTop位置数据。到目前为止我有这个:

var mainGrid = $("#mainGrid").data("kendoGrid");
var testgrid = $("#mainGrid div.k-grid-content");
topoffset = testgrid.offset();

//which gives me these numbers but they do not look correct...
//left  44.959999084472656  Number
//top   174.55999755859375  Number

然后我想通过强制我的网格滚动到顶部来展示自动定位:0和左:0然后回到我用这个捕获的位置......

//send to top
testgrid.scrollTop(0);
testgrid.scrollLeft(0);
  

网格没有按预期滚动到顶部。

//send to previous position
testgrid.scrollTop(topScroll);
testgrid.scrollLeft(leftScroll);
  

网格不会回滚到之前的位置。

您似乎不允许强制滚动到剑道网格中的某个位置。

2 个答案:

答案 0 :(得分:3)

首先,您需要在数据绑定事件中使用此功能。因此,如果您想先设置它,您可以这样做:

databound: function(e){
  $('.k-grid-content').scrollTop('150');
    setTimeout(function () {
        $('.k-grid-content').animate({
            scrollTop: 0
        }, 1000);
    }, 2000);
    setTimeout(function () {
        $('.k-grid-content').animate({
            scrollTop: 200
        }, 1000);
    }, 5000);
});

只需将值转换为您想要的速度和滚动距离(我刚使用了scrollTop,但您可以使用变体)。如果您想首先使用网格,然后捕获它的使用位置:

然后使用sessionStorage变量保存它,然后在数据绑定事件中输入它。要在刷新之前捕获网格的位置,您可以执行以下操作:

$(document).on('keydown', function(){
   $('.k-grid-content').scrollTop(); // capture how far from top
   $('.k-grid-content').scrollLeft(); // capture how far from left
});

这不需要在您的数据绑定事件中。

答案 1 :(得分:0)

您可以使用以下解决方案来获取剑道网格的滚动位置:

$('html, body').animate({
 scrollTop: $("#unSubmittedGrid").offset().top-300
}, 'slow');
相关问题