I'm using angular Infragistics UI grid in typescript 12
And I'm trying to calculate the totale of the price field when the grid is in group by mode. Say I have 2 groups by client, group 1 contained 2 items and group 2 contained 3 items. I have to get the total price by each grouped client (for example 300 for group1 and 800 for the second).
Here is my code in HTML component
<igx-grid #grid id="grid" [data]="listeinvoices" [groupingExpressions]='expr' [allowFiltering]="true" [autoGenerate]="false" height="500px">
<igx-column field="client" header="client" [groupable]="true"></igx-column>
<igx-column field="price" header="price" [groupable]="true"></igx-column>
<igx-column field="invoicenumber" header="invoice nb" [groupable]="true"></igx-column>
</igx-grid>
The code of ts component :
export class FactureComponent implements OnInit {
public expr: ISortingExpression[];
@ViewChild("grid") public grid!: IgxGridComponent;
constructor(private rest: RestService,private toastr: ToastrService,private excelExportService: IgxExcelExporterService)
{
this.expr = [
{ dir: SortingDirection.Asc, fieldName: 'client', ignoreCase: false,
strategy: DefaultSortingStrategy.instance() },
];
}
}
You can use Summaries with the GroupBy feature. Now that you've set
groupableto the columns that you want to group, just go ahead and set[hasSummary]="true"to thePricecolumn.This will show you all Summary information for the Price column - like count, min, max, sum and avg. In your case you want to show only Total (sum), so my suggestion would be to create a custom summary:
Template:
Further more, if you want to show the Summaries only on childLeve (within the grouped level) you can use the summaryCalculationMode
For more information, check out the section of Summaries with GroupBy and Custom Grid Summaries