This example exercises local filtering, multi-sort, paging, selection, status dots, coloured rows and expandable details.
The same request contract is used by server-backed grids.
<BuiDataGrid @ref="grid" TItem="Customer" Items="customers" ItemKey="x => x.Id"
Selection="DataGridSelectionMode.Multiple" @bind-SelectedItems="selected"
@bind-Page="page" @bind-PageSize="pageSize" Striped Dense ExpandOnRowClick
RowColor="x => x.Overdue ? Palette.Rose : null">
<Columns>
<BuiDataGridColumn TItem="Customer" TValue="string" Field="x => x.Name" Truncate />
<BuiDataGridColumn TItem="Customer" TValue="CustomerStatus" Field="x => x.Status" CellColor="StatusColor" ColorMode="CellColorMode.Dot" />
<BuiDataGridColumn TItem="Customer" TValue="decimal" Field="x => x.Balance" Format="FormatCurrency" />
<BuiDataGridColumn TItem="Customer" TValue="DateTime" Field="x => x.Joined" Format="FormatDate" />
</Columns>
<ChildContent Context="customer"><BuiStack Gap="2" Class="demo-detail"><BuiText Typo="Typo.Subtitle2">@customer.Name</BuiText><BuiText Typo="Typo.Body2" Color="Colors.Secondary">Customer @customer.Id · @customer.Email</BuiText></BuiStack></ChildContent>
</BuiDataGrid>
@code {
private BuiDataGrid<Customer>? grid;
private int page = 1;
private int pageSize = 10;
private IReadOnlyCollection<Customer> selected = [];
private readonly Customer[] customers = Enumerable.Range(1, 42).Select(index => new Customer(index, $"Customer {index}", $"customer{index}@@example.com", index % 3 == 0 ? CustomerStatus.Pending : index % 5 == 0 ? CustomerStatus.Blocked : CustomerStatus.Active, index * 127.35m, DateTime.Today.AddDays(-index * 8), index % 7 == 0)).ToArray();
private static string FormatCurrency(decimal value) => value.ToString("C");
private static string FormatDate(DateTime value) => value.ToString("d MMM yyyy");
private static IColor StatusColor(Customer value) => value.Status switch { CustomerStatus.Active => Colors.Success, CustomerStatus.Pending => Colors.Warning, _ => Colors.Error };
private enum CustomerStatus { Active, Pending, Blocked }
private sealed record Customer(int Id, string Name, string Email, CustomerStatus Status, decimal Balance, DateTime Joined, bool Overdue);
}