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);
}
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);
}
Aggregations