You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the built in group by feature to aggregate rows by either sum or count.
However I hit an edge case that is not handled by the built in groupBy aggregate function. The issue is that I have a list of items coming from a database query. I only wont to count each row once when doing the aggregate - if the same Id appears twice I dont want it to be summed twice.
I managed a hacky solution by attaching a Set to the column object that is passed to the aggregateValue function and then removing it when the Aggregated cell is rendered - this way I "initialize" the Set whenever it starts aggregating a certain column and reset it after all the work is complete for the next run. So far so good. I works for the built in Sum aggregate function. I will need to specialise the Count function to actually iterate through the rows and ignore undefined/null (or some sentinel value depending on my requirements if undefined should be counted).
However...
The aggregatedGroupedRows function only uses the aggregateValue function for the outermost grouping [depth === 0], from then on it just uses the regular aggregate function [whatever was defined for that column]. The issue is that for deeper levels of groupings I have no way of controlling which value should be used for a given row - it just returns the value from row.values[column.id] and does not give me a chance to intercept it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using the built in group by feature to aggregate rows by either sum or count.
However I hit an edge case that is not handled by the built in groupBy aggregate function. The issue is that I have a list of items coming from a database query. I only wont to count each row once when doing the aggregate - if the same Id appears twice I dont want it to be summed twice.
I managed a hacky solution by attaching a Set to the column object that is passed to the aggregateValue function and then removing it when the Aggregated cell is rendered - this way I "initialize" the Set whenever it starts aggregating a certain column and reset it after all the work is complete for the next run. So far so good. I works for the built in Sum aggregate function. I will need to specialise the Count function to actually iterate through the rows and ignore undefined/null (or some sentinel value depending on my requirements if undefined should be counted).
However...
The aggregatedGroupedRows function only uses the aggregateValue function for the outermost grouping [depth === 0], from then on it just uses the regular aggregate function [whatever was defined for that column]. The issue is that for deeper levels of groupings I have no way of controlling which value should be used for a given row - it just returns the value from row.values[column.id] and does not give me a chance to intercept it.
Any suggestions how to solve this? Is my only option to fork the useGroupBy plugin and change its logic?
Beta Was this translation helpful? Give feedback.
All reactions