• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Multiple Summary Values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Summary Values

    I'm trying to put together an app where the user wants to see both the total and average of a column. Is there a way to do this beyond having the column appear twice?

  • #2
    We currently don’t have a way to show multiple summary values on a single column. However, you can work around this by setting the column’s summary type to total and then using a custom formatter (summary renderer) to calculate and display the average as well.


    Here’s an example:
    Code:
    // If this is a summary row, calculate and display both the average and total
    // when the store has records
    if (summary && summary.isRow) {
        const totalCount = grid.getStore().getTotalCount();
        const average = totalCount > 0 ? v / totalCount : 0;
    
        if (average > 0) {
            const roundedAverage = Math.round(average * 100) / 100;
    
            // Display Average and Total with labels left-aligned and values right-aligned
            return `
                <div style="display:flex; justify-content:space-between; width:100%;">
                    <span>Average:</span>
                    <b>${roundedAverage}</b>
                </div>
                <div style="display:flex; justify-content:space-between; width:100%;">
                    <span>Total:</span>
                    <b>${v}</b>
                </div>
            `;
        }
        return v;
    }
    return v;

    Comment

    Working...
    X