Added recored still remains 0 id after update of datasource.

Hi team,

Here is my datasource


<SfGrid DataSource="@SODetailsEdit"

      @ref="GridDetail"

        ID="GridDetail"

        TValue="SODetailEdit"

        Toolbar="@(new List<string>() { "Add", "Delete" })"

        >


and here is my code block upon BeforeBatchSaveArgs or GridDetail.EndEdit();


  SODetails = (await SODetailService.GetBySOHeaderID(int.Parse(ID))).ToList();

  SODetailsEdit.Clear();

  if (SODetails != null)

            {

                // Details

                SODetailsEdit = SODetails.Select(e => new SODetailEdit

                {

                    SODetailID = e.SODetailID,

                    SOHeaderID = e.SOHeaderID,

                    SONo = e.SONo,

                    ItemID = e.ItemID,

                    ItemCode = e.ItemCode,

                    Description = "",

                    WarehouseID = e.WarehouseID,

                    Quantity = e.Quantity,

                    UnitCost = e.UnitCost,

                    TotalCost = e.TotalCost,

                }).ToList();


            }


            StateHasChanged();


Added records id's default is 0 and then gets it corresponding from id from EFCore after saving. My problem is, added record still remains after the update of datasource.

Untitled.png

  

as you can see, id with 0 still remains. it should not already part of datasource..  It should be already coming from saved autonumberID. 


there is no saved record with 0 id. 

Hope you could help me regarding this matter. regards. 


Tyrone


5 Replies

VN Vignesh Natarajan Syncfusion Team July 28, 2021 11:40 AM UTC

Hi Tyrone,  
 
Thanks for contacting Syncfusion support.  
 
Query: “ My problem is, added record still remains after the update of datasource. 
 
We have analyzed your query and we understand that you are facing issue after inserting the record into your database. We also understand that you are updating the batch changes into you database using OnBatchSave event of Grid. We have prepared the sample as per your suggestion and we are not able to reproduce the reported issue at our end.  
 
We suspect that the issue occur after updating the changes into database and updating the Grid datasource. So we request you to ensure the reported issue by calling the Grid.Refresh(), after updating the Grid DataSource’s property with updated value. 
 
Refer the below code example.  
 
public void OnBatchSave(BeforeBatchSaveArgs<Order> Args) 
  { 
      foreach (var ord in Args.BatchChanges.AddedRecords) 
      { 
          Orders.Add(ord); 
      } 
      GridData.Clear(); 
      GridData = Orders; 
      //After updating the Grid datasource property. Refresh the grid to fetch the updated datasource.  
      Grid.Refresh(); 
  } 
   
If you are still facing the reported issue, kindly get back to us with following details.  
 
  1. Share the entire Grid code example.
  2. Also share the details on how you updating the changes in your database.
  3. Share your Syncfusion.Blazor NuGet package version details.
  4. Share simple issue reproducible sample.
 
Above requested details will be very helpful in validating the requested feature at our end and provide solution as early as possible.  
 
Regards, 
Vignesh Natarajan 



TY Tyrone July 28, 2021 04:48 PM UTC

Hi  Vignesh,


I'm still getting the same problem..


please see attached file for my razor and code base.. 


warm regards,


Tyrone


Attachment: TransInv_f4516e4c.rar


VN Vignesh Natarajan Syncfusion Team July 29, 2021 07:23 AM UTC

Hi Tyrone,  
 
Thanks for sharing the requested details.  
 
Query: “I'm still getting the same problem.. please see attached file for my razor and code base..  
 
We have analyzed the provided code example and found that you have updated the Grid datasource with updated details in the OnBatchSave event of Grid. OnBatchSave event will be called when changes are being saved in the Grid component. Hence the reported might have occur when there is some delay in updating the batch changes along with datasource property changes.   
 
We request you to resolve the reported issue by updating the Grid datasource property in OnActionComplete event of Grid when Request Type is BatchSave. OnActionComplete event will be triggered when certain action gets completed in Grid. This event will be triggered with RequestType as BatchSave, once batch changes gets updated in Grid.  
 
So here we request you fetch the updated data from your database and update in grid datasource property. Refer the below code example. 
 
<SfGrid @ref="Grid" DataSource="@GridData" AllowPaging="true" Toolbar="@(new List<string>() { "Add""Delete""Update""Cancel" })" Height="315">    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>    <GridEvents OnBatchSave="OnBatchSave" OnActionComplete="Complete" TValue="Order"></GridEvents>. . . . . . </SfGrid> @code{    SfGrid<Order> Grid { getset; }            public void save()    {        Grid.EndEditAsync();    }     public void Complete(ActionEventArgs<Order> Args)    {        if (Args.RequestType == Syncfusion.Blazor.Grids.Action.BatchSave)        {            //update the grid datasourve property here instead of updating in OnBatchSave        }            }
 
Refer the below UG documentation for your reference 
 
 
Please get back to us if you have further queries.  
 
Regards,
Vignesh Natarajan
 



TY Tyrone September 18, 2021 09:56 AM UTC

Thanks Vignesh Natarajan . It worked. 



VN Vignesh Natarajan Syncfusion Team September 20, 2021 04:04 AM UTC

Hi Tyrone,  

Thanks for the update.  

We are glad to hear that you have resolved your query using our solution.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 


Loader.
Up arrow icon