when i add a new record automatically it save just one record

359 Views Asked by At

I have a syncfusion data grid , I want when I save a record automatically adds new record I wrote the code but it implement just one time then it adds a new record without save the previous record

this is my code:

<SfGrid @ref="Grid" DataSource="Orders" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })">
    <GridEvents OnActionComplete="OnActionComplete" TValue="Order"></GridEvents>
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal">     
    </GridEditSettings>
    <GridColumns>
        <GridColumn Field=@nameof(Order.id) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
        <GridColumn Field=@nameof(Order.Name) HeaderText="Customer Name" Width="120"></GridColumn>
        <GridColumn Field=@nameof(Order.country) HeaderText="Ship Country" Width="150"></GridColumn>
    </GridColumns>
</SfGrid>
@code{
    public SfGrid<Order> Grid { get; set; }
    public List<Order> Orders { get; set; }
    public class Order
    {
        public int id { get; set; }
        public string Name { get; set; }
        public string country { get; set; }
    }
    
    void OnActionComplete(ActionEventArgs<Order> args)
    {
        if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Save))
        {
            Grid.AddRecordAsync();
        }
    }
}
1

There are 1 best solutions below

0
On

We suspect that the reported issue occurs because the AddRecord method triggers before the previously added record is saved. So we suggest you to introduce the time delay before calling AddRecord method. Also we have declared the Orders as new List(). Kindly check the attached sample for your reference. If you face any difficulties then kindly get back to us.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp1-1302435764.zip