Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxGrid.CustomizeCellDisplayText Event

Allows you to customize text displayed within a cell.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v25.1.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[Parameter]
public Action<GridCustomizeCellDisplayTextEventArgs> CustomizeCellDisplayText { get; set; }

#Parameters

Type Description
GridCustomizeCellDisplayTextEventArgs

A GridCustomizeCellDisplayTextEventArgs object that contains data for this event.

#Remarks

You can handle the CustomizeCellDisplayText event or use a column’s DisplayFormat property to customize a cell’s display text. On export, the event handler logic applies only if the ExportDisplayText option is enabled.

Use GridCustomizeCellDisplayTextEventArgs (Value, FieldName, etc.) to specify the display format and access other grid data.

If you implement DataColumnCellDisplayTemplate or CellDisplayTemplate, the CustomizeCellDisplayText event fires in the following cases only:

The following code snippet displays the Company Name values in the “Customer”:

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

<DxGrid Data="GridDataSource"
        CustomizeCellDisplayText="Grid_CustomizeCellDisplayText">
    <Columns>
        <DxGridDataColumn FieldName="OrderDate" DisplayFormat="d" />
        <DxGridDataColumn FieldName="Customer" />
        <DxGridDataColumn FieldName="ShipViaNavigation.CompanyName" />
        <DxGridDataColumn FieldName="Freight" DisplayFormat="n2" />
    </Columns>
</DxGrid>

@code {

    object GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    IEnumerable<Customer> CustomerList { get; set; }

    protected override void OnInitialized() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = Northwind.Orders
        .Include(i => i.Customer)
        .Include(i => i.OrderDetails)
        .Include(i => i.ShipViaNavigation)
        .ToList();
        CustomerList = Northwind.Customers;
    }

    void Grid_CustomizeCellDisplayText(GridCustomizeCellDisplayTextEventArgs e) {
        if (e.FieldName == "Customer") {
            e.DisplayText = CustomerList.Where(p => p.CustomerId == ((Customer)e.Value).CustomerId).FirstOrDefault().CompanyName;
        }
    }

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

DevExpress Blazor Grid - Customize Cell Display Text

Note

Columns bound to boolean fields automatically display checkboxes instead of text. As a result, the CustomizeCellDisplayText event does not fire. To use this event, set the column’s ShowCheckBoxInDisplayMode property to false.

See Also