Help with Table#getAggregationResults()

Hi,

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.

Regards

LS

Hello,

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:

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

@Inject
private GroupTable<Good> goodsTable;

@Subscribe
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: demo.zip (81.6 KB)

Thanks Roman Pinyazhin.