Is it possible to make grid aggregates based on data out of several columns?
Requirement:
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true"> <GridAggregates> <GridAggregate> <GridAggregateColumns> <GridAggregateColumn Field=@nameof(Product.UnitsInStock) Type="AggregateType.Sum"> <FooterTemplate> @{ var aggregate = (context as AggregateTemplateContext); <div> <p>Total units:@CustomdAggregateCalc(aggregate)p> div> } FooterTemplate> GridAggregateColumn> GridAggregateColumns> GridAggregate> GridAggregates> ... SfGrid>
@code{ SfGrid<Product> Grid { get; set; } ... public string CustomdAggregateCalc(AggregateTemplateContext val) { //fetch the records with only true values for Discontinued column var data = Products.Where(e => e.Discontinued == true);
//Now calcluate the value and return it to Footer Template to display in Grid return Queryable.Sum(data.Select(x => x.UnitsInStock).AsQueryable()).ToString("N2");
} ... } |
Here is a sample for your reference,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGrid1047861799
- 0 Reply
- 1 Participant
-
SS Syncfusion Support
- Dec 3, 2020 10:47 AM UTC
- Jul 13, 2021 06:15 AM UTC