Call OnBatchSave on an another Method. Batch mode

Hi team,

I want to put the batch saving (detail) and saving of Master Entry in 1 method / customized button.

How can I call

Ex. OnBatchSave(BeforeBatchSaveArgs Args)

or args.BatchChanges.ChangedRecords in another method?


Razor

OnBatchSave="OnSaveDetail">


Code Block


public void OnSaveDetail(BeforeBatchSaveArgs Args)

{

var BatchChanges = Args.BatchChanges;

if (BatchChanges.AddedRecords.Count > 0)

{

//Insert data into your database

}

if (BatchChanges.ChangedRecords.Count > 0)

{

//update changes into your database

}

if (BatchChanges.DeletedRecords.Count > 0)

{

//delete record from your database

}

}



public void SaveRecord()

{

SaveHeader(); //for Master


OnSaveDetail (How can I pass the " BeforeBatchSaveArgs" here?); //For Detail

}




3 Replies

JP Jeevakanth Palaniappan Syncfusion Team July 7, 2021 05:54 AM UTC

Hi Tyrone, 

Greetings from Syncfusion support. 

We have checked your query and we would like to inform you that you cannot call the OnBatchSave event handler method directly but if you call the EndEdit method by using the corresponding grid reference then it will call the OnBatchSave event handler method. For your reference we have invoked the EndEdit method by using a button click which will call the OnBatchSave event handler(BatchSaveHandler method). Please refer the below code snippet and the sample for your reference. 

@using Syncfusion.Blazor.Grids 
 
<button @onclick="UpdateExternally">Update</button> 
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })"> 
    <GridEvents OnBatchSave="BatchSaveHandler" TValue="Order"></GridEvents> 
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Batch"></GridEditSettings> 
    <GridColumns> 
        .. 
   </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
 
    SfGrid<Order> Grid { get; set; } 
 
    public async Task UpdateExternally() 
    { 
        await Grid.EndEdit(); 
    } 
 
    public void BatchSaveHandler(BeforeBatchSaveArgs<Order> args) 
    { 
 
    } 
} 


Please refer the below documentation for more information. 


Regards, 
Jeevakanth SP. 



TY Tyrone July 8, 2021 05:03 PM UTC

Thanks a lot  Jeeva. It works now. 



JP Jeevakanth Palaniappan Syncfusion Team July 9, 2021 05:37 AM UTC

Hi Tyrone, 
 
You’re welcome and we glad that the provided solution resolved your problem. Please get back to us if you have any other queries. 
 
Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon