use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.
the class VirtualListPage method createTemplateFromValueProviderWithPeople.
private void createTemplateFromValueProviderWithPeople() {
VirtualList<Person> list = new VirtualList<>();
list.setHeight("100px");
DataProvider<Person, ?> dataProvider1 = DataProvider.ofCollection(createPeople(3));
DataProvider<Person, ?> dataProvider2 = DataProvider.ofCollection(createPeople(2));
DataProvider<Person, ?> dataProvider3 = DataProvider.ofCollection(createPeople(0));
list.setDataProvider(dataProvider1);
list.setRenderer(Person::getName);
NativeButton setProviderWith3Items = new NativeButton("Change dataprovider 1", evt -> {
list.setRenderer(Person::getName);
list.setDataProvider(dataProvider1);
});
NativeButton setProviderWith2Items = new NativeButton("Change dataprovider 2", evt -> {
list.setDataProvider(dataProvider2);
list.setRenderer(person -> String.valueOf(person.getAge()));
});
NativeButton setEmptyProvider = new NativeButton("Change dataprovider 3", evt -> list.setDataProvider(dataProvider3));
list.setId("dataprovider-with-people");
setProviderWith3Items.setId("dataprovider-with-people-3-items");
setProviderWith2Items.setId("dataprovider-with-people-2-items");
setEmptyProvider.setId("dataprovider-with-people-0-items");
add(list, setProviderWith3Items, setProviderWith2Items, setEmptyProvider);
}
use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.
the class VirtualListPage method createListWithComponentRenderer.
private void createListWithComponentRenderer() {
VirtualList<String> list = new VirtualList<>();
list.setHeight("100px");
List<String> items = IntStream.range(1, 101).mapToObj(i -> "Item " + i).collect(Collectors.toList());
list.setRenderer(new ComponentRenderer<>(item -> {
Div text = new Div(new Text(item));
text.addClassName("component-rendered");
text.setHeight("18px");
return text;
}));
list.setItems(items);
list.setId("component-renderer");
add(list);
}
use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.
the class VirtualListPage method createDetachableList.
private void createDetachableList() {
Div container1 = new Div(new Text("Container 1"));
container1.setId("detachable-list-container-1");
Div container2 = new Div(new Text("Container 2"));
container2.setId("detachable-list-container-2");
VirtualList<Person> list = new VirtualList<>();
list.setId("detachable-list");
list.setItems(createPeople(20));
list.setRenderer(Person::getName);
container1.add(list);
add(container1);
NativeButton detach = new NativeButton("Detach list", e -> list.getParent().ifPresent(parent -> ((HasComponents) parent).remove(list)));
detach.setId("detachable-list-detach");
NativeButton attach1 = new NativeButton("Attach list to container 1", e -> container1.add(list));
attach1.setId("detachable-list-attach-1");
NativeButton attach2 = new NativeButton("Attach list to container 2", e -> container2.add(list));
attach2.setId("detachable-list-attach-2");
NativeButton invisible = new NativeButton("Set list invisble", e -> list.setVisible(false));
invisible.setId("detachable-list-invisible");
NativeButton visible = new NativeButton("Set list visible", e -> list.setVisible(true));
visible.setId("detachable-list-visible");
add(container1, container2, detach, attach1, attach2, invisible, visible);
}
use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.
the class VirtualListPage method createListInsideFlexContainer.
private void createListInsideFlexContainer() {
VirtualList<String> list = new VirtualList<>();
list.setId("list-inside-flex-container");
list.setItems("Item 1", "Item 2", "Item 3");
Div flexContainer = new Div(list);
flexContainer.getStyle().set("display", "flex");
NativeButton setFlexDirectionColumn = new NativeButton("Set 'flex-direction: column'", e -> flexContainer.getStyle().set("flex-direction", "column"));
setFlexDirectionColumn.setId("set-flex-direction-column");
add(flexContainer, setFlexDirectionColumn);
}
use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.
the class VirtualListPage method createLazyLoadingDataProvider.
private void createLazyLoadingDataProvider() {
VirtualList<String> list = new VirtualList<>();
list.setHeight("100px");
Div message = new Div();
DataProvider<String, ?> dataProvider = DataProvider.fromCallbacks(query -> {
List<String> result = queryStrings(query);
message.setText("Sent " + result.size() + " items");
return result.stream();
}, this::countStrings);
list.setDataProvider(dataProvider);
list.setId("lazy-loaded");
message.setId("lazy-loaded-message");
add(list, message);
}
Aggregations