This is a migrated thread and some comments may be shown as answers.

Odata Grid Batch Editing

4 Answers 202 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Griffin
Top achievements
Rank 1
Griffin asked on 02 Aug 2012, 07:10 AM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 03 Aug 2012, 09:23 AM
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!
0
Griffin
Top achievements
Rank 1
answered on 03 Aug 2012, 06:18 PM
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
0
Sam
Top achievements
Rank 1
answered on 28 Nov 2014, 05:53 PM
Nikolay, 

why did you set batch: false in your source? Is there a different method of batch update that im missing here?
0
Nikolay Rusev
Telerik team
answered on 03 Dec 2014, 11:39 AM
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!
 
Tags
Grid
Asked by
Griffin
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Griffin
Top achievements
Rank 1
Sam
Top achievements
Rank 1
Share this question
or