Refresh data in a Grid with dynamic created columns


I have the following grid where its columns are created with the addColumn() function.

public class MyGrid extends Grid {
public MyGrid () {
addColumn(“Task”, String.class);
addColumn(“SubTask”, String.class);

         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);


    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[i]

public class GridView extends VerticalLayout implements View {
private MyGrid grid;
public GridView () {
grid = new MyGrid ();

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.