GridComponent's column: expressions, filtering and sorting

You should be aware of some limitations about using expressions in column which have to be filterable or/and sortable.
Because filtering and ordering grid items are performed by database while expression is evaluated at application level only simple expressions representing path to the displayed field are supported. 

Supported expressions

By simple expressions representing path we mean:

#simpleField
#belongsToField['simpleField']
#belongsToField['otherBelongsToField'].get('simpleField')
#belongsToField['otherBelongsToField'].get('anotherBelongsToField').getStringField('simpleField')
#belongsToField.get('simpleField')
#belongsToField.get('otherBelongsToField').get('simpleField')
#belongsToField.get('otherBelongsToField').get('anotherBelongsToField').getStringField('simpleField')
#belongsToField.get('otherBelongsToField').get('anotherBelongsToField').getBelongsToField(..).getBelongsToField(..) .. .getStringField('simpleField') 

And so on, where:

  • simpleField - name of field representing some value (not relation), for example: <integer .. />, <string .. />, <date .. /> etc.
  • belongsToField, otherBelongsToField, anotherBelongsToField - name of <belongsTo .. /> fields.

As you can see at above examples we were using also regular Entity's methods like 'getBelongsToField' or 'getStringField' instead of 'get'.

This is an implementation side effect - we convert entities to java.util.Maps before passing them as a variable to Expression Evaluator. Because relations between entities form a kind of bi-directional graph, we had to find efficient way to avoid infinite cycles during mapping.
We've decided to limit the depth level of traverse to some fixed value (currently it's 2) to achieve this goal without performance overhead.

So you have to remember that you can use .get('') (or brackets) only twice in a single expression and each further traversal will require use of appropriate Entity's API methods.

 

Using 'Safe navigation operator' (?.) is also allowed:

#belongsToField['otherBelongsToField']?.get('simpleField')
#belongsToField?.get('simpleField')
#belongsToField?.get('otherBelongsToField').get('simpleField')
#belongsToField.get('otherBelongsToField')?.get('simpleField')
#belongsToField?.get('otherBelongsToField')?.get('simpleField')

If you use an expression that is not supported then filtering / sorting grid will not work.

Unsupported expressions

Let's see a few examples of expressions that do not support sorting/filtering: 

'some string literal'
#someField + ' ' + #otherField
#belongsToField == null ? '' : #belongsToField['simpleField']
T(SomeHelperClass).staticMethod(#someField)
#hasManyField.get(0)
#belongsToField.get('hasManyField')[0]