2

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.

StackOverFlow
  • 4,486
  • 12
  • 52
  • 87
  • Post your query string, or your code for fetching the result when last pagination button is clicked – Abhijith Nagaraja Feb 22 '13 at 13:15
  • Can you tell us, How many records you have and when you select 10 or 20 and click on last button, what values you are expecting and what it is returning. – Adarsha Feb 28 '13 at 13:48
  • @Adarsha Total 1000 Records. On click of last button page should set to last page so that last 10 records will display in table when page size=10 selected from listbox. But on click of last button pager moving to 91th page :( Can we identify/check in OnRangeChange method i.e. user clicks last button – StackOverFlow Mar 01 '13 at 06:35
  • In your question you mentioned, when page size is 10 you are displaying 10 + empty row = 11 rows. Is empty row part of that 1000 records ????? or its just one dummy row you are explicitly adding to each page ???? more over when page size is 10, You can display only 10 records in the cell table. empty row + 9 records .... – Adarsha Mar 01 '13 at 07:53
  • @Adarsha Yes, when page size is 10 I am showing 10 + empty row = 11 rows. Empty row is not a part of 1000 Records, 1 Empty row is needed on each page. Normal user will not treat empty row as record so 1 empty row + 10 row(record). When page size=10 means 10 records then empty row+ 9 rec not makes sense for normal user. – StackOverFlow Mar 01 '13 at 08:00

2 Answers2

1

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.

Adarsha
  • 895
  • 4
  • 7
  • How to unaware of the extra empty row to pager? by setting page size to 10? if I set page limit to 10 then only 10 records will display 1 dummy record + 9 actual record. – StackOverFlow Mar 11 '13 at 11:18
  • How to add empty record at the start of page after populating actual record list? Using AsyncDataProvider to update calltable's page – StackOverFlow Mar 12 '13 at 10:09
0

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);
        }   
}
Adarsha
  • 895
  • 4
  • 7
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • ListOfYourObjects is Total record retrieved form server ? I am fectching required data only. Can you explain why ListOfYourObjects is required? – StackOverFlow Mar 04 '13 at 06:27
  • ListOfYourObjects is the list which you are populating to the grid at that particular combo change. – Suresh Atta Mar 04 '13 at 06:37
  • I already tried you solution. When page size=10 Records-1000 Onclick of last button page should navigate to 100th page. onclick of last button getting incorrect pageIndex -> pager.getPage() & Incorrect value of start = display.getVisibleRange().getStart(); – StackOverFlow Mar 04 '13 at 10:07
  • Can u please tell what are those incorrect values? So that someone can guess whats going wrong.. – Suresh Atta Mar 05 '13 at 04:17
  • @ The Suresh Atta Added incorrect values. Check question is edited. – StackOverFlow Mar 05 '13 at 04:32
  • 1
    You are adding a dummy record at the end of each page right.So its becoming total of 1100 record.check 990/11=90 – Suresh Atta Mar 05 '13 at 06:23
  • I am adding a dummy record at the start of each page. When pagesize=10 from listbox then 1000 Actual record+100 dummy record = 1100 record. It works fine in case of page size=50 & 100 :) How to resolve this issue in case of page size 10 & 20? – StackOverFlow Mar 05 '13 at 09:35
  • When page size 50 when you keep going with in 20 clicks(10 in case of 100) your will complete all of you records(1000 records) so the page index is wont increase until the empty record count become 50 or 100.Finally – Suresh Atta Mar 05 '13 at 14:17
  • And do not populate the empty record with your list of object.Add that empty record after you populated your list. – Suresh Atta Mar 06 '13 at 06:35
  • as per Adarsha's ans I will set pager size to 10 in case of 10 not 11. will populate 10 actual record into table. I am using AsyncDataProvider to update celltable i.e.[updateRowData(startRowIndexOfPage, recordVList);]. Not using ListDataProvider. How to add empty record at the start of page after populating actual record list? – StackOverFlow Mar 12 '13 at 10:07
  • http://stackoverflow.com/questions/7108456/gwt-celltable-adding-extra-row/7109021#7109021 – Suresh Atta Mar 18 '13 at 07:20
  • I am not using list provider, using AsyncDataProvider so How to add empty record in asyndataprovider? – StackOverFlow Apr 23 '13 at 04:57