Grid je komponenta pro zobrazení tabulkových dat (ve formátu sloupců a řádek). Zde je ochutnávka toho, co grid umí: demo.vaadin.com/sampler/#ui/grid.
V tomto příspěvku si vytvoříme jednoduchý grid, který bude zobrazovat data lidí (jméno, příjmení a den narození). Kód můžete umístit do metody init třídy, která dědí z UI.
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
// creating data
List<Person> persons = Arrays.asList(
new Person("John", "Smith", LocalDate.of(2001, 3, 17)),
new Person("Marie", "Jones", LocalDate.of(1987, 11, 26)),
new Person("Dave", "Williams", LocalDate.of(1995, 1, 5))
);
// creating grid
Grid<Person> grid = new Grid<>();
grid.setItems(persons);
grid.addColumn(Person::getName).setCaption("Name");
grid.addColumn(Person::getSurname).setCaption("Surname");
grid.addColumn(Person::getDateOfBirth).setCaption("Date of birth");
grid.setHeightByRows(persons.size());
layout.addComponent(grid);
setContent(layout);
}
