Power grid - how to add custom aggregate function

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Power grid - how to add custom aggregate function

Postby pitc » Tue Jun 01, 2021 1:44 pm

Is there a way to add a custom aggregation function to a power grid.
In the ag-grid docs (https://www.ag-grid.com/javascript-grid/aggregation/
it explains that custom aggregation can be provided via the colDefs or by the gridApi.addAggFunc() method.
I am not sure how to do either.

My objective is to show in the group row (using a custom InnerRenderer - which is working fine) a result of a calculation of the ratio of A and B as a percentage. Where A = aggregate (sum of x ) and B = grand sum (of x).
I do have the A value but need to get the B value.
A custom aggregate function would sum the values of a column for all rows to get the grand sum. The result of this function is then available in the InnerRenderer for the ratio calculation.
I know how to get the cellRenderer and the InnerRenderer function into a string and assign that to the property in the grid. But I am not sure how to provide the custom aggregate function via the colDefs (since there is no custom Aggregate func property).

How have others done this?
I did think about adding a column to the dataset for the power grid that contains the grand sum for every row then using the MAX aggregate function to get at it during the InnerRenderer (it is the same value of course so max is just a way to get it) but that seems a waste!
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: Power grid - how to add custom aggregate function

Postby Gabi Boros » Wed Jun 02, 2021 9:10 am

Unfortunately I don't think there is a way now to set a custom aggFunc, we don't expose ag-grid's 'aggFuncs' property, and although it is possible to define aggFunc directly on the columnDef,
we only support setting primitive custom properties via our 'columnDef' property, so setting a function won't work. But I'm also not sure how would you define such a function as that I think won't
have access to all rows, but just to the rows of the group and you want a sum of all, right? You're idea to have a column with grand sum should work, I don't see another way now.
Gabi Boros
Servoy
Gabi Boros
 
Posts: 399
Joined: Tue Jun 26, 2007 4:03 pm
Location: Timisoara, Romania

Re: Power grid - how to add custom aggregate function

Postby pitc » Wed Jun 02, 2021 2:36 pm

That is so disappointing. I was hoping to do multi-column aggregations calculations.
(I tried doing similar capbility in a data grid and it was not feasible - perhaps I may revisit that alternative).
It seems to me that such a feature would be useful.
It seems to me that since there is already a way to set a cell renderer function that it would be similar.
I wonder if the NG2 version might offer such a feature?
It seems the 'power' part of this grid is diminished.
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: Power grid - how to add custom aggregate function

Postby Gabi Boros » Wed Jun 02, 2021 3:07 pm

you may create a feature request to add support for defining custom aggregate functions;
btw, how would your custom aggregate function look like? is that based on the rows from the group or on all rows?
Gabi Boros
Servoy
Gabi Boros
 
Posts: 399
Joined: Tue Jun 26, 2007 4:03 pm
Location: Timisoara, Romania

Re: Power grid - how to add custom aggregate function

Postby pitc » Wed Jun 02, 2021 8:52 pm

Look at example 3 (Multi-column aggregate) here https://www.ag-grid.com/javascript-grid/aggregation/. Another use case is a weighted average rather than a simple average.
In my custom aggregate case I would sum a column of 'daily sales' of all row nodes to get a 'grand sum'.
Then I would grab the sum aggregate of 'daily sales' column for the current group and divide it by the 'grand sum' to get a ratio of the group daily sales to the grand sum.
Then multiply by 100 for a percent - which is the result passed back to the grid for display.
I will put in a feature request, good suggestion, maybe good for ng2 some time in the far future...whenever more votes come in I suspect.
I did add an extra column i the dataset and I did do an InnerRenderer to get the same result - but of course that is only good for the grid option of groupUseEntireRow =true.
It works as is a 'reasonable" UX but not the best since the user could unhide that grand sum column and wonder what is this doing here? {There is no way to permanently hide a column from view but allow it for calculations).
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada


Return to Programming with Servoy

Who is online

Users browsing this forum: Bing [Bot] and 8 guests