Question

I am facing problem with lastButton of SimplePager. I have 3 pages in celltable, Page size=11 (1 empty record + 10 records(with value)), Total record=26.

I used CustomerPager by extending SimplePager.

In 1st attempt 1+10 records display in celltable : Next & Last page button is enabled (First & Prev button disabled) which is correct. But LastPage button not working... :( Dont know whats the issue... (event not fires)

Strange behavior:

@1 Last page button is working only when I visit to last page(3 page in my case).

@2 Assume I am on 1st page n I moved to 2nd page(Total 3 pages in celltable). that time all buttons are enabled which is correct. In this case Last button is working but behave like Next Button

My GWT application integrated into one of our product so cant debug it from client side.

May be index value is improper in setPage(int index) method from AbstractPager

Code flow is as follows for Last button

//From SimplePager

lastPage.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
          lastPage();
        }
      });


       @Override
  public void lastPage() {
    super.lastPage();
  }

 // From AbstractPager
  /**
   * Go to the last page.
   */
  protected void lastPage() {
    setPage(getPageCount() - 1);
  }
 protected void setPage(int index) {
    if (display != null && (!isRangeLimited || !display.isRowCountExact() || hasPage(index))) {
      // We don't use the local version of setPageStart because it would
      // constrain the index, but the user probably wants to use absolute page
      // indexes.
      int pageSize = getPageSize();
      display.setVisibleRange(pageSize * index, pageSize);
    }
  }

or may be some conditions false from above code(from setPage())

actual record = 26 and 3 Empty record (1st Empty record/page)

May b problem with dataSize :|

How I can check number of pages based on the data size? ?

How can I solve this problem?

Was it helpful?

Solution 4

Only added cellTable.setRowCount(int size, boolean isExact) in OnRange change method AsyncDataProvider. My problem is solved :)

protected void onRangeChanged(HasData<RecordVO> display) {
//----- Some code --------
cellTable.setRowCount(searchRecordCount, false);
//----- Some code --------
}

OTHER TIPS

edit: I found out that the default constructor of the pager doesn't give you a "last" button, but a "fast forward 1000 lines" button instead (horrible, right?) .

call the following constructor like so, and see your problem solved:

SimplePager.Resources resources = GWT.create(SimplePager.Resources.class); SimplePager simplePager = new SimplePager(TextLocation.CENTER, resources , false, 1000, true);

the first "false" flag turns off the "fastforward button" and the last "true" flag turns on the "last" button.

also the last button will work only if the pager knows the total amount of records you have.

you can call the table's setRowCount function to update the total like so:

int totalRecordsSize = 26; //the total amount of records you have boolean isTotalExact = true; //is it an estimate or an exact match table.setRowCount(totalRecordsSize , isTotalExact); //sets the table's total and updates the pager (assuming you called pager.setDisplay(table) before)

if you are working with an attached DataProvider, than all it's updateRowCount method instead (same usage).

Without seeing more of your code, this is a hard question to answer as there could be multiple places where things are going wrong.

I would make sure you call setDisplay(...) on your SimplePager so it has the data it needs calculate its ranges.

If you can't run in devmode, I recommend setting up some GWT logging in the browser (write the logs to a popup panel or something, see this discussion for an example).

I think the problem is related with condition in the setPage(). Try putting SOP before if condition or debug the code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top