简体   繁体   English

在虚拟滚动中将新数据附加到wijmo-grid后,滚动将设置为顶部

[英]Scrolling sets to top once new data is appended to wijmo-grid in virtual scrolling

While implementing virtual scrolling with grid, as per the below code, when the new data is appended to data array (once we scroll and reach to the last record of the grid), the scroll gets reset to the initial position. 在使用网格实现虚拟滚动时,按照以下代码,将新数据附加到data数组(一旦滚动并到达网格的最后一条记录),滚动将重置为初始位置。

Check this JSFiddle 检查这个JSFiddle

scrollPositionChanged: function(s, e) {

    // if we're close to the bottom, add 10 items
    if (s.viewRange.bottomRow >= s.rows.length - 1) {
            addData(data, 20);
    s.collectionView.refresh();
  }
}

Any idea how can we stop this behaviour? 知道我们如何停止这种行为吗? Other grids like , provides smooth behaviour - once the data is appended, the previous last record stays in the view. 其他网格(如可提供平滑的行为-附加数据后,先前的最后一条记录将保留在视图中。 Can we achieve similar kind of behaviour for ? 我们可以为实现类似的行为吗?

You can save scroll postion before refreshing the grid and restore the same after scroll. 您可以在刷新网格之前保存滚动位置,并在滚动后将其恢复。

var pos;

var grid = new wijmo.grid.FlexGrid('#flex', {
  itemsSource: data,
  scrollPositionChanged: function (s, e) {
    // if we're close to the bottom, add 10 items
    if (s.viewRange.bottomRow >= s.rows.length - 1) {
      addData(data, 20);
      //save current scroll postion
      pos = grid.scrollPosition;
      s.collectionView.refresh();
    }

    //restore scroll position
    if (pos) {
      s.scrollPosition = Object.assign({}, pos);
      pos = null;
    }
  }
});

Check the updated fiddle:- http://jsfiddle.net/797tjc5u/ 检查更新的小提琴:-http: //jsfiddle.net/797tjc5u/

You need to store scroll position before making http request and set back once items have been added to FlexGrid. 您需要先存储滚动位置,然后再发出http请求,并在将项目添加到FlexGrid后再回退。

Please refer to the following updated fiddle with http service delay simulation: 请参考以下有关http服务延迟模拟的更新小提琴:

[http://jsfiddle.net/hwr2ra1q/41/][1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM