Batchsave error

Hi, I am working on batchsave in datagrid and having a problem getting my head around the datamodel in the datagrid. 

1. In the attatched example I have 3 tabs, and if I edit and save data in tab 1 (toolbar "update" -  <GridEvents OnBatchSave="BatchSaveHandler" .. ), and change to tab 2, and back to tab 1, the data is not saved in the modeldata. Is it really nessary to reload the data again?

2. There seems to be a bug in the Update Datagrid, see the attached project:
System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Syncfusion.Blazor
  StackTrace:
   at Syncfusion.Blazor.Data.BlazorAdaptor.BatchUpdate(DataManager dataManager, Object changed, Object added, Object deleted, Utils e, String keyField, Nullable`1 dropIndex, Query query, Object original)
   at Syncfusion.Blazor.DataManager.<SaveChanges>d__158`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

  This exception was originally thrown at this call stack:
    Syncfusion.Blazor.Data.BlazorAdaptor.BatchUpdate(Syncfusion.Blazor.DataManager, object, object, object, Syncfusion.Blazor.Data.Utils, string, int?, Syncfusion.Blazor.Data.Query, object)
    Syncfusion.Blazor.DataManager.SaveChanges<T>(object, object, object, string, int?, string, Syncfusion.Blazor.Data.Query, object)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  


2. I have added a HeaderTemplate to each column, to add icons (I have removed the action from this example) but if I try to order columns via the ColumnChooser, the headers disappear. When is this bug fixed? 

Attachment: DataGrid_17af3920.zip

1 Reply 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team July 3, 2020 04:20 AM UTC

Hi Soren,  
 
Thanks for contacting Syncfusion support. 
 
Query: “ In the attatched example I have 3 tabs, and if I edit and save data in tab 1 and change to tab 2, and back to tab 1, the data is not saved in the modeldata. Is it really nessary to reload the data again? 
 
In the provided sample, datasource for Grid is not static. Hence the value is not updated properly and persisted while switching. By default while performing Edit operation Grid, changes will be reflected only in Grid. We need to manually save the changes into our database or datasource list. For your convenience we have prepared sample Batch handling and static list. Now the saved changes were reflected in Grid without any error.  
 
Refer the below code example.   
 
<SfGrid DataSource="@Orders" Width="100%" EnableAutoFill="true" ShowColumnChooser="true" Toolbar="ToolbaritemsString"> 
                        <GridSelectionSettings CellSelectionMode="CellSelectionMode.Box" Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell" 
                                               Type="SelectionType.Multiple"></GridSelectionSettings> 
                        <GridEditSettings AllowEditing="true" Mode="EditMode.Batch" ShowConfirmDialog="true"></GridEditSettings> 
                        <GridEvents OnBatchSave="BatchSaveHandler" TValue="Order"></GridEvents> 
  
                        <GridColumns> 
                            <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"> 
                                <HeaderTemplate> 
                                    <div> 
                                        OrderID 
                                        <span class="e-search-icon e-icons"></span> 
                                        <span class="e-SortAscending e-icons"></span> 
                                    </div> 
                                </HeaderTemplate> 
                            </GridColumn> 
 
</GridColumns> 
                    </SfGrid> 
 
 
 
@code{    public List<Order> Orders { getset; }     public List<Object> ToolbaritemsString = new List<Object>() { "Edit""Update""Cancel""ColumnChooser" };     protected override async Task OnInitializedAsync()    {        Orders = await OrderData.GetOrderData(); // to fetch the static list    }     public async Task BatchSaveHandler(BeforeBatchSaveArgs args)    {        try        {            var batchChanges = JsonConvert.DeserializeObject<Dictionary<stringobject>>(args.BatchChanges.ToString());             foreach (var change in batchChanges)            {                if (change.Key == "changedRecords")                {                    List<Order> value = JsonConvert.DeserializeObject<List<Order>>(change.Value.ToString());                    foreach (var val in value)                    {                        await OrderData.UpdateData(val); //update the changs in datasource list                    }                }            }        }        catch (Exception e)        {            Console.WriteLine(e.Message);            throw;        }     }
 
 
Note: from your code example we found that you have not enabled IsPrimaryKey property to any of the available columns whose value is unique. TO perform CRUD operation in Grid, PrimaryKey column must be defined whose value is unique. Based on primaryKey column values changes will be reflected in Grid.  
 
Kindly download the sample from below  
 
 
Refer our UG documentation for your reference 
 
 
Query: “f I try to order columns via the ColumnChooser, the headers disappear. When is this bug fixed?  
 
Since it is known issue, we have fixed the reported issue internally at our end. Fix for the issue will be included in our  2020 Volume 2 release which is expected to be rolled out by first week of July 2020. Till then we appreciate your patience.  
 
Kindly get back to us if you have further queries.   
 
Regards,
Vignesh Natarajan
 


Marked as answer
Loader.
Up arrow icon