How do your refresh / reload a pivot grid (data only) by using jquery / ajax

My Pivot Grid works fine on initial load - JSON, but I'm having trouble finding a way to reload the data or update the data source. I'm using MVC, not the SF JavaScript version.  I'm a little lost on what client side method are available to achieve this.


Thanks


4 Replies

SP Sastha Prathap Selvamoorthy Syncfusion Team June 30, 2017 07:30 AM UTC

Hi John, 
 
Thanks for contacting Syncfusion Support. 
 
refreshPivotGrid” method is available to refresh the PivotGrid with new updated data. We have provided a sample code to refresh the PivotGrid using button click event. Please find the code snippet for your reference below. 
 
Sample Code: 
@Html.EJ().Pivot().PivotGrid("PivotGrid1").ClientSideEvents(clientSideEvents => clientSideEvents.Load("onLoad")).DataSource(dataSource => dataSource.Rows(rows => { rows.FieldName("Country").FieldCaption("Country").Add(); }).Columns(columns => { columns.FieldName("Product").FieldCaption("Product").Add(); }).Values(values => { values.FieldName("Amount").Add(); })) 
 
@Html.EJ().Button("Button1").Size(ButtonSize.Normal).Text("Click").ClientSideEvents(events => events.Click("btnClick")) 
 
<script>  
    function btnClick(args) {  
              var pivotGridObj = $('#PivotGrid1').data("ejPivotGrid"); 
        $.ajax({  
            type: "POST",  
            url: "../GetData",  // specify the url to get JSON data 
            contentType: 'application/json; charset=utf-8',  
            dataType: 'json',  
            success: function (val) {  
               pivotGridObj.model.dataSource.data = JSON.parse(val); // you can set the JSON data here 
               pivotGridObj.refreshPivotGrid(); // method call to refresh the PivotGrid 
            },  
        });  
    }  
</script>  
 
Please let us know, if you need any further assistance. 
 
Regards, 
Sastha Prathap S.


JO John June 30, 2017 09:06 PM UTC

Thank you for the solution .... I was also trying refresh a pivot chart , I see refreshPivotChart isn't a method for that object, do you know the correct method for refreshing a pivot chart?

Thanks again.





JO John June 30, 2017 09:12 PM UTC

Figured it out by logging the methods to the console.

console.log(pivot);
   pivot.refreshControl();


thanks



SP Sastha Prathap Selvamoorthy Syncfusion Team July 3, 2017 05:46 AM UTC

Hi John, 
 
Thanks for the response. 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Sastha Prathap S. 


Loader.
Up arrow icon