how can I automatically refresh the grid?

Hi
I need the grid to recharge the data every 5 minutes because the data on the server changes every 5 minutes.
I tried to use the grid.refresh () method but it does not work:

var grid = document.getElementById("Grid").ej2_instances[0];
grid.refresh(); // refresh the Grid.

Can you help me?
Thanks in advance.
Barbara Inzitari

3 Replies

VA Venkatesh Ayothi Raman Syncfusion Team July 5, 2018 09:49 AM UTC


Hi Barbara, 

Thanks for using Syncfusion products. 

As from your query, we suspect that would like to update the data source when server updated. So, the grid Data manager will send the request to server side while calling the refresh method as you have used in your project for refresh the data source. But the corresponding post request will send to server side only if we bound the remote data source otherwise it won’t. 
For your requirement, we have created a sample which can be download from following link, 


In this sample, we have rendered the two buttons one for change the server-side data and another button to refresh the Grid in client side. Please refer to the following code example, 
<script> 
       //button click function for change the datasource in server side 
       function serverData() { 
           var ajax = new ej.base.Ajax("/Home/ServerDataChange", "POST", true); // call API  
           ajax.send(); 
 
       } 
        
       //button click function for change the datasource in client side 
       function clientData() { 
 
           var gridObj = document.getElementById("FlatGrid").ej2_instances[0]; 
           gridObj.refresh();//referesh the Grid data 
       } 
    </script> 
 
[Controller code] 
public void ServerDataChange() { 
            int code = 10; 
            List<OrdersDetails> listToAdd = new List<OrdersDetails>(); 
            listToAdd.Add(new OrdersDetails(code + 1, "ALFKI", 5, 2.3 , false, new DateTime(1991, 05, 15), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16), "Kirchgasse 6")); 
. .   . 
 
            OrdersDetails.GetAllRecords().AddRange(listToAdd); 
             
        } 

Note: If you are bound local data source to Grid then request won’t send to server side while calling the refresh method. Please refer to the above code example and sample for your reference.  

If you still face the same problem, then could you please share the following details? 
1)      Share the Grid code example. 
2)      Are you binding remote data or local data? 
3)      If you are using local data, then we should handle the process of refresh data using AJAX post. 

It would be helpful for us to find the problem and provide the better solution as earliest. 

Regards, 
Venkatesh Ayothiraman. 



NI nimue July 5, 2018 04:29 PM UTC

Hi Venkatesh 
Thank you so much for your answer
Yes, I actually needed to update the data in the grid after updates to the database.
And actually I did not understand that you had to bind the remote data origin to get this result.
I followed your instructions and the code example you sent me and now everything works perfectly
Thank you so much for your support
Barbara Inzitari


PS Pavithra Subramaniyam Syncfusion Team July 6, 2018 04:52 AM UTC

Hi Barbara, 
 
Thanks for your update. 
 
We are happy to hear that the provided information helps you. 
 
Please contact us if you have any queries. 
 
Regards, 
Pavithra S. 


Loader.
Up arrow icon