Hi
2 small errors in doc. Discovered through sample project attached.
The aggregationStyle
attribute allows you to specify the location of the aggregation row: TOP
or BOTTOM
. TOP
is used by default.
In addition to the operations listed above, you can define a custom aggregation strategy by implementing the AggregationStrategy
interface and passing it to the setAggregation()
method of the Table.Column
class inside the AggregationInfo
instance. For example:
public class TimeEntryAggregation implements AggregationStrategy<List<TimeEntry>, String> {
@Override
public String aggregate(Collection<List<TimeEntry>> propertyValues) {
HoursAndMinutes total = new HoursAndMinutes();
for (List<TimeEntry> list : propertyValues) {
for (TimeEntry timeEntry : list) {
total.add(HoursAndMinutes.fromTimeEntry(timeEntry));
}
}
return StringFormatHelper.getTotalDayAggregationString(total);
}
@Override
public Class<String> getResultClass() {
return String.class;
}
}
AggregationInfo info = new AggregationInfo();
*info.setPropertyPath(metaPropertyPath); <= no
info.setStrategy(new TimeEntryAggregation());
Table.Column column = weeklyReportsTable.getColumn(columnId);
column.setAggregation(info);
info.setPropertyPath(metaPropertyPath); => no because if meta property path is defined the code in AggregatableDelegate
will not send the entity to the custom agg strategy but the property value defined by the meta property path set
protected Object doPropertyAggregation(AggregationInfo aggregationInfo, Collection<K> itemIds) {
List items;
if (aggregationInfo.getType() == AggregationInfo.Type.CUSTOM
&& aggregationInfo.getPropertyPath() == null) {
// use items in this case;
items = itemIds.stream()
.map(this::getItem)
.collect(Collectors.toList());
} else {
items = valuesByProperty(aggregationInfo.getPropertyPath(), itemIds);
}
[...]
Also, the sample should be written this way
public class TimeEntryAggregation implements AggregationStrategy<TimeEntry, String> {
@Override
public String aggregate(Collection<TimeEntry> propertyValues) {
HoursAndMinutes total = new HoursAndMinutes();
for (TimeEntry timeEntry : propertyValues) {
total.add(HoursAndMinutes.fromTimeEntry(timeEntry));
}
return StringFormatHelper.getTotalDayAggregationString(total);
}
@Override
public Class<String> getResultClass() {
return String.class;
}
}
Regards
Michael
grouptableavg.zip (80.0 KB)