We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Refresh grid data issue with getCurrentViewData

Hi Support

We have a button outside the grid that when is click do the following:


function Refresh()
{
   $.post('/Home/GetData',
                    {
                        start: $("#startDate").val(),
                        end :  $("#endDate").val(),
                    },
                    function (data, status) {
                        var gridObj = $("#grid").data("ejGrid");
                        gridObj.refreshContent(); 

                    }
                );

}

This invoke a method in the controller that updates an static collection.

Our issue is evident in this complete event handler of the grid:


        function complete()
        {
            var gridObj = $("#grid").ejGrid("instance");
            var data = gridObj.getCurrentViewData();    
         }


The issue is that the getCurrentViewData is returning the current data and not the latest server data.  But after the complete method ends, the grid shows the proper data.  But we need to have the latest data available inside the method to do data extractions to invoke a third party service.

Thanks in advanced


David 








4 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team February 6, 2017 12:12 PM UTC

Hi David, 
 
We are unable to reproduce any problem at our end. We have bound remote data to the Grid and refreshed the Grid content in the Ajax success event. Before refreshing the Grid, we have updated the records in the server end. The same changes has been the reflected in the model.currenteViewData of the Grid’s ActionComplete event. Refer to the following code example and screenshot. 
 
<ej-button id="button_button" click="Refresh" type="Button" text="click" /> 
<ej-grid id="grid" allow-paging="true" action-complete="onActionComplete"> 
    <e-datamanager url="/Home/AdrTypDataAll" adaptor="UrlAdaptor" /> 
          . . .  
                  . . . 
</ej-grid> 
 
<script> 
    function Refresh() { 
        //button click sent the POST for modification 
        $.ajax({ 
            type: "POST", 
            url: "/Home/GetData", 
            success: function (data) { 
                var gridObj = $("#grid").ejGrid("instance"); 
                //refreshed the Grid. 
                gridObj.refreshContent(); 
            }, 
        }); 
    } 
    function onActionComplete(args) { 
        var gridObj = $("#grid").ejGrid("instance"); 
        //Complete action shows the current set of Records with modification 
        console.log(gridObj.getCurrentViewData()[0].CustomerID); 
    } 
</script> 
 
        public ActionResult GetData()//POST method for Button Click 
        { 
            IEnumerable DataSource = order; 
            order[0].CustomerID = "VINET";//update the record manually 
            return Json("success"); 
        } 
 
 
 
We have also prepared a sample that can be downloaded from the following location. 
 
 
If you are still facing any problem, please share the following details to analyze the problem at our end. 
 
1)      Code example of the Grid and code behind 
2)      If possible, modify the attached sample and replicate the issue 
3)      Screenshot with replication procedure/video demo for the issue 
4)      Version of Essential Studio 
 
Regards, 
Seeni Sakthi Kumar S. 



DS dsapo February 6, 2017 04:37 PM UTC

Hi Seeni:

I tested your sample, but I did an small change to reproduce my problem:

 public ActionResult GetData()
        {
            IEnumerable DataSource = order;
            //  order[0].CustomerID = "VINET";

            var id = "YYYYY";
            order = order.Where(o => o.CustomerID == id).ToList();

            return Json("success");
        }


You will see that the grid shows the correct data, but the following line is not retrieving the correct data:

var data = gridObj.getCurrentViewData();    


Based on the customer Id "YYYYY" that I provided, the console.log should display an empty string, but instead is printing out the value of  ALFKI.

Best Regards,

David


DS dsapo replied to David Sapoznik February 7, 2017 04:11 PM UTC

Hi Seeni:

I tested your sample, but I did an small change to reproduce my problem:

 public ActionResult GetData()
        {
            IEnumerable DataSource = order;
            //  order[0].CustomerID = "VINET";

            var id = "YYYYY";
            order = order.Where(o => o.CustomerID == id).ToList();

            return Json("success");
        }


You will see that the grid shows the correct data, but the following line is not retrieving the correct data:

var data = gridObj.getCurrentViewData();    


Based on the customer Id "YYYYY" that I provided, the console.log should display an empty string, but instead is printing out the value of  ALFKI.

Best Regards,

David

Hi Seeni:

I think that the issue could be a minor issue in your api, because this property is retrieving the correct data:

var data = args.model.currentViewData;

But when you run this function, you dont get the latest data:

var gridObj = $("#grid").ejGrid("instance");
var data = gridObj.getCurrentViewData();


Remember that this issue is evident when there is no data in the datasource, so using the last function, you will get phantom data from the prior query.

Regards,

David







SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team February 13, 2017 12:51 PM UTC

Hi David,  
 
We have considered this as a bug, “getCurrentViewData is not updated after updating the empty dataSource” and fix for this issue will be included with the Volume 1 Service Pack 1, 2017.  
 
Regards, 
Seeni Sakthi Kumar S. 


Loader.
Up arrow icon