|
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true">
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<FooterTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
<div>
<p>Weighted Aggregate: @GetWeightedAggregate() </p> //here we have calculated two columns value and rendered in custom aggregate
</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Product> Grid { get; set; }
public List<Product> Products { get; set; }
private string[] Units = (new string[] { "QuantityPerUnit" });
public string WeightedAggregate = "";
public string GetWeightedAggregate()
{
// perform grouping and sorting as per the grouped column
return Queryable.Sum(Products.Select(x=>x.UnitsInStock + x.UnitsInStock1).AsQueryable()).ToString("N4");
}
. . .
} |
|
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true" AllowFiltering="true">
<GridEvents OnActionComplete="Complete" TValue="Product"></GridEvents>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<FooterTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
<div>
<p>Weighted Aggregate: @GetWeightedAggregate() </p>
</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
<GridColumn Field=@nameof(Product.ProductName) HeaderText="Product Name" TextAlign="TextAlign.Right" Width="150"></GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Product> Grid { get; set; }
public List<Product> Products { get; set; }
public object Filterd { get; set; }
private string[] Units = (new string[] { "QuantityPerUnit" });
public string WeightedAggregate = "";
public string GetWeightedAggregate()
{
if(Filterd == null) //check whether has filtered records or not
{
return Queryable.Sum(Products.Select(x => x.UnitsInStock + x.UnitsInStock1).AsQueryable()).ToString("N4"); //return calculated aggregate value for all records
} else
{
var fildterData = (List<Product>)Filterd;
return Queryable.Sum(fildterData.Select(x => x.UnitsInStock + x.UnitsInStock1).AsQueryable()).ToString("N4"); //return calculated aggregate value for filtered records
}
}
public async Task Complete(ActionEventArgs<Product> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering)
{
Filterd = await Grid.GetFilteredRecords(); //get filtered records
}
}
. . .
} |
|
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true" AllowGrouping="true" AllowFiltering="true">
<GridEvents OnActionComplete="Complete" TValue="Product"></GridEvents>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<FooterTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
<div>
<p>Weighted Aggregate: @GetWeightedAggregate() </p> //call your custom function here..
</div>
}
</FooterTemplate>
<GroupCaptionTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
var a = 4;
<div>
@*<p>Group Aggregate: @CustomdAggregateCalc() </p>*@ //call your custom function here..
<p>Group Aggregate: @aggregate.Sum </p> //or define default value
</div>
}
</GroupCaptionTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
. . .
</GridColumns>
</SfGrid> |