grid data is not refreshed

Dear Support,

The attached grid application is used by multiple users. The problem is that the Grid does not show fresh data from database. e.g. when user A edit a record, user B does see the changes. it has to Refresh the browser.

1) Can you provide a working modification on the attached grid sample in order to solve the problem?

2)on   public async Task Submit() is it possible to refactor the above code in order Not to load the huge amount of records from the database ?

  BeneficiaryObjects = await beneficiaryService.GetAllDataAsync(); //VERY LONG RUNNING TASK LOADING HUGE AMOUNT OF RECORDS!


thanks



Attachment: MyAppLearn_131377ec.zip

13 Replies

VN Vignesh Natarajan Syncfusion Team August 27, 2021 05:57 AM UTC

Hi DAN,  
 
Thanks for contacting Syncfusion support.  
 
Query: “The problem is that the Grid does not show fresh data from database. e.g. when user A edit a record, user B does see the changes. it has to Refresh the browser. 
 
We have analyzed your query and we would like to inform you that this is default behavior of Grid. Changes performed by user A will be reflected in user B only when browser or Grid component is refreshed. Because changes performed by one user cannot be auto detected unless configured for signalR.  
 
From the shared sample, we understand that application is not configured for SignalR. Hence changes performed by one user is not auto detected and refreshed in another user. Kindly refer the below documentation to configure the Blazor application for SignalR.  
 
 
Please get back to us if you have further queries.   
 
Regards, 
Vignesh Natarajan 



DA DAN replied to Vignesh Natarajan August 27, 2021 06:42 AM UTC

Hello,

1.can the observable collection help to some extend, as described in your article?

https://www.syncfusion.com/faq/blazor/data-binding/how-do-you-show-real-time-data-updates-using-observablecollection

if yes, can you please provide a modified working sample of the attached project with observable collection ?


2.can you also provide a modified working sample of the attached project blazor datagrid & signalr which you suggested?

thank you



VN Vignesh Natarajan Syncfusion Team August 30, 2021 10:20 AM UTC

Hi DAN,  
 
Query: “can the observable collection help to some extend, as described in your article? 
 
No. because Observable collection is used to reflect the external changes directly into the Grid without any external method. But requested query is different from this. So we suggest you to achieve your requirement using SignalR concept.  
 
Query:” can you also provide a modified working sample of the attached project blazor datagrid & signalr which you suggested? 
 
We have analyzed the provided sample and we found that, in the attached sample we are unable to load the data, since datasource is loaded from EF sql database. But we could not find the database in the attached sample. So kindly share the database file to load the data properly into Grid and implement the SignalR concept to achieve your requirementa.   
 
Based on your reply we will modify your sample and update you the sample.  
 
Regards, 
Vignesh Natarajan 



DA DAN August 30, 2021 01:11 PM UTC

hello,

you can use  update-database  in packagemanager console to create the database "ef code first"

the connection settings are inside appsettings.json

and database server is : (localdb)\\mssqllocaldb

i attach the database for your own reference. (it is just on table).

awaiting the signal r example .thank you


Attachment: myapplearn_9fe7aec.zip


VN Vignesh Natarajan Syncfusion Team August 31, 2021 09:42 AM UTC

Hi DAN,  

Thanks for sharing the requested details.  

Currently we are modifying your sample by integrating the SignalR concept. We need some more time to modify your sample. So we will update you the further details by 2nd September 2021.  

Till then we appreciate your patience.  

Regards, 
Vignesh Natarajan 



VN Vignesh Natarajan Syncfusion Team September 2, 2021 09:57 AM UTC

Hi Dan,  

Thanks for the patience.  

As per your request we have modified your sample to use SignalR concept. Kindly refer the below sample for your reference 


Note: In the provided sample we are able reflect the User A changes in User B without any external action while inserting and deleting a record.  

Refer the below general documentation for your reference 


Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan   



DA DAN September 3, 2021 09:38 AM UTC

Hello,

"delete" and new "adding data" is reflected to user B and working ok.

" Updating/editing" data is not reflected on user B and not working.

it is even not working when changing a page and going back . can you please recheck ?

thank you




VN Vignesh Natarajan Syncfusion Team September 6, 2021 09:02 AM UTC

Hi DAN,  
 
Sorry for the inconvenience caused.  
 
Query: “it is even not working when changing a page and going back . can you please recheck ? 
 
