Help with Table#getAggregationResults()


I need some help to get aggregated values to display in a field. I read about using the method Table#getAggregationResults(), but i don’t know how to start. Help please.




getAggregationResults() returns a map where the key is column id and value is the column’s aggregation value. Aggregation is applied only for items that are loaded in the data container.

For instance, to show value in the field you can do the following:

private TextField<Long> countField;
private TextField<BigDecimal> priceField;

private GroupTable<Good> goodsTable;

public void onAfterShow(AfterShowEvent event) {
    Map<Object, Object> results = goodsTable.getAggregationResults();

    Object countId = goodsTable.getColumn("count").getId();
    countField.setValue((Long) results.get(countId));

    Object priceId = goodsTable.getColumn("price").getId();
    priceField.setValue((BigDecimal) results.get(priceId));

Count and Price columns have “SUM” aggregation type. The full example see here: (81.6 KB)

Thanks Roman Pinyazhin.