How to call update, delete methods in the grid.

I have a grid with batch edit mode. Currently when i make some changes and click update, it doesn't actually update and it stays green highlighted even after i click yes to save changes. I think something may have affected this. Also how do i override the methods so when i click update or delete etc. it will make certain calls to the database with the updated data. I attached my grid code.

               
                   
                   
                   
                   
                   
                   
                       
                       
                       
                           

                               
                                   
                                   
                                       
                                           
Address
                                       
                                       
                                           
@((context2 as FDILocationAddress).locationAddress)
                                       
                                   
                                   
                               


                           


                       


                       
                           
                                @{var currItem = (context as FDIChemicalOrderLine);

                                   
                                       
                                       
                                           
                                               
Item NumberSearch Name
                                           
                                           

                                               
@((context2 as FDIItemID).itemid)@((context2 as FDIItemID).NameAlias)
                                           
                                       
                                       

                                   

                                }
                           


                       



                       

                   
               

5 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team September 21, 2020 02:31 PM UTC

Hi Chris, 

Greetings from Syncfusion. 

Query: How to call update, delete methods in the grid. - I have a grid with batch edit mode. - how do i override the methods so when i click update the data 

We have validated your query and you want to save the edited data in batch edit mode using external method. You can achieve your requirement by using EndEdit method of the Grid. Here, we have save the edited data using EndEdit method in button click. Find the below code snippets for your reference. 

 
<button @onclick="Update">Update</button> 
 
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315"> 
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings> 
    <GridColumns> 
        . . . 
   </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<Order> Grid; 
    . . . 
   public void Update() 
    { 
        Grid.EndEdit(); 
    } 
} 

If it does not meet your requirement, then could you please share more information about your requirement. it will be helpful to validate and provide a better solution. 

  • Full Grid code snippets.
  • More detail about your requirement.
  • Syncfusion NuGet version details.

Regards, 
Rahul 



CJ chris johansson September 21, 2020 03:06 PM UTC

So what I want to do is call a method that these base menu options initialized by the grid call. The toolbar events. This is because when I click update or delete, I'm going to call the database to update each time etc.. Also for some reason before when I clicked update, it would change from highlighted green color to regular background but it is not doing this anymore so the base update is not working properly anymore and i'm not sure why.

18.2.0.58 sync fusion package. i created another ticket with my code attached.





   
                   
                   
                   
                   
                   
                   
                       
                       
                       
                           

                               
                                   
                                   
                                       
                                           
Address
                                       
                                       
                                           
@((context2 as FDILocationAddress).locationAddress)
                                       
                                   
                                   
                               


                           


                       


                       
                           
                                @{var currItem = (context as FDIChemicalOrderLine);

                                   
                                       
                                       
                                           
                                               
Item NumberSearch Name
                                           
                                           

                                               
@((context2 as FDIItemID).itemid)@((context2 as FDIItemID).NameAlias)
                                           
                                       
                                       

                                   

                                }
                           


                       

                       

                   
               



RN Rahul Narayanasamy Syncfusion Team September 23, 2020 12:43 PM UTC

Hi Chris, 
 
Thanks for the update. 
 
We have analyzed the provided code example and found that you have not defined the PrimaryKey column in Grid. To Perform CRUD action in Grid, IsPrimaryKey property must be defined to any one of the available column whose value is unique. Based on the primarykey value only changes will be saved in Grid. So we suggest you to define the IsPrimaryKey property to any one of the column whose value is unique. Refer our UG documentation for your reference  
  
 
To save the changes in Database using OnBatchSave event of the Grid. This event will be triggered when saving all the changes (as a whole) in Grid. In the event argument we can get the changes performed in Grid, like changed record, added record, deleted records etc. Using these value, you can update the changes in Database.  
  
Refer the below code example.   
  
<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add""Delete""Update""Cancel" })">  
    <GridEvents OnBatchSave="OnSave" TValue="Order"></GridEvents>  
    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch"></GridEditSettings>  
. . . . . .  
</SfGrid>  
   
@code{  
    public List<Order> Orders { getset; }  
    public void OnSave(BeforeBatchSaveArgs<Order> 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  
        }  
    }  
  
Refer our UG documentation for your reference  
  


Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer

CJ chris johansson September 23, 2020 03:19 PM UTC

awesome that worked thanks alot


RN Rahul Narayanasamy Syncfusion Team September 24, 2020 04:37 AM UTC

HI Chris, 
 
Thanks for the update. 
 
We are happy to hear that the provided solution was helpful to achieve your requirement. 
 
Please get back to us if you need further assistance. 
 
Regards, 
Rahul 
 


Loader.
Up arrow icon