Search in sources :

Example 1 with NativeButtonRenderer

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

the class GridViewBasicPage method createDisabledGrid.

private void createDisabledGrid() {
    Grid<Person> grid = new Grid<>();
    List<Person> people = createItems(500);
    grid.setItems(people);
    grid.addColumn(Person::getFirstName).setHeader("Name");
    grid.addColumn(Person::getAge).setHeader("Age");
    grid.addColumn(new NativeButtonRenderer<>("Button")).setHeader("Action");
    grid.setSelectionMode(SelectionMode.SINGLE);
    // The selection and action button won't work, but the scrolling will
    grid.setEnabled(false);
    NativeButton toggleEnable = new NativeButton("Toggle enable", evt -> grid.setEnabled(!grid.isEnabled()));
    toggleEnable.setId("disabled-grid-toggle-enable");
    Div div = new Div(toggleEnable);
    grid.setId("disabled-grid");
    addCard("Disabled grid", grid, div);
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) NativeButton(com.vaadin.flow.component.html.NativeButton) Grid(com.vaadin.flow.component.grid.Grid) Person(com.vaadin.flow.data.bean.Person)

Example 2 with NativeButtonRenderer

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

the class ComboBoxPage method createWithButtonRenderer.

private void createWithButtonRenderer() {
    ComboBox<String> comboBox = new ComboBox<>();
    Label message = new Label("Nothing clicked yet...");
    message.setId("button-renderer-message");
    comboBox.setRenderer(new NativeButtonRenderer<>(item -> item, item -> message.setText("Button clicked: " + item)));
    comboBox.setItems("foo", "bar");
    comboBox.setId("button-renderer");
    add(comboBox, message);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Arrays(java.util.Arrays) Query(com.vaadin.flow.data.provider.Query) Component(com.vaadin.flow.component.Component) Collection(java.util.Collection) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) SerializableConsumer(com.vaadin.flow.function.SerializableConsumer) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Route(com.vaadin.flow.router.Route) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NativeButtonRenderer(com.vaadin.flow.data.renderer.NativeButtonRenderer) DataProvider(com.vaadin.flow.data.provider.DataProvider) Optional(java.util.Optional) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate) SimpleBean(com.vaadin.flow.component.combobox.bean.SimpleBean) Span(com.vaadin.flow.component.html.Span) ComboBox(com.vaadin.flow.component.combobox.ComboBox) Label(com.vaadin.flow.component.html.Label)

Example 3 with NativeButtonRenderer

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

NativeButtonRenderer (com.vaadin.flow.data.renderer.NativeButtonRenderer)3 Grid (com.vaadin.flow.component.grid.Grid)2 Div (com.vaadin.flow.component.html.Div)2 NativeButton (com.vaadin.flow.component.html.NativeButton)2 Span (com.vaadin.flow.component.html.Span)2 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)2 Route (com.vaadin.flow.router.Route)2 Component (com.vaadin.flow.component.Component)1 ComboBox (com.vaadin.flow.component.combobox.ComboBox)1 SimpleBean (com.vaadin.flow.component.combobox.bean.SimpleBean)1 Label (com.vaadin.flow.component.html.Label)1 Item (com.vaadin.flow.data.bean.Item)1 ItemGenerator (com.vaadin.flow.data.bean.ItemGenerator)1 Person (com.vaadin.flow.data.bean.Person)1 DataProvider (com.vaadin.flow.data.provider.DataProvider)1 Query (com.vaadin.flow.data.provider.Query)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 NumberRenderer (com.vaadin.flow.data.renderer.NumberRenderer)1