Solved

kendo spreadsheet

Posted on 2016-07-22
2
258 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Initial get page response times and IIS8 15 51
jquery datatables, asp.net MVC 9 42
Switching Visual Studio 2015 to normal debug display 3 28
Scroll 5 news at a time. 4 29
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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn a basic relationship technique in Power Pivot for Excel 2013.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 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