ASP.NET Core MVC Controls | ComponentOne
Working with Controls / FlexSheet / Work with FlexSheet / JSON Loading and Saving on Client-side
In This Topic
    JSON Loading and Saving on Client-side
    In This Topic

    FlexSheet supports Json loading and saving on the client side. You can easily load data from a json string in FlexSheet control, and even save the FlexSheet data in Json string. The control uses Workbook object model to accomplish this.

    The below code examples demonstrate how to use workbook object model to load Json string into FlexSheet control.

    JsonLoadController.cs 

    C#
    Copy Code
    public class JsonLoadController : Controller
    {
        public static List<Sale> SALES = Sale.GetData(15).ToList();
        // GET: Json
        public ActionResult JsonIndex()
        {
            return View(SALES);
        }
    }
    

    JsonLoading.cshtml

    HTML
    Copy Code
    <script>
        var flex, jsonString;
        c1.mvc.Utils.documentReady(function () {
            flex = wijmo.Control.getControl("#jsonLoadSheet");
        });
    
        function SaveToJson() {
            var workBook = flex.saveToWorkbookOM();
            jsonString = JSON.stringify(workBook);
    
        }
    
        function loadJSON() {
            var workBook = JSON.parse(jsonString);
            flex.loadFromWorkbookOM(workBook);
        }
    </script>
    
    <div>    
        <button class="btn btn-default" onclick="SaveToJson()">Save to Json</button>
        <button class="btn btn-default" onclick="loadJSON()">Load Json</button>
        <br /><br />
        <div>
            <c1-flex-sheet class="flexSheet" id="jsonLoadSheet" height="700px" width="700px">
                <c1-bound-sheet>
                    <c1-items-source source-collection="Model"></c1-items-source>
                </c1-bound-sheet>
            </c1-flex-sheet>
        </div>
    </div>
    

    Back to Top

    See Also