<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch">GridEditSettings>
<GridEvents TValue="Order" OnToolbarClick="toolbarClick" OnBatchAdd="BeforeAdd">GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" ValidationRules="@(new ValidationRules { Required = true })" TextAlign="TextAlign.Right" Width="120">GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" ValidationRules="@(new ValidationRules { Required = true })" Width="120">GridColumn>
. . . . . . . . .
GridColumns>
SfGrid>
@code{
public List Orders { get; set; }
private bool PreventUpdate { get; set; }
public void BeforeAdd(BeforeBatchAddArgs<Order> args)
{
if (!PreventUpdate)
{
args.Cancel = true; // prevent the add operation
}
PreventUpdate = false;
}
public void toolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Text == "Add") // if toolbar as add then we set variable as true to perform add action
{
PreventUpdate = true;
}
}
}