DxGridDataColumn.UnboundType Property
Specifies the data type of the unbound column.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v22.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(GridUnboundColumnType.Bound)]
[Parameter]
public GridUnboundColumnType UnboundType { get; set; }
Property Value
Type | Default | Description |
---|---|---|
GridUnboundColumnType | Bound | A GridUnboundColumnType enumeration value. |
Available values:
Name | Description |
---|---|
Bound | The column is bound to a data field. This field specifies the column data type. |
Integer | The column contains Int32 values. |
Decimal | The column contains Decimal values. |
DateTime | The column contains DateTime values. |
String | The column contains String values. |
Boolean | The column contains Boolean values. |
Object | The column contains Object values. |
Remarks
Specify the column’s UnboundType
and FieldName properties. The FieldName
property value should be unique and not match the Grid data source’s field names.
The following example illustrates how to evaluate the total price for each product and display this value in the unbound “Total Price” column. Two ways to evaluate unbound column values are available:
The UnboundColumnData event.
@using Microsoft.EntityFrameworkCore @inject IDbContextFactory<NorthwindContext> NorthwindContextFactory @implements IDisposable <DxGrid Data="GridDataSource" UnboundColumnData="Grid_CustomUnboundColumnData"> <Columns> <DxGridDataColumn FieldName="ProductId" Caption="Product ID" DisplayFormat="d" /> <DxGridDataColumn FieldName="UnitPrice" /> <DxGridDataColumn FieldName="Quantity" /> <DxGridDataColumn FieldName="Discount" DisplayFormat="p0" /> <DxGridDataColumn FieldName="Terminated" UnboundType="GridUnboundColumnType.Boolean"> <CellDisplayTemplate> <DxCheckBox CssClass="d-inline-block" Checked="@((bool)context.Value)" /> </CellDisplayTemplate> </DxGridDataColumn> <DxGridDataColumn FieldName="TotalPrice" DisplayFormat="c" UnboundType="GridUnboundColumnType.Decimal" /> </Columns> </DxGrid> @* ... *@ @code { object GridDataSource { get; set; } NorthwindContext Northwind { get; set; } protected override void OnInitialized() { Northwind = NorthwindContextFactory.CreateDbContext(); GridDataSource = Northwind.OrderDetails .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); } if(e.FieldName == "Discontinued") { e.Value = Convert.ToDecimal(e.GetRowValue("Discount")) == 0; } } public void Dispose() { Northwind?.Dispose(); } }
The UnboundExpression property.
@using Microsoft.EntityFrameworkCore @inject IDbContextFactory<NorthwindContext> NorthwindContextFactory @implements IDisposable @* ... *@ <DxGrid Data="GridDataSource"> <Columns> <DxGridDataColumn FieldName="Product.ProductName" Caption="Product Name" /> <DxGridDataColumn FieldName="UnitPrice" DisplayFormat="c" /> <DxGridDataColumn FieldName="Quantity" DisplayFormat="d" /> <DxGridDataColumn FieldName="Discount" DisplayFormat="p0" /> <DxGridDataColumn FieldName="TotalSum" DisplayFormat="c" UnboundType="GridUnboundColumnType.Decimal" UnboundExpression="UnitPrice * Quantity * (1 - Discount)" /> </Columns> </DxGrid> @code { object GridDataSource { get; set; } NorthwindContext Northwind { get; set; } protected override void OnInitialized() { Northwind = NorthwindContextFactory.CreateDbContext(); GridDataSource = Northwind.OrderDetails .Include(i => i.Product) .ToList(); } @* ... *@ public void Dispose() { Northwind?.Dispose(); } }
Note
When you use a Server Mode data source, the Grid does not support unbound columns whose values are populated in the UnboundColumnData event handler. You can create unbound columns whose values are calculated based on the UnboundExpression.
When you use a GridDevExtremeDataSource, the Grid does not support any unbound columns.