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
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:
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 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:
Clients client = (Clients) data.get(i);
}
and display the values
msg = "Clients on page: " + str;
Thanks!
-- Bozhidar
Hi Bozhidar,
Thanks you very much for qucik replay, the solution you given is for getting the data, but i want RowItem itself
for example look at this code, you can get a idea what i am looking for.
public void onPageSelectUnits(PageChangeEvent evt){ try{
Iterator currentPageRowItems = getUnitsGrid().getRows().iterator(); // here i am getting previous page RowItems
while (currentPageRowItems.hasNext()) { RowItem rowItem = (RowItem) currentPageRowItems.next(); { rowItem.setSelected(true); } }
}catch(Exception e){
e.printStackTrace();
Hi, Dayananda B V!
There is no way to get all RowItems from GridView yet. You can get the data source and so my suggestion was to add a boolean property to the bean representing the data in the rows and to set it to true instead of rowItem.setSelected(true); in your action listener. I hope this helps.
Thank your very much for your prompt replay, it's ok to set boolean variable true, my problem is have a check box in GridView which is automaticaly added by this code
"<ig:columnSelectRow showSelectAll="true"/>,
so actually i have to set check box as a selected depedning on some condition. is this possible? is there any way? if i am able to get all RowItems from GridView for the currently selected page than no problem for me, but as you told there is no such facility. And you are suggesting use some boolena variable to do. my question is who can set the check box as selected. using boolean variable, is this possible.
thanks
Try to data bind your grid after getting it in the action listener, e.g.:
grid = (HtmlGridView) e.getSource();
grid.dataBind();
and then use getRows();
It will now return the list of the currently displayed Row Items.
I hope this will work.
thanks your excellent support, the suggestion you given i.e. dataBind works great, thanks once again
Glad for being useful!
Regards!
--Bozhidar