Skip to content

Instantly share code, notes, and snippets.

@johannest
Created January 10, 2024 12:13
Show Gist options
  • Save johannest/f94e76dadfb8da6876179c2fc3570130 to your computer and use it in GitHub Desktop.
Save johannest/f94e76dadfb8da6876179c2fc3570130 to your computer and use it in GitHub Desktop.
package com.example.application.views;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.router.Route;
import java.util.ArrayList;
import java.util.List;
@Route(value = "test5")
public class TestView4 extends Div {
public TestView4() {
setSizeFull();
Grid<Person> grid1 = new Grid<>();
grid1.setAllRowsVisible(true);
grid1.addColumn(p -> p.id).setHeader("ID");
grid1.addColumn(p -> p.name).setHeader("Name1");
grid1.addColumn(p -> p.name).setHeader("Name2");
grid1.addColumn(p -> p.name).setHeader("Name3");
grid1.addColumn(p -> p.name).setHeader("Name4");
grid1.addColumn(p -> p.name).setHeader("Name5");
grid1.addColumn(p -> p.name).setHeader("Name6");
grid1.addColumn(p -> p.name).setHeader("Name7");
grid1.setItems(fetchPersons(1));
Grid<Person> grid2 = new Grid<>();
grid2.setAllRowsVisible(true);
grid2.addColumn(p -> p.id).setHeader("ID");
grid2.addColumn(p -> p.name).setHeader("Name1");
grid2.addColumn(p -> p.name).setHeader("Name2");
grid2.addColumn(p -> p.name).setHeader("Name3");
grid2.addColumn(p -> p.name).setHeader("Name4");
grid2.setItems(fetchPersons(1));
Grid<Person> grid3 = new Grid<>();
grid3.setAllRowsVisible(true);
grid3.addColumn(p -> p.id).setHeader("ID");
grid3.addColumn(p -> p.name).setHeader("Name1");
grid3.addColumn(p -> p.name).setHeader("Name2");
grid3.setItems(fetchPersons(1));
add(new HorizontalLayout(grid1, grid2, grid3));
}
private List<Person> fetchPersons(int limit) {
List<Person> tempList = new ArrayList<>();
for (int i = 0; i < limit; i++) {
Person e = new Person(i, "Name_" + (i));
tempList.add(e);
}
return tempList;
}
private static class Person {
private final int id;
private final String name;
private Person(int id, String name) {
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment