延迟加载GWT数据网格中的数据 [英] Lazy Load Data in a GWT DataGrid
问题描述
有可能将数据懒惰地加载到GWT DataGrid中,类似于GWT CellList如何加载数据?
我有一个GWT DataGrid,可能会带回数百行,但一次只显示大约20行。发生这种情况时,网格的加载速度很慢。
我想使用DataGrid而不是CellTList,因为我需要显示多列数据。我选择了DataGrid而不是CellTable,因为我想要修改标题列。
由于 DataGrid
不公开它的 ScrollPanel
,创建一个扩展 DataGrid $ c $>的内部类c>并提供对
ScrollPanel
的引用:
private static class MyDataGrid< T>扩展DataGrid {
public ScrollPanel getScrollPanel(){
HeaderPanel header =(HeaderPanel)getWidget();
return(ScrollPanel)header.getContentWidget();
初始化这个工作所需的变量: p>
private MyDataGrid< MyDataType> myDataGrid;
private int incrementSize = 20;
private int lastScrollPos = 0;
在构造函数中,创建网格:
< preclass =lang-java prettyprint-override> myDataGrid = new MyDataGrid< MyDataType>();
然后使用刚创建的getScrollPanel()引用添加一个ScrollHandler:
myDataGrid.getScrollPanel()。addScrollHandler(new ScrollHandler(){
@Override
公共无效onScroll(表示ScrollEvent事件){
INT oldScrollPos = lastScrollPos;
lastScrollPos = myDataGrid.getScrollPanel()getVerticalScrollPosition();
//
if(oldScrollPos> = lastScrollPos){
return;
}
//网格内容的高度(包括可视区域) -
myDataGrid.getScrollPanel()getOffsetHeight() - 滚动面板
INT maxScrollTop = myDataGrid.getScrollPanel()getWidget()getOffsetHeight()的高度;
if(lastScrollPos> = maxScrollTop){
myDataGrid.setVisibleRang E(0,myDataGrid.getVisibleRange()的getLength()+ incrementSize);
}
}
});
Is it possible to load data lazily into a GWT DataGrid, similarly to how the GWT CellList lazily loads data?
I have a GWT DataGrid that can potentially bring back hundreds of rows, but only about 20 rows are displayed at a time. When this occurs, the loading of the grid is quite slow.
I want to use a DataGrid instead of a CellTList because I have multiple columns of data that need to be displayed. And I've opted for a DataGrid instead of a CellTable because I want the header columns to be fixed.
Since DataGrid
doesn't expose it's ScrollPanel
, create an inner class that extends DataGrid
and provides a reference to the ScrollPanel
:
private static class MyDataGrid<T> extends DataGrid {
public ScrollPanel getScrollPanel() {
HeaderPanel header = (HeaderPanel) getWidget();
return (ScrollPanel) header.getContentWidget();
}
}
Initialize the variables needed for this to work:
private MyDataGrid<MyDataType> myDataGrid;
private int incrementSize = 20;
private int lastScrollPos = 0;
In the constructor, create the grid:
myDataGrid = new MyDataGrid<MyDataType>();
Then add a ScrollHandler, using the getScrollPanel() reference that was just created:
myDataGrid.getScrollPanel().addScrollHandler(new ScrollHandler(){
@Override
public void onScroll(ScrollEvent event) {
int oldScrollPos = lastScrollPos;
lastScrollPos = myDataGrid.getScrollPanel().getVerticalScrollPosition();
// If scrolling up, ignore the event.
if (oldScrollPos >= lastScrollPos) {
return;
}
//Height of grid contents (including outside the viewable area) - height of the scroll panel
int maxScrollTop = myDataGrid.getScrollPanel().getWidget().getOffsetHeight() -
myDataGrid.getScrollPanel().getOffsetHeight();
if(lastScrollPos >= maxScrollTop) {
myDataGrid.setVisibleRange(0,myDataGrid.getVisibleRange().getLength()+incrementSize);
}
}
});
这篇关于延迟加载GWT数据网格中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!