Update row values without changing view position

Hi Team,

We tried to update a row attributes when we get a server event and in out code the grid dataSource is binded with rowData values and the grid have pagination.
Every column is dynamic and each column call a component to render the cell. The component contains most of time pictures and color based on data value.
To update a row, we get the rowData index and update it's attributes like rowData[index] = newObjectValues;

With that, no change appear if the updated object is in the current page but if the object is in another page, it's correctly renderer if we go to this other page.
We tried to use grid.refresh() to have an update of the current view. It's work but we loose the current page position and the scrollbar go to the initial horizontal position.

1 - How can we update the current view renderer without changing anything of the position or the selected elements ?

2 - Is it possible to update a specific row renderer ?

Regards

5 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team June 22, 2020 11:38 AM UTC

Hi Mohamed, 

Greetings from Syncfusion support. 

We are not able to identify the exact requirement from your query. Do you wish to modify the data retrieved from server or dynamically update the row data? Can you please elaborate on your requirement so that we can check and provide the proper solution. Also from your query we suspect you are binding the data returned from the server directly to the Grid’s dataSource as local data. Can you confirm on this or let us know how you have bound data to the Grid. 

Let us know if you have any concerns. 

Regards, 
Sujith R 



MB Mohamed BENNOUR June 22, 2020 12:44 PM UTC

Hi Sujith,

We bind dataSource as rowData local data and columns as columnDefs local data (rowData and columnDefs are their names in our code).
Every row has a unique identifier in a column with aprimary key attribute
Every column has an ng-template using a custom componant.
After rendering the grid, the server sends a message to update a value of the row object.
We then modify the right row index  value from the rowData local value.

If this row is in another page then when we go to the page, the row renderer is good but if the row is in front of us, we don't see the change.

Regards


SK Sujith Kumar Rajkumar Syncfusion Team June 23, 2020 07:43 AM UTC

Hi Mohamed, 

Thanks for the information. 
 
From the provided information we could understand that your requirement is to dynamically update the row data. You can achieve this by using the Grid’s setRowData method as demonstrated in the below code snippet, 

// button click event handler 
onClick(args) { 
      var newData = Object.assign({}, this.gridObj.dataSource[2]); 
      newData.CustomerID = "BLONP"; 
      newData.Freight = 22 + (Math.random() * 100); 
      // this.gridObj.setRowData(primary key value, data to be updated) 
      this.gridObj.setRowData(10250, newData); 
} 
 

We have prepared a sample based on this for your reference which you can find below, 



Similarly you can also use the updateRow method to perform this operation. 

Please get back to us if you require any further assistance. 

Regards, 
Sujith R 


Marked as answer

MB Mohamed BENNOUR June 23, 2020 03:12 PM UTC

Hi Sujith,

That's it ! We've tried and it works as we expect.
Thanks a lot, your reply and the example that you provid are clear and fix our case.

Regards.


SK Sujith Kumar Rajkumar Syncfusion Team June 24, 2020 05:56 AM UTC

Hi Mohamed, 

We are glad to hear that. Please get back to us if you require any further assistance. 

Regards, 
Sujith R 


Loader.
Up arrow icon