Reputation: 4614
I am using my GWT 2.3 Celltable & SimplePager
Written CustomPager by extending SimplePager class.
Used ListBox to show different page size for celltable like 10,20,50,100
I am showing 11 record in celltable when page size is 10. (1 empty record(row) + 10 records(rows)
when pageSize = 20 then 21 rows(records), when pageSize = 50 then 51 rows(records), when pageSize = 100 then 101 rows(records).
Whenever selected page size 50 or 100, pager & display returning correct values so pagination working correctly, but not working in case of 10 & 20. Strange :|
After debugging found following thing:
When page size is 10 or 20, onclick of lastPage button of pager getting Incorrect pageIndex of pager & incorrect values of startIndex.
wrong startindex = display.getVisibleRange().getStart()
//Following method called when button click event fires
protected void onRangeChanged(HasData<RecordVO> display) {
info("Called onRangeChanged method of AsyncDataProvider");
eventType = "PAGINATION";
setPrevPageIndexForChangedRecord();
cellTable.setRowCount(searchRecordCount, false);
startRowIndexOfPage = display.getVisibleRange().getStart(); // startRowIndex;
// ------ My code is here
}
Incorrect value is as follows when clicked on pagers Last button assume page size=10 i.e 1 dummy record + 10 Actual record.
startRowIndexOfPage = display.getVisibleRange().getStart(); // startRowIndex;
info("Start row index of page = "+startRowIndexOfPage);
info("GWT Current page index = "+pager.getPage());
info("GWT Total page count = "+pager.getPageCount());
info("Gwt Total page size = "+pager.getPageSize());
info("Gwt page start index = "+pager.getPageStart());
Incorrect Output onclick of pagers last button when page size=10 :
(-:-) 2013-03-05 09:53:22,136 [INFO ] Start row index of page = 990
(-:-) 2013-03-05 09:53:22,150 [INFO ] GWT Current page index = 90
(-:-) 2013-03-05 09:53:22,178 [INFO ] GWT Total page count = 91
(-:-) 2013-03-05 09:53:22,191 [INFO ] Gwt Total page size = 11
(-:-) 2013-03-05 09:53:22,204 [INFO ] Gwt page start index = 990
Main problem is that pager.getPage() returning 90 instead of last page index :(
Is there any way to solve this problem? Please provide me some pointers/solution for this question.
Thanks in advance.
Upvotes: 2
Views: 1793
Reputation: 895
Try using following arithmetic operation to find startRowIndexOfPage
-
startRowIndexOfPage = display.getVisibleRange().getStart() - pager.getPage();
And make sure page limit is 10 not 11
. And make your pager unaware of the extra empty row you are adding.
Upvotes: 1
Reputation: 121998
Have you tried like this ??
@Override
protected void onRangeChanged(HasData<YourObject> display)
{
int start = display.getVisibleRange().getStart();
int end = start + display.getVisibleRange().getLength();
if (ListOfYourObjects != null)
{
end = end >= ListOfYourObjects.size() ? ListOfYourObjects.size(): end;
List<YourObject> sub = ListOfYourObjects.subList(start, end);
updateRowData(start, sub);
}
}
Upvotes: 0