Search in sources :

Example 1 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListTestPage method createTemplateFromValueProviderWithPeople.

private void createTemplateFromValueProviderWithPeople() {
    IronList<Person> list = new IronList<>();
    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) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 2 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListTestPage method createListWithStrings.

private void createListWithStrings() {
    IronList<String> list = new IronList<>();
    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) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 3 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListTestPage method createListWithComponentRenderer.

private void createListWithComponentRenderer() {
    IronList<String> list = new IronList<>();
    list.setHeight("100px");
    List<String> items = IntStream.range(1, 101).mapToObj(i -> "Item " + i).collect(Collectors.toList());
    list.setRenderer(new ComponentRenderer<>(item -> {
        Label label = new Label(item);
        label.addClassName("component-rendered");
        return label;
    }));
    list.setItems(items);
    list.setId("component-renderer");
    add(list);
}
Also used : IntStream(java.util.stream.IntStream) 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) Label(com.vaadin.flow.component.html.Label) 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) IronList(com.vaadin.flow.component.ironlist.IronList) HasComponents(com.vaadin.flow.component.HasComponents) Renderer(com.vaadin.flow.data.renderer.Renderer) Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 4 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListTestPage method createListInsideFlexContainer.

private void createListInsideFlexContainer() {
    IronList<String> list = new IronList<>();
    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) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 5 with IronList

use of com.vaadin.flow.component.ironlist.IronList in project flow-components by vaadin.

the class IronListView method createStringListWithDataProvider.

private void createStringListWithDataProvider() {
    IronList<String> list = new IronList<>();
    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");
    addCard("List of strings with DataProvider", new Label("List of books lazy loaded from the database"), list);
}
Also used : Label(com.vaadin.flow.component.html.Label) IronList(com.vaadin.flow.component.ironlist.IronList)

Aggregations

IronList (com.vaadin.flow.component.ironlist.IronList)15 NativeButton (com.vaadin.flow.component.html.NativeButton)12 Label (com.vaadin.flow.component.html.Label)11 Div (com.vaadin.flow.component.html.Div)8 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