Hello,
I have a currency column that can have multiple currencies. For this reason for the Total Sum I would like to use the response received from a backend request instead of IgxNumberSummaryOperand because all the values need to be converted to one currency and then summed. I tried to implement a custom summary that extends IgxNumberSummaryOperand but I have access only to columnData, allGridData and fieldName and it does not help me.
Is there any way to do this?
Thanks,
Anca
Hello Anca,
Thank you for posting in our community.
What I can suggest in order to change the default appearance of the summary results, is formatting them using the IgxColumnComponent's summaryFormatter property :
public summaryFormatter = (summary: IgxSummaryResult): string => { const result = summary.summaryResult; if (summary.key === 'sum') { return this.theSumFromTheBackEnd; } return result; }
Please keep in mind that since the formatter function is called from another context ( IgxColumnComponent) the properties of your component will not be available there. I would suggest using an arrow function so the "this" context is preserved.
Additionally, please ensure that the summaries are not cached when you are trying to recalculate them. In order to do that, you should clear the gird's summaries cache using its summaryService API:
this.grid.summaryService.clearSummaryCache(); this.grid.summaryService.recalculateSummaries();
I have created a small sample illustrating my suggestion, which you can find here. Please test it on your side and let me know whether you find it helpful.
Regards,Viktor KombovEntry Level Software DeveloperInfragistics, Inc.
Thank you for your answer.
Your solution works perfectly for when there is no grouping in the data-grid. If I make a grouping by a column then all subtotals have the same value with the total sum. Is there any method by which, even when I have group by in data-grid to format the sum and subtotals with values coming from the backend?
It depends of the configuration of the backend. If the backend knows what was the sum before it was being formatted, there can be made a check in the summaryFormatter function whether the summaryResult property of the summary argument is equal to the sum of the values in the cells in а group or in the column:
public summaryFormatter = (summary: IgxSummaryResult, second): string => { const column = this.grid.getColumnByName('BeatsPerMinute'); let sumOfAllValuesInTheColumn = column.cells.reduce((sum, currCell) => sum + currCell.value), 0); if (summary.summaryResult === sumOfAllValuesInTheColumn) { return this.customSummarySum.toString(); } return summary.summaryResult; }
I have updated the previously provided sample illustrating my suggestion. Please keep in mind that since we do not provide an out of the box option for customizing summaries of the grid's groups my suggestion is a workaround on application level, which is not fully tested, so it is possible to encounter any edge cases for some scenarios. Additionally, If you would like to see this feature implemented as part or out product I could suggest submitting a new feature request in our GitHub repository here.
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case.
This will give you the opportunity do directly communicate with our development team regarding the issue and get notifications whenever a new information is available. Once logged, please provide me the link to your issue to that I can prioritize it accordingly.
Looking forward to hearing from you.