Wednesday, August 20, 2014

Re: CellTable with "optimal" page size

I had the same request and went for the easy quick and dirty trick, ie override the onresize method.

public void onResize() {
if(dataProvider.getList().isEmpty() || !dataGrid.isVisible() || (dataGrid.getVisibleItems().size() == 0)) {
try {
int pageStart = pager.getPageStart();
int rowHeight = dataGrid.getRowElement(0).getOffsetHeight();
// TODO - find a way to calculate the visible part of the rows panel
int height = dataGrid.getOffsetHeight() - 30; //((HeaderPanel) (dataGrid.asWidget())).getHeaderWidget().getOffsetHeight();
pager.setPageSize(Math.max(1, (int) Math.floor((double) height / rowHeight)));
} catch(Exception e) {

As you can see in the code, I have not found a reliable way to get the header's size, and fixed it to 30px, there is always a little too much at the bottom because of that + the fact that you need an integer number of lines (so you will never have it fitting perfectly anyway), but at least it gets adjusted to the right number of lines automatically.

On Tuesday, 19 August 2014 18:48:25 UTC+2, Magnus wrote:
I know that someone posted a method here some years ago, but I cannot find it anymore...

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment