Advanced Filter
Enable Advanced filter
To enable the advanced filter, set the value of the enableAdvancedFilter variable in QueryBuilder to true:
this.queryBuilder = QueryBuilder.builder(Entity.class, Entity_.id, entityManager)
.colDefs(
// colDefs
)
.enableAdvancedFilter(true) // enable advanced filtering
.build();
For a column to be filterable in the Advanced Filter, it must have a filter defined in its ColDef.
If a column does not have a filter set in ColDef, attempting to apply an Advanced Filter on it will result in an exception.
Filter Params
Filter parameters are taken from ColDef.
- Text & Object Filters → TextFilterParams
- Date & DateString Filters → DateFilterParams
- Number Filters → NumberFilterParams
- Boolean Filters → No filter parameters
- Set Filters → SetFilterParams
Grid using Server Side Advanced Filter
Productuses a set filter- Source code for this grid available here
- Backend source code available here
Loading grid...
Custom Filter Options
Register each option under its displayKey, which AG Grid sends as the condition's type:
this.queryBuilder = QueryBuilder.builder(Trade.class, Trade_.tradeId, entityManager)
.colDefs(
ColDef.builder(Trade_.currentValue)
.filter(new AgNumberColumnFilter<>())
.build()
)
.enableAdvancedFilter(true)
.registerCustomAdvancedFilter("betweenExclusive", BetweenExclusiveFilterModel::new)
.build();
The function receives the raw condition and returns the filter model:
public class BetweenExclusiveFilterModel extends ColumnAdvancedFilterModel<Trade, BigDecimal> {
private final BigDecimal from;
private final BigDecimal to;
public BetweenExclusiveFilterModel(Map<String, Object> filter) {
super("number", FieldPath.of(Trade_.currentValue));
// { filterType: 'number', colId: 'currentValue', type: 'betweenExclusive', filter: 30, filterTo: 40 }
this.from = new BigDecimal(filter.get("filter").toString());
this.to = new BigDecimal(filter.get("filterTo").toString());
}
@Override
public Predicate toPredicate(CriteriaBuilder cb, Root<? extends Trade> root) {
Expression<BigDecimal> currentValue = this.getColumnField().getExpression(cb, root);
return cb.and(cb.gt(currentValue, this.from), cb.lt(currentValue, this.to));
}
}
Grid using Custom Filter Options
PortfoliooffersStarts with vowel(no input)Current ValueoffersBetween (Exclusive)(two inputs)Birth DateoffersSame year as(one input)- The last filter model sent to the server is shown below the grid
- Source code for this grid available here
- Backend source code available here
Loading grid...