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