Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
115
Apply multiple summaries on one igx-column
posted

My problem statement goes like this:-

I am providing a dropdown to the client to select which summary he wants to use.

I want to provide the functionality to display multiple summaries at once.
I am familiar with Custom Summaries and the example provided in it. I have tried implementing it that way, but I can't find a way to combine the logic of multiple summaries into one.
I also can't access the summaries that the user chooses since it's on the column object and the custom summary has no access to that (at least I couldn't find one).
I would love a solution if there is one.
Thanks..!!

  • 640
    Offline posted

    Hello Kaushik,

    Thank you for posting in our community.

    What I can suggest is creating combinations of individual summaries and by checking what the user has chosen to display the correct combination:

    TYPESCRIPT

    class AvgSumSummary {
        public operate(data?: any[], allData = [], fieldName = ''): IgxSummaryResult[] {
            const result = [];
            result.push({
                key: 'columnSum',
                label: 'Column sum',
                summaryResult: IgxNumberSummaryOperand.sum(data).toFixed(2)
            });
            result.push({
                key: 'columnAvg',
                label: 'Column avg',
                summaryResult: (IgxNumberSummaryOperand.sum(data) / data.length).toFixed(2)
            });
            return result;
        }
    }

    public onFilteringDone(args: IFilteringExpressionsTree) {
        ...
        const selectedItems = this.combo.selectedItems();
    
        if (selectedItems.indexOf('SumSummary') !== -1 && selectedItems.indexOf('AvgSummary') !== -1) {
            this.currentColumn.summaries = AvgSumSummary;
        } else if (selectedItems.indexOf('SumSummary') !== -1) {
            this.currentColumn.summaries = SumSummary;
        } else if (selectedItems.indexOf('AvgSummary') !== -1) {
            this.currentColumn.summaries = AvgSummary;
        }
        ...
    }

    I 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.

    Please let me know if you have any further questions and concerns.

    Regards,
    Viktor Kombov
    Entry Level Software Developer
    Infragistics, Inc.