2929import java .util .Map ;
3030import java .util .Objects ;
3131import java .util .Set ;
32+ import java .util .function .BiConsumer ;
3233import java .util .function .Function ;
34+ import java .util .function .Predicate ;
3335import java .util .stream .Collectors ;
3436
3537import com .vaadin .flow .component .AttachEvent ;
@@ -100,6 +102,16 @@ public class GridFilter<T>
100102 new FilterContainerComponent <>(this ::onFilterUpdate , false );
101103 protected final AddFilterComponentsButtons addFilterComponentButtons = new AddFilterComponentsButtons ();
102104
105+ /**
106+ * A function that defines how the filter is applied to the {@link Grid}.
107+ * <p>
108+ * Please note that the default will only work for {@link com.vaadin.flow.data.provider.ListDataProvider} or
109+ * derivates
110+ * </p>
111+ */
112+ protected BiConsumer <Grid <T >, List <FilterComponent <T , ?>>> applyFilter = (gr , components )
113+ -> gr .getListDataView ().setFilter (item -> components .stream ().allMatch (c -> c .test (item )));
114+
103115 public GridFilter (final Grid <T > grid )
104116 {
105117 this .grid = grid ;
@@ -112,6 +124,26 @@ public GridFilter(final Grid<T> grid)
112124 this .addClassNames (GridFilterStyles .GRID_FILTER );
113125 }
114126
127+ /**
128+ * @see #applyFilter
129+ */
130+ public GridFilter <T > withApplyPredicateFilter (final BiConsumer <Grid <T >, Predicate <T >> applyPredicateFilter )
131+ {
132+ Objects .requireNonNull (applyPredicateFilter );
133+ this .applyFilter = (gr , components )
134+ -> applyPredicateFilter .accept (gr , item -> components .stream ().allMatch (c -> c .test (item )));
135+ return this ;
136+ }
137+
138+ /**
139+ * @see #applyFilter
140+ */
141+ public GridFilter <T > withApplyFilter (final BiConsumer <Grid <T >, List <FilterComponent <T , ?>>> applyFilter )
142+ {
143+ this .applyFilter = Objects .requireNonNull (applyFilter );
144+ return this ;
145+ }
146+
115147 @ SuppressWarnings ("java:S1452" )
116148 public FilterComponent <T , ?> addFilterComponent (final FilterComponentSupplier supplier )
117149 {
@@ -130,12 +162,16 @@ public GridFilter(final Grid<T> grid)
130162
131163 protected void onFilterUpdate ()
132164 {
133- this .grid .getListDataView ().setFilter (item ->
134- this .filterContainerComponent .getFilterComponents ().stream ().allMatch (c -> c .test (item )));
165+ this .applyFilterToGrid ();
135166
136167 this .fireEvent (new FilterChangedEvent <>(this , false ));
137168 }
138169
170+ protected void applyFilterToGrid ()
171+ {
172+ this .applyFilter .accept (this .grid , this .filterContainerComponent .getFilterComponents ());
173+ }
174+
139175 @ SuppressWarnings ({"unchecked" , "rawtypes" })
140176 public Registration addFilterChangedListener (final ComponentEventListener <FilterChangedEvent <T >> listener )
141177 {
0 commit comments