use of com.vaadin.flow.data.bean.PeopleGenerator in project flow-components by vaadin.
the class GridViewBasicPage method createCallBackDataProvider.
private void createCallBackDataProvider() {
Grid<Person> grid = new Grid<>();
/*
* This Data Provider doesn't load all items into the memory right away.
* Grid will request only the data that should be shown in its current
* view "window". The Data Provider will use callbacks to load only a
* portion of the data.
*/
PeopleGenerator generator = new PeopleGenerator();
grid.setItems(DataProvider.fromCallbacks(query -> IntStream.range(query.getOffset(), query.getOffset() + query.getLimit()).mapToObj(index -> generator.createPerson(index + 1)), query -> 100 * 1000 * 1000));
grid.addColumn(Person::getFirstName).setHeader("Name");
grid.addColumn(Person::getAge).setHeader("Age");
grid.setId("lazy-loading");
addCard("Grid with lazy loading", grid);
}
use of com.vaadin.flow.data.bean.PeopleGenerator in project flow-components by vaadin.
the class GridViewContextMenuPage method createContextSubMenu.
private void createContextSubMenu() {
Grid<Person> grid = new Grid<>();
ListDataProvider<Person> dataProvider = DataProvider.ofCollection(getItems());
grid.setDataProvider(dataProvider);
grid.addColumn(Person::getFirstName).setHeader("Name");
grid.addColumn(Person::getAge).setHeader("Age");
GridContextMenu<Person> contextMenu = new GridContextMenu<>(grid);
GridMenuItem<Person> insert = contextMenu.addItem("Insert");
insert.getSubMenu().addItem("Insert a row above", event -> {
Optional<Person> item = event.getItem();
if (!item.isPresent()) {
// no selected row
return;
}
List<Person> items = (List) dataProvider.getItems();
items.add(items.indexOf(item.get()), new PeopleGenerator().createPerson(items.size() + 1));
dataProvider.refreshAll();
});
insert.getSubMenu().add(new Hr());
insert.getSubMenu().addItem("Insert a row below", event -> {
Optional<Person> item = event.getItem();
if (!item.isPresent()) {
// no selected row
return;
}
List<Person> items = (List) dataProvider.getItems();
items.add(items.indexOf(item.get()) + 1, new PeopleGenerator().createPerson(items.size() + 1));
dataProvider.refreshAll();
});
grid.setId("context-submenu-grid");
addCard("Context Menu", "Using Context Sub Menu With Grid", grid, contextMenu);
}
Aggregations