Search code examples
javavaadinvaadin7

Vaadin add Grid in table


I have the following code:

GridLayout grid = new GridLayout(3, 3);
grid.addComponent(btnRemove, 0, 0);
grid.addComponent(lblIstMenge, 1, 0);
grid.addComponent(btnAdd, 2, 0);
int i = 0;
if (vList != null && vList.size() > 0)
{
    for (VTr component : vList)
    {
        String transactionTypeName = component.getTransactionTypeName();
        transaktionTable.addItem(new Object[]{++transaktionTableCounter + "", 
          transactionTypeName,
          "123123123123123", grid, "Bemerkung^^^"}, 
          transaktionTableCounter);
        // System.out.println("Grid: " + grids.get(i));
      }
}

Which gives me something like this:

Example of grid

So the grid is added only in the last column. I have tried creating different grids for each column in a list but this did not work for me.

If you have any ideas or recommendations it would be nice.


Solution

  • When I move the instantiation of the buttons and grids inside the for loop it is working as expected.

                        int i = 0;
                        if (vList != null && vList.size() > 0)
                        {
                            for (VTr component : vList)
                            {
    
       btnAdd = new Button();
       btnAdd.setIcon(new ThemeResource("images/btnIncrease.png"));
                                btnRemove = new Button();
                                btnRemove.setIcon(new ThemeResource("images/btnDescrease.png"));
         GridLayout grid = new GridLayout(3, 3);
                        grid.addComponent(btnRemove, 0, 0);
                        grid.addComponent(lblIstMenge, 1, 0);
                        grid.addComponent(btnAdd, 2, 0);        
                                String transactionTypeName = component.getTransactionTypeName();
                                transaktionTable.addItem(new Object[]{++transaktionTableCounter + "", transactionTypeName,
                                    "123123123123123", grid, "Bemerkung^^^"}, transaktionTableCounter);
    
                            }
    
                        }