How to check if grid has changes with JS / jQuery

Hello,


Is there a way to programatically check with JS / jQuery if the grid data has been changed? I want to call batchSave() externally only when there are changes. batchEdit is enabled


3 Replies

RS Rajapandiyan Settu Syncfusion Team August 4, 2021 02:15 PM UTC

Hi Andrew, 
  
Thanks for contacting Syncfusion support. 

Query: Is there a way to programatically check with JS / jQuery if the grid data has been changed? I want to call batchSave() externally only when there are changes. batchEdit is enabled 

You can achieve your requirement by using getBatchChanges() method of Grid which returns the currently edited records details of batch edit. Based on returned value, you can execute the batchSave method if any changes applied in the Grid. 




<script> 
 
    function btnClick(args) { 
        var grid = document.getElementById('Grid').ej2_instances[0]; 
        // get the batch changed records  
        var batchChanges = grid.getBatchChanges(); 
        if (batchChanges.addedRecords.length > 0 || batchChanges.deletedRecords.length > 0 || batchChanges.changedRecords.length > 0) { 
            // execute the batchSave method if any changes applied in Grid 
            grid.editModule.batchSave() 
        } 
    } 
 
</script> 


Please get back to us if you need further assistance with this. 
  
Regards,  
Rajapandiyan S 



AN Andrew August 15, 2021 05:24 PM UTC

Hi  Rajapandiyan,


Worked perfectly!



Thanks!



TS Thiyagu Subramani Syncfusion Team August 16, 2021 07:36 AM UTC

Hi Andrew, 

Thanks for the update. 

We are happy to hear that the provided solution works at your end.  

Please get back to us if you need further assistance. 

Regards, 
Thiyagu S 


Loader.
Up arrow icon