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