ASP.NET MVC Controls | ComponentOne
Working with Controls / OLAP / Work with OLAP / Save and Load View
In This Topic
    Save and Load View
    In This Topic

    The following code examples demonstrate how export save and load the view of an OLAP control. This example uses the sample created in the Quick Start topic.

    In Code (Index.cshtml)

    Razor
    Copy Code
    @using OlapSample.Models;
    @model IEnumerable<ProductData>
    <br />
    @(Html.C1().PivotEngine().Id("indexEngine").Bind(Model)
        .RowFields(pfcb => pfcb.Items("Country"))
        .ColumnFields(cfcb => cfcb.Items("Product"))
        .ValueFields(vfcb => vfcb.Items("Sales")))
    @Html.C1().PivotPanel().ItemsSourceId("indexEngine")
    @Html.C1().PivotChart().ItemsSourceId("indexEngine")
    @Html.C1().PivotGrid().Id("indexGrid").ItemsSourceId("indexEngine")
    
    <button type="button" class="btn btn-default" onclick="saveView()">Save View</button><br />
    <button type="button" class="btn btn-default" onclick="loadView()">Load View</button><br />@section Scripts{
        <script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
        <script type="text/javascript">
            function saveView() {
                var ng = c1.getService('indexEngine');
                if (ng && ng.isViewDefined) {
                    localStorage.viewDefinition = ng.viewDefinition;
                }
            }
            function loadView() {
                var ng = c1.getService('indexEngine');
                if (ng && localStorage.viewDefinition) {
                    ng.viewDefinition = localStorage.viewDefinition;
                    var cmbRowTotals = wijmo.Control.getControl('#RowTotals');
                    if (cmbRowTotals) {
                        cmbRowTotals.selectedValue = ng.showRowTotals;
                    }
    
                    var cmbColTotals = wijmo.Control.getControl('#ColTotals');
                    if (cmbColTotals) {
                        cmbColTotals.selectedValue = ng.showColumnTotals;
                    }
    
                    var chkShowZeros = document.getElementById('ColTotals');
                    if (chkShowZeros) {
                        chkShowZeros.checked = ng.showZeros;
                    }
                }
            }
        </script>
    }