Search code examples
javagwtpaginationgwt-celltable

How to get the total row count for GWT CellTable pagination in


I'm trying to implement paging in a CellTable but it's currently showing "1-10 of 10" records instead of "1-10 of 1000" records. I'm not sure where I can update the total record count. My AsyncDataProvider looks like this:

    AsyncDataProvider<OutletSearchVO> latestProvider = new AsyncDataProvider<OutletSearchVO>() {

        @Override
        protected void onRangeChanged(HasData<OutletSearchVO> display) {
            final int start = display.getVisibleRange().getStart();
            int length = display.getVisibleRange().getLength();
            AsyncCallback<List<OutletSearchVO>> callback = new AsyncCallback<List<OutletSearchVO>>() {
                @Override
                public void onFailure(Throwable caught) {
                    Window.alert(caught.getMessage());
                }

                @Override
                public void onSuccess(List<OutletSearchVO> result) {
                    updateRowData(start, result);
                }
            };
            // The remote service that should be implemented
            service.getOutletPage(start, length, callback);

        }
    };

The SQL I'm using to grab the records is similar to this:

SELECT *
  FROM (SELECT outlet_id,
           outlet_name,
           image,
           ROWNUM rn
      FROM (  SELECT outlet_id outlet_id,
                     account_name outlet_name,
                     image_score image,
                FROM outlets)
            ORDER BY OOI.created_on DESC, OOI.account_name))
WHERE rn > ? AND rn < ?    

The question marks are replaced by the start and end range in a prepared statement.


Solution

  • You have to call updateRowCount from within your AsyncDataProvider (similar to how you call updateRowData), which means you have to ask your server for that count (or at least an approximation, and then choose whether you pass a true or false as the second argument to updateRowCount).

    Of course, you can also call updateRowCount from outside the onRangeChange, particularly if you can know upfront how many rows you'll have, and that number is not going to change that much.