Skip to main content

IGridDataColumn Interface

An interface that defines a Grid data column‘s API members (properties and methods).

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public interface IGridDataColumn :
    IGridColumn

Remarks

We recommend that you use the IGridDataColumn interface when you access a Grid data column’s API members in any of the following cases:

  • You use the @ref attribute to reference a Grid data column. For example, you set or change values of the Grid column’s parameters outside the markup.
  • You access a DataColumn object from templates or event handlers.
  • You access elements of the Grid column collection. For example, the collection that is returned by the GetDataColumns() method.

In all other cases, bind your data to column parameters.

The following code snippet defines the DataColumnCellDisplayTemplate template to customize the appearance of column cells to distinguish between odd and even rows. The template context‘s DataColumn property (which returns an IGridDataColumn object) provides access to a grid data column to which the processed cell belongs.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<style>
    .my-style {
        color: blue;
        font-weight: bold;
    }
    .my-date-style {
        color: mediumblue;
        font-weight: bold;
    }
</style>

<DxGrid Data="@Data">
    <Columns>
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="Title" />
        <DxGridDataColumn FieldName="BirthDate" />
        <DxGridDataColumn FieldName="HireDate" />
    </Columns>
    <DataColumnCellDisplayTemplate>
        @{
            if (context.VisibleIndex % 2 == 1) {
                if (context.DataColumn.FieldName.Contains("Date")) {
                    <span class="my-date-style">@context.DisplayText</span>
                } else {
                    <span class="my-style">@context.DisplayText</span>
                }
            } else {
                <span>@context.DisplayText</span>
            }
        }
    </DataColumnCellDisplayTemplate>
</DxGrid>

@code {
    IEnumerable<Employee> Data { get; set; }
    NorthwindContext Northwind { get; set; }
    Employee CurrentEmployee { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        Data = Northwind.Employees
            .ToList();
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}

Blazor Grid Column Cell Display Template

See Also