GWT Async DataProvider always jumping to celtable' first page

237 Views Asked by At

I have a simple celltable with:

a)A timer for retrieving the Whole list of values from the server (via rpc). when the data comes from the server:

public void onSuccess(final Object result) {

             myList ((List<myObject>) result);                            
             setRowData(myList);
        }

b)A AsyncDataProvider to refresh the current displayed page, where:

protected void onRangeChanged(HasData<myObject> display) {

            final Range range = display.getVisibleRange();
            int start = range.getStart();
            int end = start + range.getLength();

            List<myObject> dataInRange = myList.subList(start, end);
            // Push the data back into the list.                   
           setRowData(start, dataInRange);

}

This works fine, refreshing the table when new data arrives from the server ..BUT....It jumps to the first page of my displayed table regardless he current page (Page size=20). It is like it is ignoring the start and dataInRange values of the onRangeChanged method

the sentence: setRowData(myList);

Is firing properly the onRangeChanged event of the DataProvider, but some how the 'start' values get 0

Any tip? Many thanks

1

There are 1 best solutions below

2
Adam On

The problem is that when you call setRowData(myList); you also change the row range.

See the documentation:

Set the complete list of values to display on one page.

Equivalent to calling setRowCount(int) with the length of the list of values, setVisibleRange(Range) from 0 to the size of the list of values, and setRowData(int, List) with a start of 0 and the specified list of values.

Literally, below is the implementation:

public final void setRowData(List<? extends T> values) {
  setRowCount(values.size());
  setVisibleRange(0, values.size());
  setRowData(0, values);
}