We have analyzed the reported issue and we found that the reported issue occur only in your sample. We have prepared a separate sample (with static list with external service) and ensured that reported issue is working fine at our end. Kindly refer the below sample for your reference (where update action is reflected properly in B user) 
 
 
We have analyzed the reported issue in your sample and we found that old data is returned from your service (BeneficiaryService) when Refresh request is made in LoadData() method of Grid.  So we request you to ensure at your end whether the changes are updated properly in your database and also ensure why the old data is returned from your beneficiary service while refreshing the updated data from service in LoadData() method.    
 
Regards, 
Vignesh Natarajan 



DA DAN September 6, 2021 10:07 AM UTC

Dear Vignesh,

1.the sample you provided above is not compiling.

2.regarding the very simple sample we attached ,I  don't see any problem with the UpdateBeneficiary & GetAllDataAsync Code in BeneficiaryService.

do you see anything that it must be changed in order to make it work ?


===see code below===

        public async Task<Beneficiary> UpdateBeneficiaryAsync(Beneficiary model)

        {

            var data = await db.Beneficiaries.Where(m => m.Id == model.Id).FirstOrDefaultAsync();

            if (data != null)

            {

                data.Id = model.Id;

                data.FirstName = model.FirstName.Trim();

                data.LastName = model.LastName.Trim();

                data.DocId = model.DocId;

                await db.SaveChangesAsync();

            }

            return data;

        }

        public async Task<List<Beneficiary>> GetAllDataAsync()

        {

            var result = await db.Beneficiaries.ToListAsync();

            return result;

        }





VN Vignesh Natarajan Syncfusion Team September 7, 2021 04:44 AM UTC

Hi DAN,  
 
Query: “the sample you provided above is not compiling. 
 
Sorry for the inconvenience caused. We have modified and updated the sample which can be downlaoded from below.  
 
 
In the previous attached sample. Data folder was removed. We have attached the correct sample and Changes performed in User A is automatically reflected in User B.  
 
Query: “regarding the very simple sample we attached ,I  don't see any problem with the UpdateBeneficiary & GetAllDataAsync Code in BeneficiaryService. 
 
We would like to inform you that SignalR concept works in following way. While page is initialized, HubConnection is stored and maintained in OnInitializedAsync life cycle event of Blazor. Once the CRUD operation is completed, we have called Send() method inside the ActionComplete event of Grid (in your sample OnSubmit) to indicate all the available clients using hub connection that changes has been made in current page. Then we have used On method of hub connection to trigger an event to perform some action for all the available clients. 
 
protected override async Task OnInitializedAsync() 
{ 
    hubConnection = new HubConnectionBuilder() 
        .WithUrl(NavigationManager.ToAbsoluteUri("/chathub")) 
        .Build(); 
  
    hubConnection.On("ReceiveMessage", () => 
    { 
        CallLoadData(); 
        StateHasChanged(); 
    }); 
  
    await hubConnection.StartAsync(); 
  
    BeneficiaryObjects = await beneficiaryService.GetAllDataAsync(); 
    StateHasChanged(); 
  
} 
  
private void CallLoadData() 
{ 
    Task.Run(async () => 
    { 
        await LoadData(); 
    }); 
  
} 
  
protected async Task LoadData() 
{ 
    BeneficiaryObjects = await beneficiaryService.GetAllDataAsync(); 
    await Task.Yield(); 
    await InvokeAsync(StateHasChanged); 
    GridnameBeneficiary.Refresh(); 
} 
 
 
Inside that event, we have called CallLoadData method to fetch the updated data from your service and refreshed the Grid component. In your sample, issue occur in the CallLoadData() method while fetching the updated data database. We can find the difference in datasource by placing a debugger in BeneficiaryObjects variable in LoadData method for different clients. This LoadData() method will triggered based on number of clients the page is opened.  
 
But we are not able to reproduce the reported issue at our end. Hence we have requested to ensure whether the data is updated properly in your database. Please get back to us if you have further queries.    
 
Regards, 
Vignesh Natarajan 



FB Fouche Burgers replied to Vignesh Natarajan May 1, 2022 06:25 AM UTC

Hi DAN, 


Not sure if you found the problem. If you EF Core, put your query in its own "using" the statement, for example:


   using (var context = new APPContext())

            {

                return await context.Beneficiary.ToListAsync();

            }





RN Rahul Narayanasamy Syncfusion Team May 5, 2022 02:00 PM UTC

Hi DAN,


Thanks for the update.


We are currently checking the reported query from our end and we will update the further details within two business days. Until then we appreciate your patience.


Regards,

Rahul



VN Vignesh Natarajan Syncfusion Team May 16, 2022 04:31 AM UTC

Hi Fouche Burgers,


Thanks for the update.


Please get back to us if you have any queries.


Regards,

Vignesh Natarajan


Loader.
Up arrow icon