DxGridSummaryItem.FieldName Property
Specifies a data field whose values are used to calculate a summary.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v22.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(null)]
[Parameter]
public string FieldName { get; set; }
Property Value
Type | Default | Description |
---|---|---|
String | null | The data field’s name. |
Remarks
The DxGrid supports the total and group summaries. Each summary can contain predefined and custom summary items.
Use the summary item’s SummaryType property to specify an aggregate function to calculate the total and group summary values. The following functions are available: Sum, Min, Max, Avg, and Count.
The Avg, Min, Max, and Sum functions require that you set the FieldName property to a data field whose values take part in calculations. The Min and Max functions require a numeric or date-time data field. The Avg and Sum functions work with numeric fields only.
If you select the Count function, you can leave the FieldName property set to an empty string and use the FooterColumnName property to specify which column displays the summary value.
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
@* ... *@
<DxGrid Data="GridDataSource"
UnboundColumnData="Grid_CustomUnboundColumnData"
ShowGroupPanel="true">
<Columns>
<DxGridDataColumn FieldName="Order.ShipName" Caption="Contact Name" />
<DxGridDataColumn FieldName="Order.ShipCountry" Caption="Country" />
<DxGridDataColumn FieldName="Order.ShipCity" Caption="City" />
<DxGridDataColumn FieldName="ProductId" Caption="Product ID" DisplayFormat="d" />
<DxGridDataColumn FieldName="UnitPrice" />
<DxGridDataColumn FieldName="Quantity" />
<DxGridDataColumn FieldName="Discount" DisplayFormat="p0" />
<DxGridDataColumn FieldName="TotalPrice"
DisplayFormat="c"
UnboundType="GridUnboundColumnType.Decimal" />
</Columns>
<GroupSummary>
<DxGridSummaryItem SummaryType="GridSummaryItemType.Max"
ValueDisplayFormat="c"
FieldName="UnitPrice" />
</GroupSummary>
<TotalSummary>
<DxGridSummaryItem SummaryType="GridSummaryItemType.Sum" FieldName="TotalPrice" />
</TotalSummary>
</DxGrid>
@code {
object GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
protected override void OnInitialized() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = Northwind.OrderDetails
.Include(i => i.Order)
.Include(i => i.Product)
.ToList();
}
void Grid_CustomUnboundColumnData(GridUnboundColumnDataEventArgs e) {
if (e.FieldName == "TotalPrice") {
var UnitPrice = Convert.ToDecimal(e.GetRowValue("UnitPrice"));
var Quantity = Convert.ToDecimal(e.GetRowValue("Quantity"));
var Discount = Convert.ToDecimal(e.GetRowValue("Discount"));
e.Value = Quantity * UnitPrice * (1 - Discount);
}
}
public void Dispose() {
Northwind?.Dispose();
}
}