Blazorise DataGrid: Getting Started

The DataGrid component is used for displaying tabular data. Features include sorting, filtering, paging, inline editing, and row selection.

See DataGrid specifications for behavior details and edge cases.

To create a basic grid in Blazorise, define the columns that describe the grid structure and behavior.

  • <DataGrid> the main container
    • <DataGridColumns> container for datagrid columns
      • <DataGridColumn> column template for text editor
      • <DataGridNumericColumn> column template for numeric values
      • <DataGridDateColumn> column template for datetime values
      • <DataGridCheckColumn> column template for boolean values
      • <DataGridSelectColumn> column template for selectable values
      • <DataGridCommandColumn> column template for editing commands like Edit, Save, Cancel, etc.
    • <DataGridAggregates> container for datagrid aggregates
      • <DataGridAggregate> defines the column and aggregation function type

To use the DataGrid component, install the Blazorise.DataGrid package first.

Installation

NuGet

Install extension from NuGet.
dotnet add package Blazorise.DataGrid

Imports

In your main _Imports.razor add:
@using Blazorise.DataGrid

Usage

Every DataGrid example is presented as one self-contained Example.razor file. The model and sample data are included in its @code block, so the entire example can be copied into a configured Blazorise project at once.

Basic DataGrid

Bind the grid to an in-memory collection and define the columns that should be displayed.
#
First Name
Last Name
Email
Salary
1JohnDoejohn.doe@example.com80 000,00 €
2JaneDoejane.doe@example.com75 000,00 €
3DavidSmithdavid.smith@example.com100 000,00 €
@using System.Collections.Generic

<DataGrid TItem="Employee"
          Data="@employeeList"
          @bind-SelectedRow="@selectedEmployee"
          Responsive>
    <DataGridCommandColumn />
    <DataGridColumn Field="@nameof( Employee.Id )" Caption="#" Sortable="false" />
    <DataGridColumn Field="@nameof( Employee.FirstName )" Caption="First Name" Editable />
    <DataGridColumn Field="@nameof( Employee.LastName )" Caption="Last Name" Editable />
    <DataGridColumn Field="@nameof( Employee.Email )" Caption="Email" Editable />
    <DataGridColumn Field="@nameof( Employee.Salary )" Caption="Salary" DisplayFormat="{0:C}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo( "fr-FR" )" Editable>
        <EditTemplate>
            <NumericInput TValue="decimal" Value="@((decimal)context.CellValue)" ValueChanged="@(v => context.CellValue = v)" />
        </EditTemplate>
    </DataGridColumn>
</DataGrid>
@code {
    private readonly List<Employee> employeeList =
    [
        new() { Id = 1, FirstName = "John", LastName = "Doe", Email = "john.doe@example.com", Salary = 80000m },
        new() { Id = 2, FirstName = "Jane", LastName = "Doe", Email = "jane.doe@example.com", Salary = 75000m },
        new() { Id = 3, FirstName = "David", LastName = "Smith", Email = "david.smith@example.com", Salary = 100000m }
    ];

    private Employee selectedEmployee;

    private sealed class Employee
    {
        public int Id { get; set; }

        public string FirstName { get; set; } = string.Empty;

        public string LastName { get; set; } = string.Empty;

        public string Email { get; set; } = string.Empty;

        public decimal Salary { get; set; }
    }
}

DataGrid

For DataGrid the required fields are TItem typeparam and Data attribute. Other attributes on the DataGrid are optional.

Columns

Next you must set the Columns that you want to see in the grid. When defining the columns the required fields are:
  • TItem this is always the same model as on DataGrid. And you should be able to omit this on recent versions of Blazorise
  • Field name of the field in the supplied model. Caption the column caption text.

Nested fields

Field attribute also supports nested fields. You can define a column with field name like "City.Country.Name" and it will work. Just keep in mind that when editing nested fields they must be initialized first or otherwise they will raise an exception.

API

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

On this page