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