Deploying SimplePager with DataGrid and AsyncDataProvider

How to implement SimplePager using AsyncDataProvider when the data grid is equipped with the values ​​emitted from the server.

+4
source share
1 answer

You need to create a class that extends AsyncDataProvider . In this class, you can override the onRangeChanged method.

My class, for example, looks like this:

 public class AsyncListProviderVisit extends AsyncDataProvider<MyObject> { @Override protected void onRangeChanged(HasData<MyObject> display) { // Get the new range. final Range range = display.getVisibleRange(); /* * Query the data asynchronously. If you are using a database, you can * make an RPC call here. We'll use a Timer to simulate a delay. */ final int start = range.getStart(); int length = range.getLength(); Service.Util.getInstance().getPartOfImmoObjects(start, length, new AsyncCallback<List<MyObject>>() { @Override public void onFailure(Throwable caught) { ConfirmationPanel cp = new ConfirmationPanel(); cp.confirm("Error!", "An Error occurred during data-loading."); } @Override public void onSuccess(List<MyObject> result) { if (result != null) { updateRowData(start, result); } } }); } } 

Then you need to create a DataGrid, AsyncProvider and Pager, for example:

 // Create a CellList. DataGrid<LcVisits> grid = new DataGrid<LcVisits>(); // Create a data provider. AsyncListProviderVisit dataProvider = new AsyncListProviderVisit(); // Add the cellList to the dataProvider. dataProvider.addDataDisplay(grid); // Create paging controls. SimplePager pager = new SimplePager(); pager.setDisplay(grid); // and add them to your panel, container, whatever container.add(grid); container.add(pager); 

change

as Andre pointed out in his comment, you also need to get the correct line counter for the query. I did this with a "fake object", which I add to my list and then delete it on the client side. You can then call updateRowCount(rowCount, isExact) , where isExcact is a boolean that indicates whether the row count you entered was accurate or just evaluated.

+7
source

Source: https://habr.com/ru/post/1493444/


All Articles