Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Refresh data in a Grid with dynamic created columns
Hi,
I have the following grid where its columns are created with the addColumn() function.
public class MyGrid extends Grid {
public MyGrid () {
setSizeFull();
setSelectionMode(SelectionMode.NONE);
addColumn("Task", String.class);
getColumn("Task").setSortable(false);
addColumn("SubTask", String.class);
getColumn("SubTask").setSortable(false);
for (int i=0; i<24; i++) {
// add 24 cols corresponding to the 24 hours of a day
String columnTimeLabel = String.valueOf(i) + ":00";
addColumn(columnTimeLabel, String.class);
getColumn(columnTimeLabel).setSortable(false);
}
fillGridWithData();
}
public void fillGridWithData(){
// here getData() is a function that returns the grid data
String [] [26] gridData = getData();
for (int i = 0; i<gridData .length; i++){
String gridRowData[26] = gridData; addRow(gridRowData); } }}
public class GridView extends VerticalLayout implements View {
private MyGrid grid;
public GridView () {
setSizeFull();
grid = new MyGrid ();
addComponent(grid);
}
}
My question is how can I refresh the data in MyGrid if at some point getData() returns a new set of data?
Final answer to your question would require more detailed knowledge about your application context. However since it seems that you want to show kind of small dynamically changing data set in a Grid, the most natural way would be to use Container. So instead of doing it in they way you propose now, I would recommend to create some sort of Container for the data, and update the data in the Container. When you create the Grid, you simply set the Grid to use Container as data source.