Set Filter
The Set Filter takes inspiration from Excel's AutoFilter and allows filtering on sets of data.
Using Set Filter
Set filter is represented by the abstract class AgSetColumnFilter. Create it with the factory method matching the column's type — AgSetColumnFilter.forString(), forNumber(), forBoolean(), forDate(), forUUID() or forEnum(MyEnum.class).
var colDef = ColDef.builder(Trade_.product)
.filter(AgSetColumnFilter.forString())
.build()
Set Filter Parameters
Set Filters are configured though the filter params (SetFilterParams class)
| Property | Type | Default | Description |
|---|---|---|---|
caseSensitive | boolean | false | By default, set filtering is case-insensitive. Set this to true to make text filtering case-sensitive. |
textFormatter | BiFunction<CriteriaBuilder, Expression<String>, Expression<String>> | — | Formats the text before applying the filter compare logic. Useful if you want to substitute accented characters, for example. Works only if the column is string type. Same as in text filter. |
Example of using filter parameters.
var colDef = ColDef.builder(Trade_.product)
.filter(AgSetColumnFilter.forString()
.filterParams(
SetFilterParams.builder()
.caseSensitive(false)
.textFormatter((cb, expr) -> {
Expression<String> newExpression = expr;
// lower input
newExpression = cb.lower(newExpression);
// Remove accents
newExpression = cb.function("TRANSLATE", String.class, newExpression,
cb.literal("áéíóúÁÉÍÓÚüÜñÑ"),
cb.literal("aeiouAEIOUuUnN"));
return newExpression;
})
.build()
)
)
.build()
Set Filter Model
Set filter model is represented by SetFilterModel class.
Supplying Filter Values
Since the Server-Side Row Model does not have all data loaded in the browser, you must provide the list of unique values for the set filter manually.
The adapter provides the supplySetFilterValues method, which automatically
fetches distinct sorted values from the database for a given column. It takes the column's FieldPath:
List<String> values = queryBuilder.supplySetFilterValues(FieldPath.of(Trade_.product));
There is also an untyped overload that resolves the column by its field name and returns List<Object> — handy when the field comes in as a string (e.g. from a request):
List<Object> values = queryBuilder.supplySetFilterValues("product");
Grid using Server Side Set Filter
Productuses default set filterPortfoliois case-sensitiveBookuses set filter with customtextFormatter- accent removalSubmitter Iduses set filter with numbersBirth Dateuses set filter with datesIs Solduses set filter with boolean values + Blank value can be selected- Source code for this grid available here
- Backend source code available here