React Grid Summaries

    The Ignite UI for React Summaries feature in React Grid functions on a per-column level as group footer. React IgrGrid summaries is powerful feature which enables the user to see column information in a separate container with a predefined set of default summary items, depending on the type of data within the column or by implementing a custom template in the IgrGrid.

    React Grid Summaries Overview Example

    [!Note] The summary of the column is a function of all column values, unless filtering is applied, then the summary of the column will be function of the filtered result values

    IgrGrid summaries can also be enabled on a per-column level in Ignite UI for React, which means that you can activate it only for columns that you need. IgrGrid summaries gives you a predefined set of default summaries, depending on the type of data in the column, so that you can save some time:

    For string and boolean dataType, the following function is available:

    • Contar

    Para number e currency​ ​percent tipos de dados, as seguintes funções estão disponíveis:

    • Contar
    • Mínimo
    • Máx.
    • Média
    • Soma

    Para date o tipo de dados, as seguintes funções estão disponíveis:

    • Contar
    • Mais antigo
    • Mais recente

    Todos os tipos de dados de coluna disponíveis podem ser encontrados no tópico oficial Tipos de coluna.

    IgrGrid summaries are enabled per-column by setting hasSummary property to true. It is also important to keep in mind that the summaries for each column are resolved according to the column data type. In the IgrGrid the default column data type is string, so if you want number or date specific summaries you should specify the dataType property as number or date. Note that the summary values will be displayed localized, according to the grid locale and column pipeArgs.

    <IgrGrid autoGenerate="false" height="800px" width="800px">
        <IgrColumn field="ProductID" header="Product ID" width="200px"  sortable="true">
        </IgrColumn>
        <IgrColumn field="ProductName" header="Product Name" width="200px" sortable="true" hasSummary="true">
        </IgrColumn>
        <IgrColumn field="ReorderLevel" width="200px" editable="true" dataType="number" hasSummary="true">
        </IgrColumn>
    </IgrGrid>
    

    The other way to enable/disable summaries for a specific column or a list of columns is to use the public method enableSummaries/disableSummaries of the IgrGrid.

    function enableSummary() {
        gridRef.current.enableSummaries([
            {fieldName: 'ReorderLevel'},
            {fieldName: 'ProductID'}
        ]);
    }
    function disableSummary() {
        gridRef.current.disableSummaries(['ProductID']);
    }
    
    <IgrGrid ref={gridRef} auto-generate="false" height="800px" width="800px">
        <IgrColumn field="ProductID" header="Product ID" width="200px" sortable="true">
        </IgrColumn>
        <IgrColumn field="ProductName" header="Product Name" width="200px" sortable="true" hasSummary="true">
        </IgrColumn>
        <IgrColumn field="ReorderLevel" width="200px" editable="true" dataType="number" hasSummary="false">
        </IgrColumn>
    </IgrGrid>
    <button onClick={enableSummary}>Enable Summary</button>
    <button onClick={disableSummary}>Disable Summary </button>
    

    Summary Template

    Summary tem como alvo o resumo da coluna, fornecendo como contexto os resultados do resumo da coluna.

    function summaryTemplate(ctx: IgrSummaryTemplateContext) {
      return (
        <>
          <span>My custom summary template</span>
          <span>{ctx.dataContext.implicit[0].label} - {ctx.dataContext.implicit[0].summaryResult}</span>
        </>
      );
    }
    
    <IgrColumn hasSummary="true" summaryTemplate={summaryTemplate}></IgrColumn>
    

    When a default summary is defined, the height of the summary area is calculated by design depending on the column with the largest number of summaries and the --ig-size of the grid. Use the summaryRowHeight input property to override the default value. As an argument it expects a number value, and setting a falsy value will trigger the default sizing behavior of the grid footer.

    Formatting summaries

    By default, summary results, produced by the built-in summary operands, are localized and formatted according to the grid locale and column pipeArgs. When using custom operands, the locale and pipeArgs are not applied. If you want to change the default appearance of the summary results, you may format them using the summaryFormatter property.

    public summaryFormatter(
        summary: IgrSummaryResult,
        summaryOperand: IgrSummaryOperand
      ): string {
        const result = summary.summaryResult;
        if (summary.key !== "count" && result !== null && result !== undefined) {
          const format = new Intl.DateTimeFormat("en", { year: "numeric" });
          return format.format(new Date(result));
        }
        return result;
      }
      
    <IgrColumn hasSummary="true" summaryFormatter={this.summaryFormatter}></IgrColumn>
    

    Summaries with Group By

    When you have grouped by columns, the IgrGrid allows you to change the summary position and calculation mode using the summaryCalculationMode and summaryPosition properties. Along with these two properties the IgrGrid exposes and showSummaryOnCollapse property which allows you to determine whether the summary row stays visible when the group row that refers to is collapsed.

    Os valores disponíveis do summaryCalculationMode imóvel são:

    • RootLevelOnly- Os resumos são calculados apenas para o nível raiz.
    • ChildLevelsOnly- Os resumos são calculados apenas para os níveis filhos.
    • RootAndChildLevels- Resumos são calculados para níveis raiz e filho. Este é o valor padrão.

    Os valores disponíveis do summaryPosition imóvel são:

    • Top- A linha de resumo aparece antes dos filhos do grupo por linha.
    • Bottom- A linha de resumo aparece depois do grupo por linha filhos. Este é o valor padrão.

    A showSummaryOnCollapse propriedade é booleana. Seu valor padrão é definido como false, o que significa que a linha de resumo ficaria oculta quando a linha do grupo fosse recolhida. Se a propriedade for definida como true, a linha de resumo permanecerá visível quando a linha do grupo for recolhida.

    [!Note] The summaryPosition property applies only for the child level summaries. The root level summaries appear always fixed at the bottom of the IgrGrid.

    Demo

    Keyboard Navigation

    As linhas de resumo podem ser navegadas com as seguintes interações de teclado:

    • PARA CIMA- navega uma célula para cima.
    • PARA BAIXO- navega uma célula para baixo.
    • ESQUERDA- navega uma célula para a esquerda.
    • DIREITA- navega uma célula para a direita.
    • CTRL + ESQUERDA ou HOME- navega para a célula mais à esquerda.
    • CTRL + DIREITA ou END- navega para a célula mais à direita.

    Styling

    Além dos temas predefinidos, a grade pode ser ainda mais personalizada ao definir algumas das propriedades CSS disponíveis. Caso você queira alterar algumas das cores, precisa definir uma classe para a grade primeiro:

    <IgrGrid className="grid">
    </IgrGrid>
    

    Em seguida, defina as propriedades CSS relacionadas para essa classe:

    .grid {
        --ig-grid-summary-background-color:#e0f3ff;
        --ig-grid-summary-focus-background-color: rgba( #94d1f7, .3 );
        --ig-grid-summary-label-color: rgb(228, 27, 117);
        --ig-grid-summary-result-color: black;
    }
    

    Demo

    API References

    Additional Resources

    Nossa comunidade é ativa e sempre acolhedora para novas ideias.