on click generate extra column in grid

hello , i want to have a button… when i press on it:

  • new column appears with checkboxes, the checkbox of the selected row from grid will be pre-selected

  • the user has now the choice to select multiple rows by marking the checkboxes or to select the “Select All” checkbox in header

addButton = new Button(“Show checkboxes”);
add(addButton);

    addButton.addClickListener(event -> {
        Column<EntitySystem> checkboxColumn = grid.addComponentColumn(item -> {
            Checkbox checkbox = new Checkbox();
            checkbox.setValue(false); // unselect by default
            checkbox.addValueChangeListener(event2 -> {
                // Handle checkbox value changes here
            });

            if (item.equals(grid.asSingleSelect().getValue())) {
                checkbox.setValue(true);
            }
            return checkbox;
        });

        selectAllCheckbox = new Checkbox("Select All");

        checkboxColumn.setHeader(selectAllCheckbox);
    });

this is my code so far

  • the problem is that it is simply appended to the grid as the “last” column, but i want it to be the first column.
  • additionally the “Select All” functionality is not working yet

Are you sure you are not manually implementing multi-selection mode? Grid | Components | Design System | Vaadin 14 Docs

omg yeah this is exactly what i want LOL

is there a way to iterate through each row in the grid? to get the value which checkbox is checked?

grid.getSelectedItems?

At least you get instantly only the selected :sweat_smile:

oooh that would be perfect

if this works

gonna try that out in a sec

how can i reference the new column with the checkboxes?

can i give it a header “Status”? so that i can reference it by:

grid.getColumnByKey(“Status”).setFooter(confirmExportButton);

i tried::

“grid.getColumns().get(0).setFooter(confirmExportButton);”

but index 0 isnt the “checkbox”-column

of multi-select

is it not possible?

You can’t access this column from java

so theres no way to access this?

You’re probably easier off looking for some other solution

hmmmm