Blazorise DataGrid: Commands 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.
Command Templates
If you want to change the default command buttons, you can use following templates:
NewCommandTemplate
EditCommandTemplate
SaveCommandTemplate
CancelCommandTemplate
DeleteCommandTemplate
ClearFilterCommandTemplate
<DataGrid TItem="Employee" Data="" @bind-SelectedRow="" Editable Responsive> <DataGridCommandColumn> <NewCommandTemplate> <Button Color="Color.Success" Clicked="@context.Clicked">New</Button> </NewCommandTemplate> <EditCommandTemplate> <Button Color="Color.Primary" Clicked="@context.Clicked">Edit</Button> </EditCommandTemplate> </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> <NumericEdit TValue="decimal" Value="@((decimal)context.CellValue)" ValueChanged="@( v => context.CellValue = v)" /> </EditTemplate> </DataGridColumn> </DataGrid>
@code{ [Inject] public EmployeeData EmployeeData { get; set; } private List<Employee> employeeList; private Employee selectedEmployee; protected override async Task OnInitializedAsync() { employeeList = await EmployeeData.GetDataAsync(); await base.OnInitializedAsync(); } }
API
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.