Articles in this section
Category / Section

How to pass PivotGrid report to PivotClient dynamically?

1 min read

This KB illustrates that how to pass PivotGrid report to PivotClient dynamically.

Solution:

You can pass OLAP report of PivotGrid to PivotClient dynamically through the following methods. You can work with the rendered PivotClient as usual. (like filtering, drilldown, save and load etc). 

Step 1:

Create a project for PivotGrid using any one of the below mentioned links.

JavaScript- https://help.syncfusion.com/js/pivotgrid/olap-getting-started#creating-a-simple-application-with-pivot-grid-and-olap-data-source-server-mode

ASP- https://help.syncfusion.com/aspnet/pivotclient/olap-getting-started#creating-a-simple-application-pivot-client-and-olap-data-sources-server-mode

MVC- https://help.syncfusion.com/aspnetmvc/pivotclient/olap-getting-started#creating-a-simple-application-with-pivotclient-and-olap-datasource-server-mode

Step 2:

Add a WebAPI controller (here, “OlapClientController.cs”) for PivotClient.

Step 3:

Add a button in the View page for passing Olap Report to PivotClient to render the same on button click. Please refer the below code snippet for View page.

JS

<div class="cols-sample-area" style=" width:100%;height:100%; position:absolute">
<button class="btn">Load PivotClient</button>
<div id="PivotGrid" style="width: 100%"></div>
<div id="PivotClient"></div>

 

MVC

<button class="btn">Load PivotClient</button>
@Html.EJ().Pivot().PivotGrid("PivotGrid").Url(Url.Content("~/api/OlapGrid"))
<div id="PivotClient"></div>

 

ASP

<button class="btn">Load PivotClient</button>
ej:PivotGrid ID="PivotGrid" runat="server" Locale="en-US" Url="../api/OlapGrid">
</ej:PivotGrid>
<div id="PivotClient"></div>

 

JS (Click event for all the platforms)

<script type="text/javascript">
 
  $(".btn").ejButton({click: "Apply"});
    $(function () {
       $("#PivotGrid").ejPivotGrid({ url: "OlapGrid", enableGroupingBar: true});
  });
 
  function Apply() {
    $(".e-pivotclient").remove();
    var gridPanel = ej.buildTag("div#PivotClient", "", {})[0].outerHTML;
    $(gridPanel).appendTo(".cols-sample-area");
    var controlObj= $("#PivotGrid").data("ejPivotGrid");
    var customObj = JSON.parse(controlObj.getOlapReport()).Report;
    $("#PivotClient").ejPivotClient({
           url: "OlapClient",
           customObject: { Report: customObj 
    });
  }                   
   
 

 

Step 4:

In “OlapClientController.cs”, we need to pass the report with “SetCurrentReport” method in the “InitializeClient” method.

[System.Web.Http.ActionName("InitializeClient")]
[System.Web.Http.HttpPost]
public Dictionary<string, object> InitializeClient(Dictionary<string, object> jsonResult)
 {
  OlapDataManager DataManager = null;
  dynamic customData = serializer.Deserialize<dynamic>(jsonResult["customObject"].ToString());
 
  //…
  DataManager.SetCurrentReport(OLAPUTILS.Utils.DeserializeOlapReport(customData["Report"]));
  //…
  return report;
 }     

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied