DxGridDataColumn Class
A DxGrid‘s data column.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
#Declaration
public class DxGridDataColumn :
DxGridColumn,
IGridDataColumn,
IGridColumn,
IParameterTrackerSettingsOwner
#Remarks
The DxGrid supports bound and unbound data columns. Bound columns get their data from the bound data source. Unbound columns are not bound to any data source field and should be populated manually.
#Create a Bound Column
Add a DxGridDataColumn
object to the Columns collection. Specify the FieldName property to bind the column to a data field. Note that the FieldName property value must be unique for each data column.
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource">
<Columns>
<DxGridDataColumn FieldName="OrderId" Caption="Order ID" DisplayFormat="d" />
<DxGridDataColumn FieldName="Order.OrderDate" DisplayFormat="d" Caption="Order Date" />
<DxGridDataColumn FieldName="Order.ShipName" Caption="Ship Name" />
<DxGridDataColumn FieldName="Discount" DisplayFormat="p0" />
</Columns>
</DxGrid>
@code {
object GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
protected override void OnInitialized() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = Northwind.OrderDetails
.Include(i => i.Order)
.ToList();
}
public void Dispose() {
Northwind?.Dispose();
}
}
#Create an Unbound Column
Add a DxGridDataColumn
object to the Columns collection and and set up the following properties:
- UnboundType
- Indicates that the column is unbound and specifies its data type.
- FieldName
- Specifies a unique name that should not match field names in the Grid’s data source.
You can use the following API to fill an unbound column with data:
- UnboundExpression
- Specifies an expression to evaluate column values. An expression can consist of field names, constants, operators, and functions.
- UnboundColumnData
- Allows you to implement custom logic or obtain column values from a custom/external data source.
<DxGrid Data="forecasts" UnboundColumnData="Grid_CustomUnboundColumnData">
<Columns>
<DxGridDataColumn FieldName="Date" Caption="Date" />
<DxGridDataColumn FieldName="TemperatureC" Caption="@("Temperature (\x2103)")" />
<DxGridDataColumn FieldName="TemperatureF" Caption="@("Temperature (\x2109)")"
UnboundType="GridUnboundColumnType.Decimal"
UnboundExpression="32 + [TemperatureC] / 0.5556" />
<DxGridDataColumn FieldName="Summary"
UnboundType="GridUnboundColumnType.String" />
</Columns>
</DxGrid>
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync() {
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
void Grid_CustomUnboundColumnData(GridUnboundColumnDataEventArgs e) {
if (e.FieldName == "Summary") {
int temperature = Convert.ToInt32(e.GetRowValue("TemperatureC"));
e.Value = GetTemperatureString(temperature);
}
}
static string GetTemperatureString(int value) {
if (value < -10)
return "Cool";
if (value >= -10 && value < 5)
return "Chilly";
if (value >= 5 && value < 15)
return "Warm";
return "Hot";
}
}
#Limitations
- 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 unbound columns.
#Column Cell Editors
The Grid component generates and configures cell editors for columns based on associated data types. The component automatically displays column editors in the filter row and in data rows during edit operations.
The table below list classes that define cell editor settings and the corresponding data types:
Editor Settings | Generated for Data Types | Supported Data Types |
---|---|---|
All data types | ||
All data types | ||
Never generated | Numeric, String, Time | |
Never generated | ||
Refer to the following topic for additional information: Cell Editors in Blazor Grid.
#Inheritance
-
The Grid replaces a checkbox editor with a combo box in the filter row.