Grid The selectedRows and datasource are not equal

For the record has been revised just now, when I choose it and to modify its value through the code, it results the value of SelectedRows, which is not the one in DataSource. However, no problem for the records haven’t been modified.

Operation steps:

1. Edit the record #10248 and complete

2. Choose #10248 and press “Update”

3. Then it results the value in DataSource, which conflicts with the one of the record selected.


https://stackblitz.com/edit/angular-8d9u2z?file=app.component.ts




1 Reply

AG Ajith Govarthan Syncfusion Team July 13, 2021 01:26 PM UTC

Hi techlandandyzhan, 
  
Thanks for contacting Syncfusion support. 
  
Query: For the record has been revised just now, when I choose it and to modify its value through the code, it results the value of SelectedRows, which is not the one in DataSource. However, no problem for the records haven’t been modified. 
  
Based on your attached sample we found that you have tried to update the values just by changing the values in the selected row data with button click event. By default, in our EJ2 Grid, we have edited feature and its public methods to update and refresh the data properly in our Grid application. 
  
So, we have prepared sample and, in that sample, we have used the updateRow method to modify the data in the button click event without moving into edit state for selected row and we have also used the actionBegin event to modify the data while saving the data with toolbar UI interactions.  
 
For your convenience we have attached the sample, please refer them for your reference. 
  
Code Example: 
App.component.ts 
  
rowSelected(args) { 
    this.selectedRowIndex = args.rowIndex; 
  } 
  
  click(args) { 
    var selectedRecords = this.grid.getSelectedRecords(); 
    if (selectedRecords.length && this.selectedRowIndex !== undefined) { 
      selectedRecords[0]['CustomerID'] = 'Value Changed'; 
      this.grid.updateRow(this.selectedRowIndex, selectedRecords[0]);  // changed with button click 
    } 
  } 
  
  actionBegin(args: any): void { 
    if (args.requestType === 'save') { 
      args.data['CustomerID'] = 'Value Changed'; // changed the data with actionBegin 
    } 
  } 
  
  
  
Please get back to us if you need further assistance. 
  
Regards, 
Ajith G. 


Loader.
Up arrow icon