Search in sources :

Example 1 with ColumnTextAlign

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

the class GridViewConfiguringColumnsPage method createColumnApiExample.

private void createColumnApiExample() {
    Grid<Person> grid = new Grid<>();
    GridSelectionModel<Person> selectionMode = grid.setSelectionMode(SelectionMode.MULTI);
    grid.setItems(getItems());
    Column<Person> idColumn = grid.addColumn(Person::getId).setHeader("ID").setFlexGrow(0).setWidth("75px");
    grid.addColumn(Person::getFirstName).setHeader("Name").setResizable(true);
    // Setting a column-key allows fetching the column later
    grid.addColumn(Person::getAge).setHeader("Age").setKey("age");
    grid.getColumnByKey("age").setResizable(true);
    NativeButton idColumnVisibility = new NativeButton("Toggle visibility of the ID column");
    idColumnVisibility.addClickListener(event -> idColumn.setVisible(!idColumn.isVisible()));
    NativeButton userReordering = new NativeButton("Toggle user reordering of columns");
    userReordering.addClickListener(event -> grid.setColumnReorderingAllowed(!grid.isColumnReorderingAllowed()));
    NativeButton freezeIdColumn = new NativeButton("Toggle frozen state of ID column");
    freezeIdColumn.addClickListener(event -> idColumn.setFrozen(!idColumn.isFrozen()));
    NativeButton freezeSelectionColumn = new NativeButton("Toggle frozen state of selection column");
    GridMultiSelectionModel<?> multiSlection = (GridMultiSelectionModel<?>) selectionMode;
    freezeSelectionColumn.addClickListener(event -> multiSlection.setSelectionColumnFrozen(!multiSlection.isSelectionColumnFrozen()));
    RadioButtonGroup<ColumnTextAlign> alignments = new RadioButtonGroup<>();
    alignments.setItems(ColumnTextAlign.values());
    alignments.setLabel("Text alignment for the Age column");
    alignments.setValue(ColumnTextAlign.START);
    alignments.addValueChangeListener(event -> grid.getColumnByKey("age").setTextAlign(event.getValue()));
    grid.setId("column-api-example");
    idColumnVisibility.setId("toggle-id-column-visibility");
    userReordering.setId("toggle-user-reordering");
    freezeIdColumn.setId("toggle-id-column-frozen");
    freezeSelectionColumn.setId("toggle-selection-column-frozen");
    alignments.setId("toggle-text-align");
    addCard("Configuring columns", "Column API example", grid, new VerticalLayout(idColumnVisibility, userReordering, freezeIdColumn, freezeSelectionColumn, alignments));
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) GridMultiSelectionModel(com.vaadin.flow.component.grid.GridMultiSelectionModel) Grid(com.vaadin.flow.component.grid.Grid) RadioButtonGroup(com.vaadin.flow.component.radiobutton.RadioButtonGroup) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Person(com.vaadin.flow.data.bean.Person) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign)

Aggregations

ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 Grid (com.vaadin.flow.component.grid.Grid)1 GridMultiSelectionModel (com.vaadin.flow.component.grid.GridMultiSelectionModel)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 RadioButtonGroup (com.vaadin.flow.component.radiobutton.RadioButtonGroup)1 Person (com.vaadin.flow.data.bean.Person)1