一旦在虚拟滚动中将新数据附加到 wijmo-grid,滚动设置到顶部
Scrolling sets to top once new data is appended to wijmo-grid in virtual scrolling
在使用 wijmo 网格实现虚拟滚动时,按照以下代码,当新数据附加到 data
数组时(一旦我们滚动并到达网格的最后一条记录) , 滚动会重置到初始位置。
勾选这个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();
}
}
知道我们如何才能阻止这种行为吗?其他网格如 slickgrid, ag-grid provides smooth behaviour - once the data is appended, the previous last record stays in the view. Can we achieve similar kind of behaviour for wijmo-grid?
您可以在刷新网格之前保存滚动位置,并在滚动后恢复相同位置。
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;
}
}
});
检查更新后的 fiddle:- http://jsfiddle.net/797tjc5u/
您需要在发出 http 请求之前存储滚动位置,并在项目添加到 FlexGrid 后返回。
请参考以下更新后的fiddle http服务延迟模拟:
[http://jsfiddle.net/hwr2ra1q/41/][1]
在使用 wijmo 网格实现虚拟滚动时,按照以下代码,当新数据附加到 data
数组时(一旦我们滚动并到达网格的最后一条记录) , 滚动会重置到初始位置。
勾选这个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();
}
}
知道我们如何才能阻止这种行为吗?其他网格如 slickgrid, ag-grid provides smooth behaviour - once the data is appended, the previous last record stays in the view. Can we achieve similar kind of behaviour for wijmo-grid?
您可以在刷新网格之前保存滚动位置,并在滚动后恢复相同位置。
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;
}
}
});
检查更新后的 fiddle:- http://jsfiddle.net/797tjc5u/
您需要在发出 http 请求之前存储滚动位置,并在项目添加到 FlexGrid 后返回。
请参考以下更新后的fiddle http服务延迟模拟:
[http://jsfiddle.net/hwr2ra1q/41/][1]