Docs

Documentation versions (currently viewingVaadin 25)
Documentation translations (currently viewingEnglish)

Binding Data to Grid Flow

Binding and displaying data in Grid

Grid supports connecting to various types of data sources through data providers. A data provider is a class that implements the DataProvider interface and encapsulates the logic for fetching items from a specific data source, with support for pagination, sorting, and filtering. For common use cases, Grid provides convenience methods so that you don’t have to deal with the full data provider setup, and it also supports custom data providers where more flexibility is needed.

Binding Items via setItems

The most straightforward way to bind data to a Grid is to use the setItems convenience method. It allows you to bind an in-memory collection or provide callbacks for lazy loading from a backend service without the need to explicitly create a data provider.

The example below shows how to display, filter and sort a static list of Person records:

Source code
PeopleView.java
Person.java

The next example shows how to display, filter and sort data from a backend service with lazy loading by providing fetch and count callbacks to the setItems method:

Source code
PeopleView.java
PersonService.java
Person.java

More documentation and examples for using the setItems method are available in the Binding Items To Components article.

Custom Data Providers

A more advanced way to bind data to a Grid is to supply a custom data provider implementation via the setDataProvider(DataProvider<T, F>) method.

The example below shows a Grid backed by a custom data provider that imitates fetching data from a database, with support for filtering and sorting:

Source code
PersonDataProvider.java
PersonFilter.java
Person.java
PeopleView.java

More examples of custom data providers are available in the Binding Items To Components article.