use of com.vaadin.flow.data.bean.Item in project flow-components by vaadin.
the class GridViewUsingRenderersPage method createBasicRenderers.
private void createBasicRenderers() {
Grid<Item> grid = new Grid<>();
grid.setItems(getShoppingCart());
grid.addColumn(Item::getName).setHeader("Name");
// NumberRenderer to render numbers in general
grid.addColumn(new NumberRenderer<>(Item::getPrice, "$ %(,.2f", Locale.US, "$ 0.00")).setHeader("Price");
// LocalDateTimeRenderer for date and time
grid.addColumn(new LocalDateTimeRenderer<>(Item::getPurchaseDate, DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM))).setHeader("Purchase date and time").setFlexGrow(2);
// LocalDateRenderer for dates
grid.addColumn(new LocalDateRenderer<>(Item::getEstimatedDeliveryDate, DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM))).setHeader("Estimated delivery date");
// Icons
grid.addColumn(new IconRenderer<>(item -> item.getPrice() > 50 ? new Span("$$$") : new Span("$"), item -> ""));
// NativeButtonRenderer for an easy clickable button,
// without creating a component
grid.addColumn(new NativeButtonRenderer<>("Remove", item -> {
ListDataProvider<Item> dataProvider = (ListDataProvider<Item>) grid.getDataProvider();
dataProvider.getItems().remove(item);
dataProvider.refreshAll();
})).setWidth("100px").setFlexGrow(0);
grid.setId("grid-basic-renderers");
addCard("Using renderers", "Using basic renderers", grid);
}
Aggregations