Skip to main content

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).

MethodTypeRequiredDescription
treeDatabooleanYesEnables Tree Data mode.
isServerSideGroupFieldNameStringYesName of the virtual boolean field indicating if a row has children. Matches field used in isServerSideGroup callback.
treeDataParentReferenceFieldSingularAttribute<E, E>ConditionalThe parent-reference attribute (e.g. Trade_.parentTrade). Required if not using treeDataParentIdField.
treeDataParentIdFieldSingularAttribute<E, E_ID>ConditionalThe raw parent-ID attribute. Required if not using treeDataParentReferenceField.
treeDataStringToParentIdTypeConverterFunction<String, E_ID>YesConverts 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.
treeDataChildrenFieldPluralAttribute<E, ?, ?>NoThe child-collection attribute (e.g. Trade_.childTrades).
treeDataDataPathFieldNameSingularAttribute<E, String>NoThe attribute storing the path string. Use if you want to utilize standard tree filtering.
treeDataDataPathSeparatorStringNoThe 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();
  • Source code for this grid available here
  • Backend source code available here
Loading grid...

Providing Child Counts​

warning

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.

  • Source code for this grid available here
  • Backend source code available here
Loading grid...

Aggregations on Tree Data​

warning

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.

  • Source code for this grid available here
  • Backend source code available here
Loading grid...

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:

  1. it has any children that pass the filter, or
  2. it has a parent that passes the filter, or
  3. its own data passes the filter
warning

To make filtering of tree data work as expected, you need to provide treeDataDataPathFieldName parameter.

  • Source code for this grid available here
  • Backend source code available here

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.