gwtdatagridsimplepager

GWT DataGrid with SimplePager, Last Page Issue


I'm using GWT DataGrid with SimplePager to show a my Data,

The Component shows the first pages correctly, but the last page shows always 10 rows (10 = SimplePager.pagesize) even if we have less then 10 rows to display.

AnyOne have an idea about yhis issue ?

Thanx.


Solution

  • I encountered a similar issue before. The small difference is that I was using Celltable instead of DataGrid.

    The problem is coming from a known bug of gwt which you can see the detail on its github page. Obviously it has been fixed yet.

    The workaround is to subclass the SimplePager and create your custom pager class.

    import com.google.gwt.user.cellview.client.SimplePager;
    import com.google.gwt.view.client.Range;
    
    public class CustomPager extends SimplePager {
    
    public CustomPager() {
        this.setRangeLimited(true);
    }
    
    @Override
    public void setPageStart(int index) {
        if (this.getDisplay() != null) {
            Range range = this.getDisplay().getVisibleRange();
            int pageSize = range.getLength();
            index = Math.max(0, index);
            if (index != range.getStart()) {
                this.getDisplay().setVisibleRange(index, pageSize);
            }
        }
    }
    
    }