How to refresh a Grid!

Hi everyone, I’m working with vaadin framework and trying ti fill a Grid with some data that I get from a rest.
The thing is that the data im asking to the rest is quite large so I need to insert into the Grid the first item I receive and make it visible on Grid, that way we have an speed sensation.

this si part of my code

			try {
						jsonItems = mapper.writeValueAsString(dmMaquina);
						// System.out.println("X:" + jsonItems);
						DatosMaquinas m = sendPost(jsonItems);
						if (m.getFechaUltimaConexion() == null && m.getFechaUltimaDispensacion() == null) {
							listaMaquinas.add(dmMaquina);
							System.out.println("Tamaño Lista: "+listaMaquinas.size());
							gridMaquinas.setItems(listaMaquinas);
							gridMaquinas.getDataProvider().refreshItem(dmMaquina);
							System.out.println("Condicion 1");
						} else if (m.getFechaUltimaConexion() != null && m.getFechaUltimaDispensacion() == null) {
							m.setFechaUltimaDispensacion(fecha);
							listaMaquinas.add(m);
							System.out.println("Tamaño Lista: "+listaMaquinas.size());
							gridMaquinas.setItems(listaMaquinas);
							gridMaquinas.getDataProvider().refreshItem(m);
							System.out.println("Condicion 2");
						}else if (m.getFechaUltimaConexion() == null && m.getFechaUltimaDispensacion() != null) {
							m.setFechaUltimaConexion(fecha);
							listaMaquinas.add(m);
							System.out.println("Tamaño Lista: "+listaMaquinas.size());
							gridMaquinas.setItems(listaMaquinas);
							gridMaquinas.getDataProvider().refreshItem(m);
							System.out.println("Condicion 3");
						}else{
							listaMaquinas.add(m);
							System.out.println("Tamaño Lista: "+listaMaquinas.size());
							gridMaquinas.setItems(listaMaquinas);
							gridMaquinas.getDataProvider().refreshItem(m);
							System.out.println("Else");
						}

					} catch (JsonProcessingException e) {
						e.printStackTrace();
					} catch (Exception e) {
						e.printStackTrace();
					}
				} catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}

In this code as you can see occordingly with the conditionals Im trying to add the item m or dmMaquinas into the grd hoping thta it can show it right away, however is not working that way, Grid is updated fully when the rest stop working and all the data is ready, and it seems that the app is taking all the time in the world.

I have to say that the code I shared is inside a for clause, so the m value is changing, idk maybe is important to know.

If is there any way that I can do this please let me know, thanks in advancce Guys!

The method [DataProvider.refreshItem(…)]
(https://vaadin.com/download/release/8.3/8.3.2/docs/api/com/vaadin/data/provider/DataProvider.html#refreshItem-T-) should be used when you change existing item in Grid. If you add items to grid, you should use DataProvider.refreshAll().

Tatu Lund:
The method [DataProvider.refreshItem(…)]
(https://vaadin.com/download/release/8.3/8.3.2/docs/api/com/vaadin/data/provider/DataProvider.html#refreshItem-T-) should be used when you change existing item in Grid. If you add items to grid, you should use DataProvider.refreshAll().

Thanks for your response Tatu Lund, I really appreciate that, I tried that with:

gridMaquinas.getDataProvider().refreshAll();

But still not working the way I want, is uppdated alll the grid aat the end with the 52 items, and is not adding them one by one. Maybe I’m not doing it in the right place I guess, I put it after and before insert the new element into the ArrayList and still not working.

Thanks again!

I have to say that the class that Im inserting into the grid is not a table on db, so Im not inserting a model, is just a class that I have, I do not know if this have some effect.

I’m not sure I understand what you mean, but if what you want is to update a Grid from a loop that takes time, you can use a background Thread and Push. See this video: https://www.youtube.com/watch?v=EG6iizVH1rY and [this part]
(https://vaadin.com/docs/v8/framework/advanced/advanced-push.html) of the documentation.

Thanks I wil check that and let you know.

Cheers!

Tatu Lund:
The method [DataProvider.refreshItem(…)]
(https://vaadin.com/download/release/8.3/8.3.2/docs/api/com/vaadin/data/provider/DataProvider.html#refreshItem-T-) should be used when you change existing item in Grid. If you add items to grid, you should use DataProvider.refreshAll().

DataProvider.refreshItem() does not refresh the row in the Grid with updated values.
Please find my question here https://vaadin.com/forum/thread/17234067

Appreciate if you could help me solve this problem.

Alejandro Duarte:
I’m not sure I understand what you mean, but if what you want is to update a Grid from a loop that takes time, you can use a background Thread and Push. See this video: https://www.youtube.com/watch?v=EG6iizVH1rY and [this part]
(https://vaadin.com/docs/v8/framework/advanced/advanced-push.html) of the documentation.

This works when you scroll the items than it will visible to the browser.

In my case i need to display latest created row in first position so i always need to place newly created item in first position. so in that case it doesn’t reflect to the browser instantly.