Search in sources :

Example 6 with Renderer

use of com.vaadin.flow.data.renderer.Renderer in project flow-components by vaadin.

the class IronListTestPage method createTemplateFromRendererWithPeople.

private void createTemplateFromRendererWithPeople() {
    IronList<Person> list = new IronList<>();
    list.setHeight("100px");
    List<Person> people = createPeople(3);
    DataProvider<Person, ?> dataProvider = DataProvider.ofCollection(people);
    list.setDataProvider(dataProvider);
    list.setRenderer(TemplateRenderer.<Person>of("[[item.name]] - [[item.age]] - [[item.user]]").withProperty("name", Person::getName).withProperty("age", Person::getAge).withProperty("user", person -> person.getName().toLowerCase().replace(" ", "_")));
    NativeButton update = new NativeButton("Update item 1", evt -> {
        Person item = people.get(0);
        item.setName(item.getName() + " Updated");
        list.getDataProvider().refreshItem(item);
    });
    list.setId("template-renderer-with-people");
    update.setId("template-renderer-with-people-update-item");
    add(list, update);
}
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) NativeButton(com.vaadin.flow.component.html.NativeButton) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 7 with Renderer

use of com.vaadin.flow.data.renderer.Renderer 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)

Aggregations

DataProvider (com.vaadin.flow.data.provider.DataProvider)7 Query (com.vaadin.flow.data.provider.Query)7 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)7 Renderer (com.vaadin.flow.data.renderer.Renderer)7 TemplateRenderer (com.vaadin.flow.data.renderer.TemplateRenderer)7 ValueProvider (com.vaadin.flow.function.ValueProvider)7 ArrayList (java.util.ArrayList)7 Arrays (java.util.Arrays)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 IntStream (java.util.stream.IntStream)7 HasComponents (com.vaadin.flow.component.HasComponents)6 Div (com.vaadin.flow.component.html.Div)6 NativeButton (com.vaadin.flow.component.html.NativeButton)6 LocalDateRenderer (com.vaadin.flow.data.renderer.LocalDateRenderer)6 LocalDateTimeRenderer (com.vaadin.flow.data.renderer.LocalDateTimeRenderer)6 NativeButtonRenderer (com.vaadin.flow.data.renderer.NativeButtonRenderer)6 NumberRenderer (com.vaadin.flow.data.renderer.NumberRenderer)6 Route (com.vaadin.flow.router.Route)6 LocalDate (java.time.LocalDate)6