You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,43 +13,163 @@ Grid supports connecting to various types of data sources through data providers
13
13
14
14
== Binding Items via `setItems`
15
15
16
-
The `setItems` method in Grid is a convenience API that allows you to bind and display data from in-memory collections and simple lazy-loaded data sources without explicitly creating a data provider. This method offers several overloads for different use cases, and returns either a `GridListDataView` or `GridLazyDataView` instance, which you can use to add filtering, sorting, and other configurations to the resulting list of displayed items.
16
+
The simplest way to bind data to a Grid is by using the `setItems` convenience method. It lets you bind an in-memory collection or provide callbacks for lazy loading from a backend service without explicitly creating a data provider.
17
+
18
+
*Example:* Binding items from an in-memory collection.
19
+
20
+
[.example]
21
+
--
17
22
18
-
.Example: Binding a collection of items
19
23
[source,java]
24
+
.PeopleView.java
20
25
----
26
+
Grid<Person> grid = new Grid<>(Person.class);
27
+
28
+
// Binding
21
29
GridListDataView dataView = grid.setItems(
22
-
new Person("George Washington", 1732),
23
-
new Person("John Adams", 1735),
24
-
new Person("Thomas Jefferson", 1743),
25
-
new Person("James Madison", 1751)
30
+
new Person("Michael Chen"),
31
+
new Person("Sarah Johnson"),
32
+
new Person("David Rodriguez"),
33
+
new Person("Emma Wilson")
26
34
);
35
+
36
+
// Filtering
37
+
TextField searchInput = new TextField("Search", event -> {
38
+
if (!event.getValue().isEmpty()) {
39
+
// Set a filter to show only persons whose name contains the search term
For more documentation and examples, see the <<{articles}/flow/binding-data/data-provider#,Binding Items To Components>> article.
159
+
[source,java]
160
+
.Person.java
161
+
----
162
+
public record Person(String name) {
163
+
}
164
+
----
165
+
166
+
--
167
+
168
+
More documentation and examples for using the `setItems` method are available in the <<{articles}/flow/binding-data/data-provider#,Binding Items To Components>> article.
49
169
50
170
== Custom Data Providers
51
171
52
-
Alternatively, you can provide a custom data provider via the `setDataProvider(DataProvider<T, ?>)` method, passing your own class that implements the [interfacename]`DataProvider` interface.
172
+
Alternatively, you can supply a custom data provider via the `setDataProvider(DataProvider<T, ?>)` method, passing your own class that implements the [interfacename]`DataProvider` interface:
53
173
54
174
[source,java]
55
175
----
@@ -83,7 +203,7 @@ public class CustomDataProvider extends AbstractDataProvider<T, F> {
83
203
84
204
The `Query<T, F>` parameter in the `size` and `fetch` methods provides information about the requested data such as pagination details (offset and limit), sorting orders, and an optional filter object of type `F`.
85
205
86
-
Below is a practical example of a custom data provider that extends the `AbstractDataProvider` class and uses a fake database to return `Person` records. It supports filtering with a `PersonFilter` object and sorting using a list of `QuerySortOrder` objects from the Grid. The example also includes a simple view that uses the data provider with a Grid and filter components:
206
+
Below is a practical example of a custom data provider that extends the `AbstractDataProvider` class and uses a fake database to return `Person` records. It supports filtering with a `PersonFilter` object and sorting using `QuerySortOrder` objects from the Grid. The example also includes a simple view that uses the data provider with a Grid and filter components:
87
207
88
208
[.example]
89
209
--
@@ -99,7 +219,6 @@ public class PersonDataProvider extends AbstractDataProvider<Person, PersonFilte
99
219
new Person("Sarah Johnson", "Engineering"),
100
220
new Person("David Rodriguez", "Marketing"),
101
221
new Person("Emma Wilson", "HR"),
102
-
new Person("James Patterson", "Marketing"));
103
222
104
223
@Override
105
224
public boolean isInMemory() {
@@ -203,10 +322,13 @@ public class PeopleView extends VerticalLayout {
203
322
public PeopleView() {
204
323
Grid<Person> grid = new Grid<>(Person.class);
205
324
206
-
// Enable sorting for the columns
325
+
// Enable sorting for the columns. This will send sorting information
326
+
// to the data provider as List<QuerySortOrder> when the user sorts
327
+
// the columns in the Grid.
207
328
grid.setSortableColumns("name", "department");
208
329
209
-
// Create a data provider instance with a configurable filter.
330
+
// Create a data provider instance with a configurable filter,
331
+
// as it doesn't provide filtering capabilities by default.
210
332
// The returned wrapper allows setting the filter dynamically
211
333
// using the ConfigurableFilterDataProvider#setFilter() method
212
334
dataProvider = new PersonDataProvider().withConfigurableFilter();
Copy file name to clipboardExpand all lines: articles/components/grid/index.adoc
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -325,6 +325,8 @@ endif::[]
325
325
326
326
--
327
327
328
+
See the <<../grid/data-binding#custom-data-providers,Data Binding>> page for more information about creating data providers for Grid.
329
+
328
330
=== Lazy Column Rendering
329
331
330
332
Grids containing a large number of columns can sometimes exhibit performance issues. If many of the columns are typically outside the visible viewport, rendering performance can be optimized by using "lazy column rendering" mode.
0 commit comments