Search in sources :

Example 56 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridViewStylingPage method createStyling.

private void createStyling() {
    String instructions = "<p>In order to inject styles into Grid cells, " + "create a style-module like in the snippet below, " + "put it into an html-file in your resources folder, " + "and import it with <code>@HtmlImport</code>. " + "After this you can apply the CSS classes " + "(<code>subscriber</code> and <code>minor</code> in this case) " + "into grid rows and cells as shown in the next example.</p>";
    addCard("Styling", "Styling Grid Cells", new Html(instructions));
    Grid<Person> grid = new Grid<>();
    grid.setItems(getItems());
    grid.setSelectionMode(SelectionMode.NONE);
    grid.addColumn(Person::getFirstName).setHeader("Name");
    Column<Person> ageColumn = grid.addColumn(Person::getAge).setHeader("Age");
    grid.addColumn(person -> person.isSubscriber() ? "Yes" : "").setHeader("Subscriber");
    grid.setClassNameGenerator(person -> person.isSubscriber() ? "subscriber" : "");
    ageColumn.setClassNameGenerator(person -> person.getAge() < 18 ? "minor" : "");
    grid.setId("class-name-generator");
    addCard("Styling", "Generating CSS Class Names for Cells", grid);
}
Also used : Column(com.vaadin.flow.component.grid.Grid.Column) Person(com.vaadin.flow.data.bean.Person) Grid(com.vaadin.flow.component.grid.Grid) Html(com.vaadin.flow.component.Html) SelectionMode(com.vaadin.flow.component.grid.Grid.SelectionMode) Route(com.vaadin.flow.router.Route) Grid(com.vaadin.flow.component.grid.Grid) Html(com.vaadin.flow.component.Html) Person(com.vaadin.flow.data.bean.Person)

Example 57 with Grid

use of com.vaadin.flow.component.grid.Grid 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)

Example 58 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridWithTemplatePage method createStandaloneGridWithTemplatesInTheCells.

private void createStandaloneGridWithTemplatesInTheCells() {
    Grid<String> grid = new Grid<>();
    setCommonGridFeatures(grid, "standalone-template-in-cells");
    grid.addColumn(value -> value);
    grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
    add(new H3("Grid with templates in the cells"), grid);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) Grid(com.vaadin.flow.component.grid.Grid) H3(com.vaadin.flow.component.html.H3)

Example 59 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridWithTemplatePage method createStandaloneGridWithTemplatesInTheDetails.

private void createStandaloneGridWithTemplatesInTheDetails() {
    Grid<String> grid = new Grid<>();
    setCommonGridFeatures(grid, "standalone-template-in-details");
    grid.addColumn(value -> value);
    grid.setItemDetailsRenderer(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get())));
    add(new H3("Grid with templates in the details"), grid);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) Grid(com.vaadin.flow.component.grid.Grid) H3(com.vaadin.flow.component.html.H3)

Example 60 with Grid

use of com.vaadin.flow.component.grid.Grid in project flow-components by vaadin.

the class GridWithTemplatePage method createStandaloneGridWithColumnProperties.

private void createStandaloneGridWithColumnProperties() {
    Grid<String> grid = new Grid<>();
    setCommonGridFeatures(grid, "standalone-columns-with-properties");
    grid.addColumn(value -> value).setFlexGrow(2);
    grid.addColumn(TemplateRenderer.of("[[index]]")).setFlexGrow(0).setWidth("20px");
    grid.addColumn(new ComponentRenderer<>(value -> getTestTemplate(value, grid.getId().get()))).setFrozen(true).setResizable(true);
    add(new H3("Grid with column properties"), grid);
}
Also used : ComponentRenderer(com.vaadin.flow.data.renderer.ComponentRenderer) Grid(com.vaadin.flow.component.grid.Grid) TemplateRenderer(com.vaadin.flow.data.renderer.TemplateRenderer) Element(com.vaadin.flow.dom.Element) Div(com.vaadin.flow.component.html.Div) H3(com.vaadin.flow.component.html.H3) H2(com.vaadin.flow.component.html.H2) Route(com.vaadin.flow.router.Route) Grid(com.vaadin.flow.component.grid.Grid) H3(com.vaadin.flow.component.html.H3)

Aggregations

Grid (com.vaadin.flow.component.grid.Grid)73 Route (com.vaadin.flow.router.Route)41 Div (com.vaadin.flow.component.html.Div)38 List (java.util.List)26 NativeButton (com.vaadin.flow.component.html.NativeButton)22 Person (com.vaadin.flow.data.bean.Person)22 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)21 H2 (com.vaadin.flow.component.html.H2)17 Collections (java.util.Collections)16 Button (com.vaadin.flow.component.button.Button)15 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)14 ArrayList (java.util.ArrayList)13 Collectors (java.util.stream.Collectors)13 Component (com.vaadin.flow.component.Component)12 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)12 Column (com.vaadin.flow.component.grid.Grid.Column)12 Label (com.vaadin.flow.component.html.Label)12 Span (com.vaadin.flow.component.html.Span)11 TextField (com.vaadin.flow.component.textfield.TextField)10 DenseGrid (io.imunity.furms.ui.components.DenseGrid)10