Vaadin Grid Iterate all rows and print values of each column

Hi i m using Vaadin 8.1.0

and Trying to print the values of each row i m not able to print . can anyone help this.

Here is my code

Grid grid = new Grid<>();
grid.setWidth(“100%”);
grid.setColumnReorderingAllowed(true);
grid.setSelectionMode(SelectionMode.SINGLE);

ArrayList personDataList = new ArrayList();
for (int i = 0; i <= 15; i++) {
PersonData p = new PersonData();
p.setId(100);
p.setName(“AAA”);
p.setWeight(50.20);
p.setDob(new Date());
personDataList.add(p);
}

grid.addColumn(PersonData::getName).setCaption(“Name”);
grid.addColumn(PersonData::getWeight).setCaption(“Weight”);
grid.addColumn(PersonData::getDob, new DateRenderer(new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”)))
.setCaption(“DATE”);
grid.setItems(personDataList);

below is how i am trying to read data

List<Column<PersonData, ?>> s=grid.getColumns();
Column<PersonData, ?> c=s.get(0);

How can i get values of each column.

Regards
Nagaraj RC

You need to get the Grids DataProvider (there is getDataProvider), which in default case is ListDataProvider. Check the API of ListDataProvider how to iterate values.

https://vaadin.com/api/8.1.1/com/vaadin/data/provider/ListDataProvider.html

E.g. getItems() is a good start.

HI Tatu Lund

Thanks for your answer i tried ur way as below

ListDataProvider s=(ListDataProvider) grid.getDataProvider();
ArrayList s1=(ArrayList) s.getItems();
System.out.println(“Value=”+s1.get(0).getId());

This is giving me the proper values.
but when i pass other POJO class insted of PersonData that will have other field insted if getId() .
is there a way that i can get the data by column.
i am trying to export the complete Grid data into excel file including column names also.

Regards
Nagaraj RC

Hello,

Did you figure any way to do this? I have a similar issue at hand.

Hi Guys,

Any solution for the above problem. I am having the same problem as Nagaraj RC. I need to migrate all the grid data to excel. Please let me if you have solutions. Thank you.

How about having all you Pojos derive from the same base class ?