Reputation: 4988
I have the following domain class
class Something {
User user
BigDecimal balance
Boolean cancelled
String status
Client client
Date dateCreated
Date lastUpdated
static constraints { ... }
...
}
I need to create a filter to this domain class the ui looks like this
I do not know how to create this filter all its criteria are optionals so I need your suggestions about what is the best way to create a criteria filter?
Thanks
Upvotes: 0
Views: 108
Reputation: 187499
I'd do it like this
List<Something filter(Client client, String status, BigDecimal balance) (
Something.withCriteria {
if (client) {
eq 'client', client
}
if (status) {
eq 'status', status
}
if (balance != null) {
eq 'balance', balance
}
// other predicates go here....
}
}
Upvotes: 1