Access to aggregation values

Hello,

Is there any possibility to have access to the aggregation values from a table?
Let say we have a column with BigDecimal values and following the aggregation “SUM” we have a top row with a BigDecimal value: 524.
How can we get 524 programmatically?

Regards,
-n

Hello @neutrino

You can use method Table#getAggregationResults() that returns map of aggregation results for corresponding columns.

Regards,
Daniil

1 Like

Something doesn’t work…instead of 75 I have 0.

  for (int i=0; i<resourcesTable.getAggregationResults().size(); i++){
            Map<Object, Object> hash = resourcesTable.getAggregationResults();
            Set<Object> set = hash.keySet();
            Iterator itr = set.iterator();
            Object string = itr.next();
            BigDecimal val = (BigDecimal) hash.get(string);
            System.out.println("jjj" + string );
            System.out.println("fff" + val);
}

agg
agg1

Could you describe the case in more details? I’ve tested all aggregation types with BigDecimal and everything works ok.

I defined a new BigDecimal attributeamount (to a random entity), I set the aggregate type (table and column) and I tried to get the SUM result to onInit method. In the map there is amount attribute but the value is zero. Maybe I have to define more columns? But is non sense…
Can you share your code snippet, please?

You cannot get aggregation results because at this moment there is no data to aggregate.

I don’t understand. I added 3 records (40, 30, 5) and the table shows aggregate 75. What do you mean…

there is no data?

I mean that data is not loaded when InitEvent occurred

image

Why?
From which event the data is loaded? I tried to AfterInitEvent but the result is the same.

In generic case @LoadDataBeforeShow annotation is used, so you can subscrube for BeforeShowEvent when data will be ready

Still doesn’t work:

@Subscribe
public void onBeforeShowEvent(BeforeShowEvent event){

//my  code

}

Where shoud I use @LoadDataBeforeShow annotation?

Sorry, I’ve mixed up with AfterShowEvent:

image

It works perfectly now.
You made my day!

Thank you Daniil!