Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
475
Getting all RowItem for currently selected page
posted

Hi,

i have added pageChangeListener to GridView, i want to get all RowItems for the currently selected page,

getRows() method giving previous page RowItems, can you people give me any suggestion,

any help will be appreciated.

 

Thanks

Dayananda B V 

  • 1579
    posted

    Hello, Dayananda B V!

    Unfortunatelly you canot use getRows() for that aim. But there is a trick, you can apply for your purpose. In the event handler you can do the following:

    HtmlGridView grid = (HtmlGridView) e.getComponent();

    List data = (List) grid.getDataSource().getWrappedData();

    where data  is the actual underlying data source (not limited by page size). Then you have the page size and the new page index, accordingly:

    int pageSize = grid.getPageSize();

    int newIndex = e.getNewPageIndex();

     By having the whole data list for the data source, the new index and the page size, you can now estimate the list of rows for the current page:

    int startIndex = newIndex * pageSize;

    int endIndex = startIndex + pageSize - 1;

     Now you can iterate through the list containing all rows (data), starting from the startIndex and ending with the endIndex and get the property you need, in my example:

    for(int i = startIndex; i <= endIndex; i++){

    Clients client = (Clients) data.get(i);

    str += ((Clients) data.get(i)).getId() +
    "; ";

    }

    and display the values

    msg = "Clients on page: " + str;

    Thanks!

    -- Bozhidar