Search in sources :

Example 1 with LocalDateRenderer

use of com.vaadin.flow.data.renderer.LocalDateRenderer 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);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) Grid(com.vaadin.flow.component.grid.Grid) FormatStyle(java.time.format.FormatStyle) ItemGenerator(com.vaadin.flow.data.bean.ItemGenerator) IconRenderer(com.vaadin.flow.data.renderer.IconRenderer) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) LocalDateTimeRenderer(com.vaadin.flow.data.renderer.LocalDateTimeRenderer) List(java.util.List) Item(com.vaadin.flow.data.bean.Item) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) Locale(java.util.Locale) DateTimeFormatter(java.time.format.DateTimeFormatter) Span(com.vaadin.flow.component.html.Span) Item(com.vaadin.flow.data.bean.Item) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Grid(com.vaadin.flow.component.grid.Grid) LocalDateRenderer(com.vaadin.flow.data.renderer.LocalDateRenderer) Span(com.vaadin.flow.component.html.Span) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer)

Aggregations

Grid (com.vaadin.flow.component.grid.Grid)1 Span (com.vaadin.flow.component.html.Span)1 Item (com.vaadin.flow.data.bean.Item)1 ItemGenerator (com.vaadin.flow.data.bean.ItemGenerator)1 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)1 IconRenderer (com.vaadin.flow.data.renderer.IconRenderer)1 LocalDateRenderer (com.vaadin.flow.data.renderer.LocalDateRenderer)1 LocalDateTimeRenderer (com.vaadin.flow.data.renderer.LocalDateTimeRenderer)1 NativeButtonRenderer (com.vaadin.flow.data.renderer.NativeButtonRenderer)1 NumberRenderer (com.vaadin.flow.data.renderer.NumberRenderer)1 Route (com.vaadin.flow.router.Route)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 FormatStyle (java.time.format.FormatStyle)1 List (java.util.List)1 Locale (java.util.Locale)1