Load Blazor DataGrid data on demand with the LoadData event - the grid passes you the current page, sort, and filter so you can fetch rows from a web API, stored procedure, or any custom data source and return just that page.
ID | Photo | First Name | Last Name | Job Title | Title | Birth Date | Hire Date | Address | City | Region | Postal Code | Country | Home Phone | Extension | Notes |
|---|
1. Set the Data and Count properties.
<RadzenDataGrid Count="@count" Data="@employees"
2. Handle the LoadData event and update the Data and Count backing fields (employees and count in this case).
void LoadData(LoadDataArgs args)
{
var query = dbContext.Employees.AsQueryable();
if (!string.IsNullOrEmpty(args.Filter))
{
query = query.Where(grid.ColumnsCollection);
}
if (!string.IsNullOrEmpty(args.OrderBy))
{
query = query.OrderBy(args.OrderBy);
}
count = query.Count();
employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
}
Use LoadData when the data comes from a web API or any source you query yourself - the grid passes you the current page, sort, and filter, and you return that page plus the total count.
With IQueryable, such as Entity Framework, the grid builds and runs the query for you. With LoadData you run the query yourself and return the page, which suits REST APIs and custom back ends.
Radzen Blazor Components, © 2018-2026 Radzen.
Source Code licensed under
MIT