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.

Examples

DisplayTemplate

Display template uses CellDisplayContext<TItem> as a context value, exposing the item, column, and display metadata for the cell.
Birth Date
8/26/1970 | Age: 56
5/25/1974 | Age: 52
4/29/1969 | Age: 57
2/12/1984 | Age: 42
11/6/1983 | Age: 43
10/2/1995 | Age: 31
3/15/1978 | Age: 48
7/1/1970 | Age: 56
6/24/1993 | Age: 33
9/18/1992 | Age: 34
<DataGrid TItem="Employee"
          Data="@employeeList"
          Responsive>
    <DataGridNumericColumn Field="@nameof( Employee.DateOfBirth )" Caption="Birth Date" Editable>
        <DisplayTemplate>
            @{
                var date = context.Item?.DateOfBirth;

                if ( date != null )
                {
                    @($"{date.Value.ToShortDateString()} | Age: {( DateTime.Now.Year - date.Value.Year )}")
                }
            }
        </DisplayTemplate>
    </DataGridNumericColumn>
</DataGrid>
@code {
    private readonly EmployeeData EmployeeData = new();
    private List<Employee> employeeList;


    protected override async Task OnInitializedAsync()
    {
        employeeList = await EmployeeData.GetDataAsync();
        await base.OnInitializedAsync();
    }
}

API

See the API reference for the parameters, events, methods, and related types available to the components covered on this page.

On this page