Odata Grid Batch Editing

5 posts, 1 answers
  1. Griffin
    Griffin avatar
    5 posts
    Member since:
    Jul 2009

    Posted 02 Aug 2012 Link to this post

    Hi,

    I'm trying to enable batch editing for a grid bound to an odata data source but having trouble using ParameterMap function to properly format a request.

    I started from this example (https://github.com/telerik/kendo-examples-asp-net/tree/master/grid-odata-crud) and my code looks like this:
    <html>
        <head>
            <meta charset="utf-8" />
            <title>OData CRUD</title>
            <link href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css" rel="stylesheet" />
            <link href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.default.min.css" rel="stylesheet" />
            <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
            <script src="http://cdn.kendostatic.com/2012.1.322/js/kendo.all.min.js"></script>
        </head>
        <body>
            <div id="grid"></div>
            <script>
                $(document).ready(function () {
                    var crudServiceBaseUrl = "/Northwind.svc/Products",
                        dataSource = new kendo.data.DataSource({
                            type: "odata",
                            transport: {
                                read: {
                                    url: crudServiceBaseUrl,
                                    dataType: "json"
                                },
                                update: {
                                    url: function(data) {
                                        return crudServiceBaseUrl + "(" + data.ProductID + ")";
                                    }
                                },
                                create: {
                                    url: crudServiceBaseUrl
                                },
                                destroy: {
                                    url: function(data) {
                                        return crudServiceBaseUrl + "(" + data.ProductID + ")";
                                    }
                                },
                                parameterMap: function (data, operation) {
                                    if (operation !== "read" && data.models) {
                                        //return { items: kendo.stringify(data.models) };
                                        return { data: kendo.stringify(data.models) };
                                    }
                                }
                            },
                            batch: true,
                            pageSize: 10,
                            serverPaging: true,
                            schema: {
                                data: "d",
                                model: {
                                    id: "ProductID",
                                    fields: {
                                        ProductID: { editable: false, nullable: true },
                                        ProductName: { validation: { required: true } },
                                        UnitPrice: { type: "number", validation: { required: true, min: 1} },
                                        Discontinued: { type: "boolean" },
                                        UnitsInStock: { type: "number", validation: { min: 0, required: true } }
                                    }
                                }
                            }
                        });
     
                        $("#grid").kendoGrid({
                            dataSource: dataSource,
                            height: 400,
                            pageable: true,
                            editable: true,
                            toolbar: ["create", "save", "cancel"],
                            columns: [                          
                                "ProductName",
                                { field: "UnitPrice", format: "{0:c}", width: "150px" },
                                { field: "UnitsInStock", width: "150px" },
                                { field: "Discontinued", width: "100px" },
                                { command: ["destroy"], title: " ", width: "110px" }]
                        });
                });
            </script>
        </body>
    </html>


    I've attached a demo project that includes my web service.

    Thanks,
    Griffin
  2. Answer
    Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 03 Aug 2012 Link to this post

    Hello Griffin,

    There few thinks that you need to change:
     - remove the parameterMap - there is default parameterMap for odata type DataSource
     - also data configuration in the schema is not required - there are predefined settings which handlers OData services

    Greetings,
    Nikolay Rusev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Griffin
    Griffin avatar
    5 posts
    Member since:
    Jul 2009

    Posted 03 Aug 2012 Link to this post

    Hi Nikolay,

    Perfect! Thank you.

    For anyone reading this later, I'd like to mention that I had to rebuild Nikolay's project otherwise Northwind.svc would generate a 500 Internal Server Error.

    Best regards,
    Griffin
  5. Sam
    Sam avatar
    1 posts
    Member since:
    Aug 2012

    Posted 28 Nov 2014 Link to this post

    Nikolay, 

    why did you set batch: false in your source? Is there a different method of batch update that im missing here?
  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2285 posts

    Posted 03 Dec 2014 Link to this post

    Hello Sam,

    This is because update action is using PUT verb which points to single entity. You can find more details of the OData v2.0 specification here: 2.6 Updating Entries.


    Regards,
    Nikolay Rusev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready