0

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.

Check this 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 ?

Paritosh
  • 11,144
  • 5
  • 56
  • 74

2 Answers2

1

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/

Paritosh
  • 11,144
  • 5
  • 56
  • 74
Abhishek Dutta
  • 123
  • 1
  • 1
  • 7
  • in my specific situation, the data comes from server and even after using `grid.scrollPosition` the issue is still there. Scroll goes to top even after this. Have to use `setTmeout` to make the scroll position persistent due to this. But as your solution solves the issue in fiddle, marking it as answer. – Paritosh Feb 26 '18 at 10:20
1

You need to store scroll position before making http request and set back once items have been added to FlexGrid.

Please refer to the following updated fiddle with http service delay simulation:

[http://jsfiddle.net/hwr2ra1q/41/][1]
Manish Gupta
  • 276
  • 2
  • 5