Search in sources :

Example 11 with TemplateRenderer

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

the class IronListTestPage method createTemplateWithEventHandlers.

private void createTemplateWithEventHandlers() {
    IronList<String> list = new IronList<>();
    list.setHeight("100px");
    Label message = new Label();
    List<String> items = new ArrayList<>(Arrays.asList("Clickable item 1", "Clickable item 2", "Clickable item 3"));
    list.setRenderer(TemplateRenderer.<String>of("<div on-click='remove' id='template-events-item-[[index]]'>[[item.label]]</div>").withProperty("label", ValueProvider.identity()).withEventHandler("remove", item -> {
        items.remove(item);
        list.getDataCommunicator().reset();
        message.setText(item + " removed");
    }));
    list.setItems(items);
    list.setId("template-events");
    message.setId("template-events-message");
    add(list, message);
}
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) ArrayList(java.util.ArrayList) IronList(com.vaadin.flow.component.ironlist.IronList)

Example 12 with TemplateRenderer

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

Aggregations

TemplateRenderer (com.vaadin.flow.data.renderer.TemplateRenderer)12 ArrayList (java.util.ArrayList)12 List (java.util.List)12 Div (com.vaadin.flow.component.html.Div)11 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)11 Route (com.vaadin.flow.router.Route)11 NativeButton (com.vaadin.flow.component.html.NativeButton)10 DataProvider (com.vaadin.flow.data.provider.DataProvider)9 Query (com.vaadin.flow.data.provider.Query)9 ValueProvider (com.vaadin.flow.function.ValueProvider)9 Arrays (java.util.Arrays)9 Collectors (java.util.stream.Collectors)8 Label (com.vaadin.flow.component.html.Label)6 Serializable (java.io.Serializable)6 Collections (java.util.Collections)6 IntStream (java.util.stream.IntStream)6 Faker (com.github.javafaker.Faker)5 HasComponents (com.vaadin.flow.component.HasComponents)5 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)5 Renderer (com.vaadin.flow.data.renderer.Renderer)5