寻找实现无限滚动的GWT DataGrid
组件,但也确保丢弃屏幕上不再显示的结果:例如先前加载的结果不再显示。
这是为了避免内存耗尽。
我一直想在Google上找到这个,但到目前为止还没有运气。
请注意:我可以使用JS库并根据我的需要进行调整,但我认为它不适用于GWT的DataGrid
组件。
编辑:我特别感兴趣的是无限滚动,它会丢弃/释放不可见的最顶层结果(并根据需要加载它们)。
有什么想法吗?
答案 0 :(得分:3)
事实上showcase example有无限滚动CellList
。 (你可以在那里找到代码)
虽然这是使用CellList
完成的,但相同的原则也适用于DataGrid
查看ShowMorePagerPanel.java
文件。
<强>更新强>
ShowMorePagerPanel.java
的onScroll函数将在底部添加新记录。但是,您可以轻松更改行为:
有些事情(未经过强硬测试):
HasRows display = getDisplay();
if (display == null) {
return;
}
boolean loadData = false;
// If scrolling up, change newStart
int oldScrollPos = lastScrollPos;
lastScrollPos = scrollable.getVerticalScrollPosition();
// get the current visible Range
Range currentRange = display.getVisibleRange();
if (oldScrollPos >= lastScrollPos) {
int newStart = Math.max(
currentRange.getStart() - incrementSize,0);
loadData = true;
}
int maxScrollTop = scrollable.getWidget().getOffsetHeight()
- scrollable.getOffsetHeight();
if (lastScrollPos >= maxScrollTop) {
// We are near the end, so increase the page size.
int newPageSize = Math.min(
display.getVisibleRange().getLength() + incrementSize,
display.getRowCount());
loadData = true;
}
if (loadData) {
display.setVisibleRange(newStart, newPageSize);
}