DxGridDataColumn.DisplayFormat Property
Specifies the format of column values and summary values calculated for this column.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(null)]
[Parameter]
public string DisplayFormat { get; set; }
Property Value
Type | Default | Description |
---|---|---|
String | null | The format string. |
Remarks
Use the DisplayFormat
property to format values displayed in column cells and summaries. For information about supported format strings, refer to the following topics:
Note
A summary’s ValueDisplayFormat property takes priority over the column’s DisplayFormat
.
The code snippet below applies the following formats:
- The short date format to the OrderDate field.
- The numeric format to the Freight field.
- The currency format to the ExtendedPrice field.
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource">
<Columns>
<DxGridDataColumn FieldName="OrderDate" DisplayFormat="d" />
<DxGridDataColumn FieldName="CustomerName" />
<DxGridDataColumn FieldName="Country" />
<DxGridDataColumn FieldName="Freight" DisplayFormat="n2" />
<DxGridDataColumn FieldName="ExtendedPrice" DisplayFormat="c" />
</Columns>
<TotalSummary>
<DxGridSummaryItem SummaryType="GridSummaryItemType.Avg" FieldName="ExtendedPrice" />
</TotalSummary>
</DxGrid>
@code {
object GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
protected override void OnInitialized() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = new GridDevExtremeDataSource<Invoice>(Northwind.Invoices);
}
public void Dispose() {
Northwind?.Dispose();
}
}
The DisplayFormat
property also accepts format strings with the {0} placeholder that replaces a column value. The format string syntax is below:
<custom text>{0:<format specifier>}<custom text>
- custom text - any plain text displayed before and after the column value.
- ‘{0}’ - the placeholder for the column value.
- format specifier - specifies the value format.
The following code shows possible format strings:
<DxGrid Data="GridDataSource">
<Columns>
@* ... *@
<DxGridDataColumn FieldName="ExtendedPrice" DisplayFormat="c" />
@* or *@
<DxGridDataColumn FieldName="ExtendedPrice" DisplayFormat="${0}" />
@* or *@
<DxGridDataColumn FieldName="ExtendedPrice" DisplayFormat="my custom text {0:c}" />
</Columns>
</DxGrid>