Search in sources :

Example 1 with HeaderRow

use of com.vaadin.flow.component.grid.HeaderRow in project flow-viritin by viritin.

the class PagingGrid method preparePaginationBar.

private void preparePaginationBar() {
    paginationBar = new PaginationBar(null);
    HeaderRow headerRow = prependHeaderRow();
    headerRow.join(getColumns().toArray(new Column[0])).setComponent(paginationBar);
}
Also used : HeaderRow(com.vaadin.flow.component.grid.HeaderRow)

Example 2 with HeaderRow

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

the class CrudGrid method setupFiltering.

private void setupFiltering() {
    final HeaderRow filterRow = this.appendHeaderRow();
    getColumns().forEach(column -> {
        final TextField field = new TextField();
        field.getElement().setAttribute("crud-role", "Search");
        field.getElement().setAttribute("aria-label", "Filter by " + SharedUtil.propertyIdToHumanFriendly(column.getKey()));
        field.addValueChangeListener(event -> {
            filter.getConstraints().remove(column.getKey());
            if (!field.isEmpty()) {
                filter.getConstraints().put(column.getKey(), event.getValue());
            }
            super.getDataProvider().refreshAll();
        });
        field.setValueChangeMode(ValueChangeMode.EAGER);
        filterRow.getCell(column).setComponent(field);
        field.setSizeFull();
        field.setPlaceholder("Filter");
    });
}
Also used : HeaderRow(com.vaadin.flow.component.grid.HeaderRow) TextField(com.vaadin.flow.component.textfield.TextField)

Example 3 with HeaderRow

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

the class GridViewBasicFeaturesPage method createBasicFeatures.

private void createBasicFeatures() {
    final int baseYear = 2015;
    final int numberOfYears = 5;
    DecimalFormat dollarFormat = new DecimalFormat("$#,##0.00");
    Grid<CompanyBudgetHistory> grid = new Grid<>();
    ListDataProvider<CompanyBudgetHistory> list = CompanyBudgetHistory.getBudgetDataProvider(baseYear, numberOfYears);
    grid.setDataProvider(list);
    grid.setColumnReorderingAllowed(true);
    Column<CompanyBudgetHistory> companyNameColumn = grid.addColumn(CompanyBudgetHistory::getCompany).setHeader("Company");
    companyNameColumn.setWidth("200px");
    grid.setSelectionMode(SelectionMode.SINGLE);
    HeaderRow topHeader = grid.prependHeaderRow();
    IntStream.range(baseYear, baseYear + numberOfYears).forEach(year -> {
        BigDecimal firstHalfSum = list.fetch(new Query<>()).collect(Collectors.toList()).stream().map(budgetHistory -> budgetHistory.getFirstHalfOfYear(year)).reduce(BigDecimal.ZERO, BigDecimal::add);
        BigDecimal secondHalfSum = list.fetch(new Query<>()).collect(Collectors.toList()).stream().map(budgetHistory -> budgetHistory.getSecondHalfOfYear(year)).reduce(BigDecimal.ZERO, BigDecimal::add);
        Column<?> firstHalfColumn = grid.addColumn(new NumberRenderer<>(budgetHistory -> budgetHistory.getFirstHalfOfYear(year), dollarFormat)).setHeader("H1").setTextAlign(ColumnTextAlign.END).setFooter(dollarFormat.format(firstHalfSum)).setComparator((p1, p2) -> p1.getFirstHalfOfYear(year).compareTo(p2.getFirstHalfOfYear(year)));
        Column<?> secondHalfColumn = grid.addColumn(new NumberRenderer<>(budgetHistory -> budgetHistory.getSecondHalfOfYear(year), dollarFormat)).setHeader("H2").setTextAlign(ColumnTextAlign.END).setFooter(dollarFormat.format(secondHalfSum)).setComparator((p1, p2) -> p1.getSecondHalfOfYear(year).compareTo(p2.getSecondHalfOfYear(year)));
        topHeader.join(firstHalfColumn, secondHalfColumn).setText(year + "");
    });
    HeaderRow filteringHeader = grid.appendHeaderRow();
    TextField filteringField = new TextField();
    filteringField.addValueChangeListener(event -> {
        list.setFilter(CompanyBudgetHistory::getCompany, company -> {
            if (company == null) {
                return false;
            }
            String companyLower = company.toLowerCase(Locale.ENGLISH);
            String filterLower = event.getValue().toLowerCase(Locale.ENGLISH);
            return companyLower.contains(filterLower);
        });
    });
    filteringField.setPlaceholder("Filter");
    filteringField.setWidth("100%");
    filteringHeader.getCell(companyNameColumn).setComponent(filteringField);
    grid.setId("grid-basic-feature");
    addCard("Basic Features", "Grid Basic Features Demo", grid);
}
Also used : IntStream(java.util.stream.IntStream) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Grid(com.vaadin.flow.component.grid.Grid) Query(com.vaadin.flow.data.provider.Query) Collection(java.util.Collection) DecimalFormat(java.text.DecimalFormat) HashMap(java.util.HashMap) SelectionMode(com.vaadin.flow.component.grid.Grid.SelectionMode) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) NumberRenderer(com.vaadin.flow.data.renderer.NumberRenderer) BigDecimal(java.math.BigDecimal) Column(com.vaadin.flow.component.grid.Grid.Column) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Locale(java.util.Locale) Map(java.util.Map) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) TextField(com.vaadin.flow.component.textfield.TextField) DecimalFormat(java.text.DecimalFormat) Grid(com.vaadin.flow.component.grid.Grid) BigDecimal(java.math.BigDecimal) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) TextField(com.vaadin.flow.component.textfield.TextField)

