DataGrid

This guide demonstrates how to use the DataGrid component.

DataGrid Properties

Name Type Default Description
TItem type null Item type.
Data array null DataGrid data.
Count integer null DataGrid number of all records.
PageSize integer 10 DataGrid number of records per page.
AllowPaging boolean false Is paging allowed.
AllowSorting boolean false Is sorting allowed.
AllowFiltering boolean false Is filtering allowed.
Visible boolean true Is DataGrid visible.
EmptyText string No records to display. DataGrid text on no records.
Columns array of GridColumn empty DataGrid columns.
Template string null DataGrid row details template.

DataGrid Events

Name Type Default Description
RowSelect event null Row select event of the DataGrid. Fired when row is selected. Row data as event arguments.
RowDoubleClick event null Row double click event of the DataGrid. Fired when row is double clicked. Row data as event arguments.
RowExpand event null Row expand event of the DataGrid. Fired when row is expanded. Row data as event arguments.
RowCollapse event null Row collapse event of the DataGrid. Fired when row is collapsed. Row data as event arguments.
LoadData event null Load data event of the DataGrid raised on page, sort and filter with info about the current page, page size, sorted columns and filter expressions

GridColumn Properties

Name Type Default Description
Type string string GridColumn type. string, integer, number or boolean.
Format string null GridColumn format. int32, int64, float, double, byte, binary, base64, date, date-time, date-time-offset or password.
Property string null GridColumn property name.
SortProperty string null GridColumn sort property name. If not set Property will be used for sorting.
FilterProperty string null GridColumn filter property name. If not set Property will be used for filtering.
Title string null GridColumn title.
Template string null GridColumn template.
Width number null GridColumn width in pixels.
Sortable boolean true Is sorting allowed for this column.
Filterable boolean true Is filtering allowed for this column.

Customizing the column appearance

By default the DataGrid component displays the value of the Property in a column. Use the Template property to customize the appearance. The whole data item is available as data in the expression.

Template examples:

  • <strong>${data.FirstName}</strong> - display the FirstName property in a <strong></strong> element.
  • <strong>@(data.FirstName)</strong> - display the FirstName property in a <strong></strong> element.
  • Full Name: ${data.FirstName} ${data.LastName} - display two data item properties in the column.
  • Full Name: @(data.FirstName) @(data.LastName) - display two data item properties in the column.

Important: The ${} syntax is specific to Radzen. If you are using the Radzen Blazor components outside of Radzen you have to use the @() syntax.

Blazor declaration

  <RadzenGrid AllowFiltering="true" AllowPaging="true" PageSize="4" AllowSorting="true" Data="@employees" TItem="Employee" ColumnWidth="200px">
    <Columns>
      <RadzenGridColumn TItem="Employee" Property="EmployeeID" Title="Employee ID" />
      <RadzenGridColumn TItem="Employee" Property="Photo" Title="Photo" Sortable="false" Filterable="false">
        <Template Context="data">
            <RadzenImage Path="@data?.Photo" />
        </Template>
      </RadzenGridColumn>
      <RadzenGridColumn TItem="Employee" Property="LastName" Title="Last Name"/>
      <RadzenGridColumn TItem="Employee" Property="FirstName" Title="First Name"/>
      <RadzenGridColumn TItem="Employee" Property="Title" Title="Title"/>
      <RadzenGridColumn TItem="Employee" Property="TitleOfCourtesy" Title="Title Of Courtesy"/>
      <RadzenGridColumn TItem="Employee" Property="BirthDate" Title="Birth Date" Format="date-time">
        <Template Context="data">
            @String.Format("{0:d}", data.BirthDate)
        </Template>
      </RadzenGridColumn>
      <RadzenGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" Format="date-time">
        <Template Context="data">
            @String.Format("{0:d}", data.HireDate)
        </Template>
      </RadzenGridColumn>
      <RadzenGridColumn TItem="Employee" Property="Address" Title="Address"/>
    </Columns>
  </RadzenGrid>

Server-side operations

  • DataGrid component can perform server-side sorting, paging and filtering when bound to IQueryable (default) or using LoadData event. When generating pages from database, Radzen will create automatically IQueryable service and will set Data property for the DataGrid component.

  • For paging with LoadData event enable paging, add LoadData event handler, call your service with provided information in the event argument and set Data and Count properties to returned values.

Sorting and Filtering by lookup fields

DataGrid component can sort and filter by lookup fields by defining SortProperty and FilterProperty for desired column. When generating pages from database, Radzen will set automatically SortProperty and FilterProperty for all lookup columns based on data-source relations.

We are here for you

Making our users happy is always a priority for us.