Skip to main content
A newer version of this page is available. .

GridUnboundColumnDataEventArgs Class

Contains data for the UnboundColumnData event.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public class GridUnboundColumnDataEventArgs

Remarks

Handle the UnboundColumnData event to specify data for the unbound column. Use GridUnboundColumnDataEventArgs (Value, FieldName, and so on) to specify column values and access other grid data.

The following example illustrates how to create two unbound columns: “Discontinued” and “Total Price”. The UnboundType property specifies the data types of the unbound columns (Boolean and Decimal). To display the “Discontinued” column values as check boxes, use the DxCheckBox<T> component within the column’s cell template (CellDisplayTemplate). The UnboundColumnData event allows you to evaluate data for the unbound columns.

@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();
    }
}

DevExpress Blazor Grid - Unbound Columns

Inheritance

Object
GridUnboundColumnDataEventArgs
See Also