Search in sources :

Example 1 with GridSingleSelectionModel

use of com.vaadin.flow.component.grid.GridSingleSelectionModel in project flow-components by vaadin.

the class GridSingleSelectionPage method buildToggle.

@SuppressWarnings("rawtypes")
private NativeButton buildToggle(Grid grid, String id) {
    NativeButton button = new NativeButton("Toggle deselectAllowed", e -> {
        GridSingleSelectionModel gssm = (GridSingleSelectionModel) grid.getSelectionModel();
        gssm.setDeselectAllowed(!gssm.isDeselectAllowed());
    });
    button.setId(id);
    return button;
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) GridSingleSelectionModel(com.vaadin.flow.component.grid.GridSingleSelectionModel)

Example 2 with GridSingleSelectionModel

use of com.vaadin.flow.component.grid.GridSingleSelectionModel in project flow-components by vaadin.

the class GridSingleSelectionPage method setDeselectAllowedAndSetItems.

private Grid<String> setDeselectAllowedAndSetItems() {
    Grid<String> grid = new Grid<>();
    GridSingleSelectionModel gssm = (GridSingleSelectionModel) grid.getSelectionModel();
    // Set deselectAllowed to false
    gssm.setDeselectAllowed(false);
    // Set Items for grid
    grid = setItemsGrid(grid, ITEMS_GRID);
    Button text = new Button();
    grid.addSelectionListener(e -> {
        if (e.getFirstSelectedItem().isPresent()) {
            text.setId("item" + e.getFirstSelectedItem().get());
            text.setText("The row " + e.getFirstSelectedItem().get() + " is selected");
            add(text);
        }
    });
    return grid;
}
Also used : GridSingleSelectionModel(com.vaadin.flow.component.grid.GridSingleSelectionModel) Button(com.vaadin.flow.component.button.Button) NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid)

Aggregations

GridSingleSelectionModel (com.vaadin.flow.component.grid.GridSingleSelectionModel)2 NativeButton (com.vaadin.flow.component.html.NativeButton)2 Button (com.vaadin.flow.component.button.Button)1 Grid (com.vaadin.flow.component.grid.Grid)1