Search in sources :

Example 11 with VirtualList

use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.

the class VirtualListPage method createDataProviderWithStrings.

private void createDataProviderWithStrings() {
    VirtualList<String> list = new VirtualList<>();
    list.setHeight("100px");
    DataProvider<String, ?> dataProvider1 = DataProvider.ofItems("Item 1", "Item 2", "Item 3");
    DataProvider<String, ?> dataProvider2 = DataProvider.ofItems("Another item 1", "Another item 2");
    DataProvider<String, ?> dataProvider3 = DataProvider.ofItems();
    list.setDataProvider(dataProvider1);
    NativeButton setProviderWith3Items = new NativeButton("Change dataprovider 1", evt -> list.setDataProvider(dataProvider1));
    NativeButton setProviderWith2Items = new NativeButton("Change dataprovider 2", evt -> list.setDataProvider(dataProvider2));
    NativeButton setEmptyProvider = new NativeButton("Change dataprovider 3", evt -> list.setDataProvider(dataProvider3));
    list.setId("dataprovider-with-strings");
    setProviderWith3Items.setId("dataprovider-with-strings-3-items");
    setProviderWith2Items.setId("dataprovider-with-strings-2-items");
    setEmptyProvider.setId("dataprovider-with-strings-0-items");
    add(list, setProviderWith3Items, setProviderWith2Items, setEmptyProvider);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList)

Example 12 with VirtualList

use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.

the class VirtualListPage method createListWithComponentRendererWithBeansAndPlaceholder.

private void createListWithComponentRendererWithBeansAndPlaceholder() {
    VirtualList<Person> list = new VirtualList<>();
    list.setHeight("100px");
    List<Person> people = createPeople(100);
    list.setRenderer(new ComponentRenderer<Div, Person>(person -> {
        Div text = new Div(new Text(person.getName()));
        text.addClassName("component-rendered");
        return text;
    }));
    list.setItems(people);
    list.setId("component-renderer-with-beans");
    Person placeholder = new Person();
    placeholder.setName("the-placeholder");
    list.setPlaceholderItem(placeholder);
    add(list);
}
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) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) Text(com.vaadin.flow.component.Text)

Example 13 with VirtualList

use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.

the class VirtualListPage method createListWithStrings.

private void createListWithStrings() {
    VirtualList<String> list = new VirtualList<>();
    list.setHeight("100px");
    list.setItems("Item 1", "Item 2", "Item 3");
    NativeButton setListWith3Items = new NativeButton("Change list 1", evt -> list.setItems("Item 1", "Item 2", "Item 3"));
    NativeButton setListWith2Items = new NativeButton("Change list 2", evt -> list.setItems("Another item 1", "Another item 2"));
    NativeButton setEmptyList = new NativeButton("Change list 3", evt -> list.setItems());
    list.setId("list-with-strings");
    setListWith3Items.setId("list-with-strings-3-items");
    setListWith2Items.setId("list-with-strings-2-items");
    setEmptyList.setId("list-with-strings-0-items");
    add(list, setListWith3Items, setListWith2Items, setEmptyList);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList)

Example 14 with VirtualList

use of com.vaadin.flow.component.virtuallist.VirtualList in project flow-components by vaadin.

the class VirtualListViewPage method createStringListWithDataProvider.

private void createStringListWithDataProvider() {
    VirtualList<String> list = new VirtualList<>();
    list.setHeight("200px");
    list.getStyle().set("border", "1px solid lightgray");
    DataProvider<String, ?> dataProvider = DataProvider.fromCallbacks(query -> queryStringsFromDatabase(query), query -> countStringsFromDatabase(query));
    list.setDataProvider(dataProvider);
    list.setId("list-of-strings-with-dataprovider");
    add(new Div(new Text("List of books lazy loaded from the database")), list);
}
Also used : Div(com.vaadin.flow.component.html.Div) VirtualList(com.vaadin.flow.component.virtuallist.VirtualList) Text(com.vaadin.flow.component.Text)

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