Articles in this section
Category / Section

How to render PivotGrid using custom JSON data?

2 mins read

This KB illustrates that how to render PivotGrid using custom JSON data.

Solution:

The PivotGrid control normally gets rendered through the JSON data returned from WCF service after processing the report. You can also render the PivotGrid control by directly binding the custom JSON data structured in a format that is acceptable by PivotGrid.

WCF

public Dictionary<string, object> InitializeGrid(string action)
        {
            string[] index = { "0,0", "0,1", "0,2", "0,3", "0,4", "0,5", "1,0", "1,1", "1,2", "1,3", "1,4", "1,5"};
            string[] css = { "none", "rowheader", "rowheader", "rowheader", "rowheader", "summary", "colheader", "value", "value", "value", "value", "summary value" };
            string[] value = { "", "FY 2002", "FY 2003", "FY 2004", "FY 2005", "Total", "Internet Sales Amount", "$7,072,084.24", "$5,762,134.30", "$16,473,618.05", "$50,840.63", "$29,358,677.22" };
            string[] info = { "", "[Date].[Fiscal].[Fiscal Year].&[2002];[Date].[Fiscal].[Fiscal Year];FY 2002;[Date].[Fiscal].[All Periods];System.Linq.Enumerable+WhereSelectEnumerableIterator`2[<>f__AnonymousType2`2[Syncfusion.Olap.Data.Tuple,Syncfusion.Olap.Data.Member],System.String];1", "[Date].[Fiscal].[Fiscal Year].&[2003];[Date].[Fiscal].[Fiscal Year];FY 2003;[Date].[Fiscal].[All Periods];System.Linq.Enumerable+WhereSelectEnumerableIterator`2[<>f__AnonymousType2`2[Syncfusion.Olap.Data.Tuple,Syncfusion.Olap.Data.Member],System.String];1", "[Date].[Fiscal].[Fiscal Year].&[2004];[Date].[Fiscal].[Fiscal Year];FY 2004;[Date].[Fiscal].[All Periods];System.Linq.Enumerable+WhereSelectEnumerableIterator`2[<>f__AnonymousType2`2[Syncfusion.Olap.Data.Tuple,Syncfusion.Olap.Data.Member],System.String];1",
              "[Date].[Fiscal].[Fiscal Year].&[2005];[Date].[Fiscal].[Fiscal Year];FY 2005;[Date].[Fiscal].[All Periods];System.Linq.Enumerable+WhereSelectEnumerableIterator`2[<>f__AnonymousType2`2[Syncfusion.Olap.Data.Tuple,Syncfusion.Olap.Data.Member],System.String];1", "Date].[Fiscal].[All Periods];[Date].[Fiscal];All Periods;;System.Linq.Enumerable+WhereSelectEnumerableIterator`2[<>f__AnonymousType2`2[Syncfusion.Olap.Data.Tuple,Syncfusion.Olap.Data.Member],System.String];1", "[Measures].[Internet Sales Amount];[Measures].[MeasuresLevel];Internet Sales Amount;;System.Linq.Enumerable+WhereSelectEnumerableIterator`2[<>f__AnonymousType2`2[Syncfusion.Olap.Data.Tuple,Syncfusion.Olap.Data.Member],System.String];1", "", "", "", "", ""};
            ExpandableState[] state = { ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None, ExpandableState.None,ExpandableState.None };
            int[] rowspan = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            int[] colspan = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
            string[] span = { "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None" };
            List<object> pivotEngineRecords = new List<object>();
            for (int i = 0; i < index.Length; i++)
            {
                pivotEngineRecords.Add(new { Index= index[i], CSS= css[i], Value= value[i], Info= info[i], State= state[i], RowSpan= rowspan[i], ColSpan= colspan[i], Span= span[i] });
            }
            string jsonData = serializer.Serialize(pivotEngineRecords);
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("jsonData", jsonData);
            dic.Add("report", "");
            return (dic);
        }

 

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