Search in sources :

Example 6 with VirtualList

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);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList)

Example 7 with VirtualList

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);
}
Also used : IntStream(java.util.stream.IntStream) Text(com.vaadin.flow.component.Text) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Div(com.vaadin.flow.component.html.Div) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) Text(com.vaadin.flow.component.Text)

Example 8 with VirtualList

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) IntStream(java.util.stream.IntStream) Text(com.vaadin.flow.component.Text) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) ValueProvider(com.vaadin.flow.function.ValueProvider) LocalDateTime(java.time.LocalDateTime) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DataProvider(com.vaadin.flow.data.provider.DataProvider) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) LocalDate(java.time.LocalDate) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) NativeButton(com.vaadin.flow.component.html.NativeButton) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) Text(com.vaadin.flow.component.Text) HasComponents(com.vaadin.flow.component.HasComponents)

Example 9 with VirtualList

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList)

Example 10 with VirtualList

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList)

Aggregations

VirtualList (com.vaadin.flow.component.virtuallist.VirtualList)14 NativeButton (com.vaadin.flow.component.html.NativeButton)12 Div (com.vaadin.flow.component.html.Div)11 Text (com.vaadin.flow.component.Text)9 DataProvider (com.vaadin.flow.data.provider.DataProvider)7 Query (com.vaadin.flow.data.provider.Query)7 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)7 TemplateRenderer (com.vaadin.flow.data.renderer.TemplateRenderer)7 ValueProvider (com.vaadin.flow.function.ValueProvider)7 Route (com.vaadin.flow.router.Route)7 ArrayList (java.util.ArrayList)7 Arrays (java.util.Arrays)7 List (java.util.List)7 HasComponents (com.vaadin.flow.component.HasComponents)5 LocalDateRenderer (com.vaadin.flow.data.renderer.LocalDateRenderer)5 LocalDateTimeRenderer (com.vaadin.flow.data.renderer.LocalDateTimeRenderer)5 NativeButtonRenderer (com.vaadin.flow.data.renderer.NativeButtonRenderer)5 NumberRenderer (com.vaadin.flow.data.renderer.NumberRenderer)5 Renderer (com.vaadin.flow.data.renderer.Renderer)5 LocalDate (java.time.LocalDate)5