Blazorise DataGrid: Display Template
Blazor includes templated components that can accept one or more UI segments as input and render them as part of the component during component rendering. DataGrid is a templated Blazor component that lets you customize various parts of the user interface with template parameters. It enables you to generate custom components or content using your own logic.
DisplayTemplate
Display template usesCellDisplayContext<TItem> as a context value, exposing the item, column, and display metadata for the cell.
<DataGrid TItem="Employee" Data="" Responsive> <DataGridNumericColumn Field="@nameof( Employee.DateOfBirth )" Caption="Date Of Birth" Editable> <DisplayTemplate> @{ var date = context.Item?.DateOfBirth; if ( date != null ) { @($"{date.Value.ToShortDateString()} | Age: {( DateTime.Now.Year - date.Value.Year )}") } } </DisplayTemplate> </DataGridNumericColumn> </DataGrid>
@code { [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
API
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.