I had the same problem. I solved it by adding null
rows. Basically, you need to override onRangeChange(HasData<T> display)
in your DataProvider
to add null
to the list representing the range asked for. You add enough null
to fill the range you want.
@Override
protected void onRangeChanged(HasData<T> display){
Range range = display.getVisibleRange();
List<T> listOfObjects = getRange(range);
for(int i=listOfObject.size(); i<range.getLength(); i++){
listOfObjects.add(null);
}
updateRowData(range.getStart(), listofObjects);
}
In the above code getRange()
returns a list containing the objects that are requested (within the range)
You'll also have to add some CSS to give a height to rows. If you don't specify the height then the rows will be very small so they won't pad the whole table.
It's disappointing that GWT doesn't have support for this type of padding. This way was the best one that I found but unfortunately when your row heights differ within a table it makes everything harder.
Paging
With the solution above you'll need to have a custom Pager
if you want paging. You can extend your AsyncDataProvider
with method like getVisibleRowCount()
this will return how many objects in the current sublist are actually real data (not null
). Then you can give a reference of the AsyncDataProvider
to the Pager
and override the createText()
method:
@Override
protected String createText(){
return getPageStart() + " - " + dataProvider.getVisibileRowCount() + " of "
+ dataProvider.getTotalRowCount();
}