DataGrid not refreshing when Datasource changes

We are having problems with the DataGrid component. We use our own DataSource, which is a list of objects and we manage CRUD operations ourselves.
We have a ContextMenu in the DataGrid which allows a delete operation. On ContextMenuItemClicked, we remove the item from the DataSource, but the DataGrid is not updated.
Calling  SfGrid.Refresh() or StateHasChanged() doesn't seem to do anything.

How can we have the DataGrid automatically refresh when the DataSource is modified?

You can find a sample project attached. Just try right clicking a row on the grid and select delete, the Grid is not updated.

Attachment: GridRefresh_f885ae62.zip

3 Replies

RS Renjith Singh Rajendran Syncfusion Team April 29, 2020 07:05 AM UTC

Hi Davy, 

Thanks for contacting Syncfusion support. 

We suggest you to return the Clients as List after performing filter in Clients to remove the particular row data. Please add the below highlighted code in your application to overcome the problem you are facing. 

 
    public void OnConfirmDeleteClick(object args) 
    { 
        if (SelectedClientId > 0) 
        {  
            //remove deleted client from list 
            Clients = Clients.Where(x => x.Id != SelectedClientId).ToList(); 
            ... 
       } 
        ... 
    } 


And also based on your requirement, we suggest you the below documentations. If you want the dynamic changes to be updated in Grid without calling Refresh method, then you can bind data to Grid as ObservableCollection. Please refer the documentation and online sample demos showing CRUD operation with ObservableCollection as data in Grid.  

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



DA Davy May 5, 2020 07:50 AM UTC

Thanks for the explanation. I didn't know about the observable collection, I will start using it now.


RS Renjith Singh Rajendran Syncfusion Team May 6, 2020 04:51 AM UTC

Hi Davy, 

Thanks for your update. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 


Loader.
Up arrow icon