Example 4 with HeaderRow

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

the class GridViewFilteringPage method createGridWithFilters.

private void createGridWithFilters() {
    Grid<Person> grid = new Grid<>();
    ListDataProvider<Person> dataProvider = new ListDataProvider<>(createItems());
    grid.setDataProvider(dataProvider);
    List<ValueProvider<Person, String>> valueProviders = new ArrayList<>();
    valueProviders.add(Person::getFirstName);
    valueProviders.add(person -> String.valueOf(person.getAge()));
    valueProviders.add(person -> person.getAddress().getStreet());
    valueProviders.add(person -> String.valueOf(person.getAddress().getPostalCode()));
    Iterator<ValueProvider<Person, String>> iterator = valueProviders.iterator();
    grid.addColumn(iterator.next()).setHeader("Name");
    grid.addColumn(iterator.next()).setHeader("Age");
    grid.addColumn(iterator.next()).setHeader("Street");
    grid.addColumn(iterator.next()).setHeader("Postal Code");
    HeaderRow filterRow = grid.appendHeaderRow();
    Iterator<ValueProvider<Person, String>> iterator2 = valueProviders.iterator();
    grid.getColumns().forEach(column -> {
        TextField field = new TextField();
        ValueProvider<Person, String> valueProvider = iterator2.next();
        field.addValueChangeListener(event -> dataProvider.addFilter(person -> StringUtils.containsIgnoreCase(valueProvider.apply(person), field.getValue())));
        field.setValueChangeMode(ValueChangeMode.EAGER);
        filterRow.getCell(column).setComponent(field);
        field.setSizeFull();
        field.setPlaceholder("Filter");
    });
    grid.setId("grid-with-filters");
    addCard("Filtering", "Using text fields for filtering items", grid);
}
Also used : ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) List(java.util.List) Person(com.vaadin.flow.data.bean.Person) Grid(com.vaadin.flow.component.grid.Grid) Iterator(java.util.Iterator) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) ValueProvider(com.vaadin.flow.function.ValueProvider) StringUtils(org.apache.commons.lang3.StringUtils) TextField(com.vaadin.flow.component.textfield.TextField) ValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode) ArrayList(java.util.ArrayList) Route(com.vaadin.flow.router.Route) ListDataProvider(com.vaadin.flow.data.provider.ListDataProvider) Grid(com.vaadin.flow.component.grid.Grid) ArrayList(java.util.ArrayList) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) TextField(com.vaadin.flow.component.textfield.TextField) ValueProvider(com.vaadin.flow.function.ValueProvider) Person(com.vaadin.flow.data.bean.Person)

Example 5 with HeaderRow

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

the class GridViewHeaderAndFooterRowsPage method createGridWithHeaderAndFooterRows.

private void createGridWithHeaderAndFooterRows() {
    Grid<Person> grid = new Grid<>();
    grid.setItems(createItems());
    Column<Person> nameColumn = grid.addColumn(Person::getFirstName).setHeader("Name").setComparator((p1, p2) -> p1.getFirstName().compareToIgnoreCase(p2.getFirstName()));
    Column<Person> ageColumn = grid.addColumn(Person::getAge, "age").setHeader("Age");
    Column<Person> streetColumn = grid.addColumn(person -> person.getAddress().getStreet()).setHeader("Street");
    Column<Person> postalCodeColumn = grid.addColumn(person -> person.getAddress().getPostalCode()).setHeader("Postal Code");
    HeaderRow topRow = grid.prependHeaderRow();
    HeaderCell informationCell = topRow.join(nameColumn, ageColumn);
    informationCell.setText("Basic Information");
    HeaderCell addressCell = topRow.join(streetColumn, postalCodeColumn);
    addressCell.setText("Address Information");
    grid.appendFooterRow().getCell(nameColumn).setText("Total: " + getItems().size() + " people");
    grid.setId("grid-with-header-and-footer-rows");
    addCard("Header and footer rows", "Adding header and footer rows", 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) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Span(com.vaadin.flow.component.html.Span) HeaderCell(com.vaadin.flow.component.grid.HeaderRow.HeaderCell) Route(com.vaadin.flow.router.Route) HeaderRow(com.vaadin.flow.component.grid.HeaderRow) Grid(com.vaadin.flow.component.grid.Grid) HeaderCell(com.vaadin.flow.component.grid.HeaderRow.HeaderCell) Person(com.vaadin.flow.data.bean.Person)

Aggregations

HeaderRow (com.vaadin.flow.component.grid.HeaderRow)9 Grid (com.vaadin.flow.component.grid.Grid)5 TextField (com.vaadin.flow.component.textfield.TextField)4 Route (com.vaadin.flow.router.Route)4 Column (com.vaadin.flow.component.grid.Grid.Column)3 Person (com.vaadin.flow.data.bean.Person)3 HeaderCell (com.vaadin.flow.component.grid.HeaderRow.HeaderCell)2 Span (com.vaadin.flow.component.html.Span)2 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)2 ArrayList (java.util.ArrayList)2 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 SelectionMode (com.vaadin.flow.component.grid.Grid.SelectionMode)1 Query (com.vaadin.flow.data.provider.Query)1 NumberRenderer (com.vaadin.flow.data.renderer.NumberRenderer)1 ValueChangeMode (com.vaadin.flow.data.value.ValueChangeMode)1 ValueProvider (com.vaadin.flow.function.ValueProvider)1 BigDecimal (java.math.BigDecimal)1 DecimalFormat (java.text.DecimalFormat)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1