Solved

kendo spreadsheet

Posted on 2016-07-22
2
156 Views
Last Modified: 2016-07-26
I am using kendo spreadsheet and all my data is returning json values.
Question can i format the grid as far as rename headers or position my data where I want to. Not much info on how when it is dynamically coming from the server.
  $("#spreadsheet").kendoSpreadsheet({
      //          columns: 50,
      //          rows: 100,
      //          toolbar: true,
      //          sheetsbar: true,
      //          sheets: [{
      //              name: "Summary",
      //                    mergedCells: [
      //         // "A1:D1"  // Sheet Cell Placement , "C4:G4", "O4:R4", "A13:B13", "A16:B16"
      //                    ],
      //             rows: [{
      //          height: 30,
      //          cells: [{
      //            value: "label", background: "rgb(144,164,174)", textAlign: "center",
      //                      color: "white", fontSize: 18
      //          },
      //          ],
      //      }, 
      //      {
      //               index: 3,
      //               cells: [
      //                  {   index: 2, value: "Mean Total Returns(net)", fontSize: 15, textAlign: "center"}
      //                ],
                  
      //          },
      //        {
      //               index: 3,
      //               cells: [
      //                  {   index: 14, value: "Mean Asset Allocation", fontSize: 15, textAlign: "center"}
      //                ],
                  
      //        }],
                 
      //            dataSource:  dataSource, 
      //              columns: [
      //                  { width: 100 },
      //                  { width: 415 },
      //                  { width: 145 },
      //                  { width: 145 },
      //                  { width: 145 }
      //              ],
               
      //          }]
      //      });
           

Open in new window

0
Comment
Question by:sevensnake77
2 Comments
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 41725530
I have only looked at kendo but your data source is going to be generated jsonp

https://demos.telerik.com/kendo-ui/spreadsheet/datasource
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="styles/kendo.common.min.css" />
    <link rel="stylesheet" href="styles/kendo.default.min.css" />
    <link rel="stylesheet" href="styles/kendo.default.mobile.min.css" />

    <script src="js/jquery.min.js"></script>
    <script src="js/jszip.min.js"></script>
    <script src="js/kendo.all.min.js"></script>
</head>
<body>
<div id="example">
    <div class="box wide">
        <div class="box-col">
        <h4>Save data changes</h4>
        <ul class="options">
            <li>
                <button class="k-button" id="save">Save changes</button>
                <button class="k-button" id="cancel">Cancel changes</button>
            </li>
        </ul>
        </div>
    </div>

    <div id="spreadsheet" style="width: 100%"></div>
    <script>
        $(function() {
            var crudServiceBaseUrl = "//demos.telerik.com/kendo-ui/service";

            var dataSource = new kendo.data.DataSource({
                transport: {
                    read:  {
                        url: crudServiceBaseUrl + "/Products",
                        dataType: "jsonp"
                    },
                    update: {
                        url: crudServiceBaseUrl + "/Products/Update",
                        dataType: "jsonp"
                    },
                    destroy: {
                        url: crudServiceBaseUrl + "/Products/Destroy",
                        dataType: "jsonp"
                    },
                    create: {
                        url: crudServiceBaseUrl + "/Products/Create",
                        dataType: "jsonp"
                    },
                    parameterMap: function(options, operation) {
                        if (operation !== "read" && options.models) {
                            return {models: kendo.stringify(options.models)};
                        }
                    }
                },
                batch: true,
                change: function() {
                   $("#cancel, #save").toggleClass("k-state-disabled", !this.hasChanges());
                },
                schema: {
                    model: {
                        id: "ProductID",
                        fields: {
                            ProductID: { type: "number" },
                            ProductName: { type: "string" },
                            UnitPrice: { type: "number" },
                            Discontinued: { type: "boolean" },
                            UnitsInStock: { type: "number" }
                        }
                    }
                }
            });

            $("#spreadsheet").kendoSpreadsheet({
                columns: 20,
                rows: 100,
                toolbar: false,
                sheetsbar: false,
                sheets: [{
                    name: "Products",
                    dataSource: dataSource,
                    rows: [{
                        height: 40,
                        cells: [
                        {
                            bold: "true",
                            background: "#9c27b0",
                            textAlign: "center",
                            color: "white"
                        },{
                            bold: "true",
                            background: "#9c27b0",
                            textAlign: "center",
                            color: "white"
                        },{
                            bold: "true",
                            background: "#9c27b0",
                            textAlign: "center",
                            color: "white"
                        },{
                            bold: "true",
                            background: "#9c27b0",
                            textAlign: "center",
                            color: "white"
                        },{
                            bold: "true",
                            background: "#9c27b0",
                            textAlign: "center",
                            color: "white"
                        }]
                    }],
                    columns: [
                        { width: 100 },
                        { width: 415 },
                        { width: 145 },
                        { width: 145 },
                        { width: 145 }
                    ]
                }]
            });

            $("#save").click(function() {
                if (!$(this).hasClass("k-state-disabled")) {
                    dataSource.sync();
                }
            });

            $("#cancel").click(function() {
                if (!$(this).hasClass("k-state-disabled")) {
                    dataSource.cancelChanges();
                }
            });
        });
    </script>
</div>


</body>
</html>

Open in new window


Your processing page just needs to produce jsonp.  The example above is hard coded but you can generate the same rendered code through your server side code.

Where you see the datasource
var dataSource = new kendo.data.DataSource({
                transport: {
                    read:  {
                        url: crudServiceBaseUrl + "/Products",
                        dataType: "jsonp"
                    },
                    update: {
                        url: crudServiceBaseUrl + "/Products/Update",
                        dataType: "jsonp"
                    },
                    destroy: {
                        url: crudServiceBaseUrl + "/Products/Destroy",
                        dataType: "jsonp"
                    },
                    create: {
                        url: crudServiceBaseUrl + "/Products/Create",
                        dataType: "jsonp"
                    },
                    parameterMap: function(options, operation) {
                        if (operation !== "read" && options.models) {
                            return {models: kendo.stringify(options.models)};
                        }
                    }
                },

Open in new window

it is the urls like Products where you produce your dynamic content.

To pass variables, use jquery to past post/get and data
http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#methods-data
 data: [
    { name: "Jane Doe" },
    { name: "John Doe" }
  ]

Open in new window


They do have examples for .net https://demos.telerik.com/aspnet-mvc/spreadsheet/datasource

Your dynamic data comes from the processing page in that case
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 41730436
Sorry I thought I  closed this. I figured it out with the top 2 help thanks.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: Zack
Viewers will learn about using Excel in a browser with Excel Online.
Viewers will learn the basics of formula auditing in Excel 2013.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now