Populate pivot client datasource from Razor Page model

Hi,
I am trying to populate the pivotclient's datasource from a razor page model. I tried to convert the example to do this but I am stuck. Please help. See my attempt below:

/===============================================================
Index.cshtml

@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<ej-pivot-client id="PivotClient1" title="Relational Browser" load="onload">
    <e-data-source>
        <e-pivot-rows>
            <e-row-field field-name="Country" field-caption="Country"></e-row-field>
        </e-pivot-rows>
        <e-pivot-columns>
            <e-column-field field-name="Product" field-caption="Product"></e-column-field>
        </e-pivot-columns>
        <e-pivot-values>
            <e-value-field field-name="Amount" field-caption="Amount"></e-value-field>
        </e-pivot-values>
    </e-data-source>
</ej-pivot-client>

<script type="text/javascript">
    function onload(args) {
        args.model.dataSource.data = parseFromString(@Model.CubeData);
    }
/===============================================================
Index.cshtml.cs

    public class IndexModel : PageModel
    {
        public string CubeData { get; private set; } = string.Empty;

        public void OnGet()
        {
            CubeData = LoadData();
        }

        private string LoadData()
        {
            return "[{ Amount: 100, Country: \"Canada\", Date: \"FY 2005\", Product: \"Bike\", Quantity: 2, State: \"Alberta\" }]";
        }
    }
/===============================================================

1 Reply

SA Scintilla Arul Jothi Raj Syncfusion Team April 20, 2018 01:13 PM UTC

Hi Johan,   
  
Thanks for contacting Syncfusion Support.   
  
We have analyzed your query and suspect that the problem occurs in the conversion of string (datasource) returned from model. You can use @Html.Raw(@Model.CubeData) instead parseFromString(@Model.CubeData). Please refer the code snippet below.   
  
Code Snippet: [JavaScript]   
<script>   
    function onload(args) {   
        args.model.dataSource.data = @Html.Raw(@ModelCubeData);   
    }   
</script>   
   
  
Meanwhile, we have prepared a sample for your reference. Please find the sample in the below link.   
  
Regards,   
Scintilla A  

Loader.
Up arrow icon