Filtering Grid | Vaadin

Grid that makes it easy to filter its data

The FilterGrid component allows attaching filters to the grid and it's columns which can be used to filter its data. Filtering can be performed in case of both in-memory and backend data.

Filtering In-memory data

The FilterColumn#setFilter() method accepts a Component that will show up in the Grid's header row for the column, and a SerializableBiPredicate<COLUMN_VALUE, FILTER_VALUE> which instructs the Grid to display a given row or not. The BiPredicate is a function that gets two parameters, the value and the filter's value, and returns true (keep the row) or false (filter out the row).

colDateOfBirth.setFilter(new DateField(), (v, fv) -> fv == null || v.isEqual(fv));

In addition, in case the value is of different type than the filter's value, it is possible to provide a value provider which converts the value to a filterable value.

colDateOfBirth.setFilter(
        v -> v.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(),
        new DateField(),
        (v, fv) -> fv == null || v.isEqual(fv));

Filtering backend data

Add Filters to the Grid using the Grid#addFilter() method.

Then, given a backend service that returns a stream of objects (e.g. from database or REST service) public Stream<Person> getPersonsFilteredByFirstName(int offset, int limit, String firstNameContains) {/* ... */}, create a filtered data provider which uses this service for fetching and counting data.

grid.setFilteredDataProvider(
        (sortOrder, filters, offset, limit) -> PersonService.getInstance()
                .getPersons(offset, limit, filters.getStringValue("filterFirstName")
                        .orElse(null)),
        filters -> PersonService.getInstance().getSize(
                filters.getValue("firstName", String.class)
                        .orElse(null)));

For more detailed documentation, please visit https://github.com/wbadam/filtering-grid

Install

Link to this version
ExperimentalReleased 15 February 2018Apache License 2.0
Framework Support
Install with
Release notes - Version 0.1.1