0

I am using Pivot.js library/tool here. I am trying to load dynamic PIVOT table by taking parameters from the server. I am facing problem in PIVOT() method in second parameter which is optionsObj. When I pass static string to that parameter PIVOT grid is loading as expected but when I am passing it dynamically from the server PIVOT grid is not loading as per expectation.

PIVOT() method expects second parameter as an OBJECT.

NOTE : I hae tried JSON.stringify JSON.PARSE already. Response from the asynchronous call is coming properly from the method. I have debug the code.

<div>
            <script>
                var Json_ConfigData = new Object();
                $.ajax({
                    url: "Handlers/GET_Pivot_Config.ashx",                    
                    contentType: "application/text",
                    dataType: "text",
                    success: OnCompleteConfig,
                    error: OnFailConfig,
                });
                function OnCompleteConfig(data) {
                    Json_ConfigData = data;
                }
                function OnFailConfig(data) {
                    alert('FAil');                   
                }

                $.ajax({
                    url: "Handlers/GET_pivotDataSet.ashx",
                    contentType: "",
                    dataType: "json",
                    success: OnComplete,
                    error: OnFail,
                });

                function OnComplete(data) {                    
                    var JsonDataSet = data;                    
                    alert("CD : " + Json_ConfigData);
                    var utils = $.pivotUtilities;                    
                    var heatmap = utils.renderers["Heatmap"];
                    var SumasFractionofColumns = utils.aggregators["Sum as Fraction of Columns"];
                    var SumoverSum = utils.aggregators["Sum over Sum"];


                    var optionsObj = JSON.stringify(Json_ConfigData);
                    $("#output2").pivot(data,                            
                        optionsObj // { rows: ['MATERIAL_TYPE'] , cols: ['LOCATION_DESC'] , aggregator: SumasFractionofColumns(['WAITING_TIME']) , renderer: heatmap }
                        );
                }
                function OnFail(data) {
                    alert('Failed :- ' + data);
                }
            </script>
            <div id="output2" runat="server" style="margin: 30px;"></div>
</div>
Hardik Parmar
  • 1,053
  • 3
  • 15
  • 39
  • @Andreas Response from the aync call is working properly & data is coming proper from the response – Hardik Parmar Jan 20 '18 at 07:55
  • 1
    You should still have a look at [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call#14220323) – Andreas Jan 20 '18 at 07:57
  • I have looked at the article & i have also included one if condition for checking optionsObj parameter is filled or not. it is satisfying the condition & parameter is filled properly. – Hardik Parmar Jan 20 '18 at 08:05

1 Answers1

0

The problem is likely the line var optionsObj = JSON.stringify(Json_ConfigData); ... The output of JSON.stringify is a string, but this needs to be an object.

nicolaskruchten
  • 26,384
  • 8
  • 83
  • 101
  • I have changed it to object than also it is not working. I have created it as json object. I have tried everything can you please give me the idea how to achieve this. – Hardik Parmar Jan 22 '18 at 08:29