Tree Data
To enable Tree Data, set .treeData(true) and configure the field mappings needed to traverse the hierarchy. The entity's ID attribute is passed as the second argument to QueryBuilder.builder(entityClass, primaryField, ...) (it is not a chained method).
| Method | Type | Required | Description |
|---|---|---|---|
treeData | boolean | Yes | Enables Tree Data mode. |
isServerSideGroupFieldName | String | Yes | Name of the virtual boolean field indicating if a row has children. Matches field used in isServerSideGroup callback. |
treeDataParentReferenceField | SingularAttribute<E, E> | Conditional | The parent-reference attribute (e.g. Trade_.parentTrade). Required if not using treeDataParentIdField. |
treeDataParentIdField | SingularAttribute<E, E_ID> | Conditional | The raw parent-ID attribute. Required if not using treeDataParentReferenceField. |
treeDataStringToParentIdTypeConverter | Function<String, E_ID> | Yes | Converts a parent group key (String) to the parent id type E_ID (e.g. Long::valueOf). Group keys arrive as strings, so this rebuilds the id used to match parent rows. |
treeDataChildrenField | PluralAttribute<E, ?, ?> | No | The child-collection attribute (e.g. Trade_.childTrades). |
treeDataDataPathFieldName | SingularAttribute<E, String> | No | The attribute storing the path string. Use if you want to utilize standard tree filtering. |
treeDataDataPathSeparator | String | No | The string separator used in your path. For example, in path 1/2/3, this would be /. |
Example:
this.queryBuilder = QueryBuilder.builder(Trade.class, Trade_.tradeId, entityManager) // primary key attribute is the 2nd arg
.colDefs(
// colDefs
)
// turn on treeData
.treeData(true)
// name of field in which we return whether has children (required)
.isServerSideGroupFieldName("hasChildren")
// attribute that references the parent (provide one of them)
.treeDataParentReferenceField(Trade_.parentTrade) // mapped parent entity
// .treeDataParentIdField(Trade_.parentTradeId) // raw parent ID field
// converts a parent group key (String) to the parent id type (required)
.treeDataStringToParentIdTypeConverter(Long::valueOf)
// attribute which holds child collection (optional)
.treeDataChildrenField(Trade_.childTrades)
.build();
Providing Child Counts
To make providing child counts work, you need to provide treeDataDataPathFieldName parameter.
When showing child counts with Tree Data, the child count is a count of all descendants, including groups.
To receive child counts for groups, you need to set getChildCount param to true and provide property name getChildCountFieldName in which server returns the count.
Aggregations on Tree Data
To make aggregation on tree data work, you need to provide treeDataDataPathFieldName parameter.
You can get aggregates on group-level nodes the same way as with regular grouping.
Filtering Tree Data
When filtering Tree Data in Server-Side Row Model, the adapter follows the standard AG Grid filtering logic.
A group will be included if:
- it has any children that pass the filter, or
- it has a parent that passes the filter, or
- its own data passes the filter
To make filtering of tree data work as expected, you need to provide treeDataDataPathFieldName parameter.
Ignore Filters when Aggregating Values
When using Tree Data and filters, the aggregates are only calculated from the rows which pass the filter.
This can be changed by enabling the queryBuilder option suppressAggFilteredOnly.