Reputation: 629
I am trying to implement a generic data grid that will work with whatever data I will send to the component. I am writing code in blazor and specifically using MudBlazor framework.
So I have an issue when I want to send a variable with DateTime I want to be displayed with the following format : 22 Nov 2012 and I dont want to send it as text since in a later stage I want to be able to sort the values based on Date.
How can I can different displayed and actual value here ?
<PropertyColumn Property="@column.PropertyExpression" Title="@column.Title" Filterable="@column.Filterable" Sortable="@column.Sortable" />
I am sending it like this :
new ColumnDefinition<TransferDetails>("Creation Date", x => x.IssueDate, typeof(DateTime), filterable: false),
and those are the ColumnDefinitions:
public string Title { get; set; }
public Expression<Func<TItem, object>> PropertyExpression { get; set; }
public Type PropertyType { get; set; }
public bool Filterable { get; set; }
public bool Sortable { get; set; }
public RenderFragment<MudBlazor.CellContext<TItem>> CellTemplate { get; set; }
public bool IsTemplateColumn => CellTemplate != null;
Upvotes: 0
Views: 528
Reputation: 2657
This is covered in the documentation
You can pass a format string in the Format parameter on PropertyColumn to format the value for the cells.
As an example, refer to the Hired
column
<PropertyColumn Property="x => x.HireDate" Title="Hired" Format="dd MMM yyyy"/>
Upvotes: 0