We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SetCellValue function doesn't add changes to batch changes

Hello syncfusion,

I used SetCellValue to set cell value programmatically, but if I add value not by using grid interface the applied changes do not appear in getBatchChanges.

Small context:

     Loaded grid can be edited. On every cell edit i'm looping through grids currentViewData and i'm using some logic while comparing currentViewData values. But there's the issue. If I edit cell by using grid interface, the changes are added to getBatchChanges() changedRecords, but it's not added in currentViewData. So in order to have newly edited data in currentViewData I tried to apply SetCellValue() function. By using this function new data appears in currentViewData but it doens't add it to batchChanges. 

Query: How to have cell changes either in currentViewData and in batchChanges assuming that I need to loop through edited data and save batchChanges to database later on

I've used demo example to reproduce behaviour:


5 Replies

PS Pavithra Subramaniyam Syncfusion Team January 23, 2019 05:11 AM UTC

Hi Domantas, 
 
Greetings from Syncfusion. 
 
Query: How to have cell changes either in currentViewData and in batchChanges assuming that I need to loop through edited data and save batchChanges to database later on 
 
We have analyzed your query and we suggest to use the updateCell method of the editModule to update the grid cells programmatically. By using this method you will be able to get the batch changes from getBatchChanges method for later update to the database since it acts as a actual batch cell edit. Using setCellValue method directly updates the cell value in the dataSource thus the changes will not be available in the getBatchChanges method but available in the currentViewData. Please refer to the below sample and documentation for your reference, 
 
Code Example:  
 
[.ts] 
... 
this.batchgrid.editModule.updateCell(0, "CustomerID", "test") 
... 
 
 
 
Please get back to us for further assistance. 
 
Regards,  
Pavithra S.   



DO Domantas January 23, 2019 07:29 AM UTC

Hello,

Thank you for your answer, but that did not quite answer my question.

You're suggesting me use one or another, but what I need is to have correct values in BOTH either in currentData and batchChanges.

Different uses gives data to different places but not in both:
1. If I use setCellValue() I get data in currentViewData but don't get it in getBatchChanges()
2. If I use editModule.updateCell() I get data in getBatchChanges() but I don't get data either in currentViewData or getCurrentViewRecords()

So the query is still the same

Query: How to have cell changes in both places: currentData for looping new data, and in batchChanges for database saving



PS Pavithra Subramaniyam Syncfusion Team January 24, 2019 05:49 AM UTC

 
Greetings from Syncfusion. 
 
Query: How to have cell changes in both places: currentData for looping new data, and in batchChanges for database saving 
 
We have analyzed your query and currentViewData is updated with new values only when the records are saved. So we suggest to use the dataBound event to get the currentViewData with new values and we have saved the batchChanges after updating the cell values. Please refer to the below sample for your reference, 
 
Code Example:  
 
[.ts] 
... 
 
  bound(args){ 
    console.log("changes", this.changes || "No changes"); 
    console.log("currentViewData", this.batchgrid.currentViewData); 
  } 
 
  public ngAfterViewInit(): void { 
    console.log("batchgrid", this.batchgrid) 
 
    setTimeout(i => { 
      this.batchgrid.editModule.updateCell(0, "CustomerID", "test") 
      this.changes = this.batchgrid.editModule.getBatchChanges(); 
    }, 1000) 
... 
 
 
 
Please get back to us for further assistance. 
  
Regards,  
Pavithra S 



DO Domantas January 24, 2019 08:56 AM UTC

Hello,

So from that what you've said, it is not possible to have the changes in batch change and in currentViewData without copying to another variable and updating. Alright. I could work with this, but this acts differently with remote data. 

Example: 
  1.      I'm adding removing or deleting in grid which is loaded with remote data.
  2.      I do copy down getBatchChanges() to variable in order to have them saved for later.
  3.      I have to execute batchSave() to add added/deleted/udpated records to currentViewData
  4.      When you execute batchSave() with remote data it executes http post with DataManager data url and batch changes as parameters to save.
  5.      For my example, that url is just for GET data, we save/update/delete with another button and another post url, so now when batchSave() calls our back-end with list DataManager url it just loads data again and we lose changes.
Query: How to not call url post on batchSave() but add edited data to currentViewData

I've prepared example from your demo with remote data loading. You can see in the example, that when I hit batchSave after updating the cell, the grid calls http post and tries to save them there, but it fails cause there is no such option. So not that it did not save data with link, but also it did not renew my currentViewData to work with.




PS Pavithra Subramaniyam Syncfusion Team January 25, 2019 08:33 AM UTC

Hi Domantas, 

Greetings from Syncfusion. 

Query: How to not call url post on batchSave() but add edited data to currentViewData 
 
We have analyzed your query and we suggest to use the getRowsObject method to get the current and changed records as per your requirement. In the below sample, after a cell is edited with a value, we have got the batch changes by using getBatchChanges method and we have created a variable to store the custom current view data from the getRowsObject method which has the updated cell values too. In the below work around we have not called the batchSave method, so the request will not be triggered until you do so. Please refer to the below sample for your reference, 

Code Example:  

[.ts] 
... 
setTimeout(i => { 
      var viewData = [];                        //a variable to store the currentView data with updated cells value 
 
      this.grid.editModule.updateCell(0, "CustomerID", "test");  
 
      for(let i=0; i<this.grid.getRowsObject().length; i++){ 
        if(this.grid.getRowsObject()[i].changes){ 
          viewData.push(this.grid.getRowsObject()[i].changes);           //changed cells value are pushed into the currentView data if any 
        } 
        else{ 
          viewData.push(this.grid.getRowsObject()[i].data);                 //non-changed cells value are pushed into the currentView data 
        } 
      } 
      console.log(this.grid.editModule.getBatchChanges()); 
      console.log(viewData); 
    }, 3000) 
 
... 
 
 
Please get back to us for further assistance. 
 
Regards, 
Pavithra S. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon