<EjsGrid @ref="Grid" DataSource="@GridData" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })" AllowFiltering="true" AllowSorting="true" AllowPaging="true">
<GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings>
<GridEvents OnActionBegin="OnBegin" TValue="Order"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsIdentity="true" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120">
<EditTemplate>
</EditTemplate>
</GridColumn>
</GridColumns>
</EjsGrid> |
<EjsGrid DataSource="@GridData" Toolbar="@(new string[] {"Add", "Edit" ,"Delete","Update","Cancel" })">
<GridEvents OnActionBegin="Begin" TValue="OrdersDetails"></GridEvents>
. . . . ..
</GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(OrdersDetails.OrderID) HeaderText="Order ID" IsIdentity="true" Visible="false" IsPrimaryKey="true" TextAlign="@TextAlign.Center" HeaderTextAlign="@TextAlign.Center" Width="140">
</GridColumn>
. .. . . . . . . . . . .
</GridColumns>
</EjsGrid> |
public async void OnBegin(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.EJ2.Blazor.Grids.Action.Save)
{
Args.Cancel = true; // prevent default action.
if (Args.Data.OrderID == null)
{
await Task.Run(() => OrderData.AddOrder(Args.Data));
}
else
{
OrderData.UpdateOrder(Args.Data);
}
Grid.CloseEdit(); // close the edit / insert dialog
}
} |