Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 674
  • Last Modified:

kendo spreadsheet

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
Seven price
Asked:
Seven price
1 Solution
 
Scott Fell, EE MVEDeveloperCommented:
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
 
Seven priceFull StackAuthor Commented:
Sorry I thought I  closed this. I figured it out with the top 2 help thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now