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

Editing in grid using JSON web service

3 Answers 346 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 22 Dec 2011, 02:18 PM
Hi,

I am trying to implement grid editing. Grid is using JSON web service as data source. Getting data works great, but when I try to save changes I get an error "The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml'; 'Json'. "

var dataSource = new kendo.data.DataSource({
    severFiltering: false,
    serverPaging: true,
    pageSize: 15,
    batch: false,
    transport: {
        read: {
            url: crudServiceBaseUrl,
            dataType: "json"
        },
        update: {
            url: crudServiceBaseUrl,
            type: 'PUT',
            dataType: "json"
        }
    },
    schema: {
        data: "Data",
        total: "Count",
        model: {
            id: "ID",
            fields: {
                ID: { editable: false, nullable: false },
                Name: { type: "string" },
                Unit: { type: "string" }
            }
        }
    }
});
 
$("#grid").kendoGrid({
    theme: "metro",
    dataSource: dataSource,
    scrollable: false,
    pageable: true,
    height: 400,
    toolbar: ["save", "cancel"],
    columns: ["ID", "Name", "Unit"],
    editable: true
});

What should I do to enable updates using JSON web service?


Thanks,

Igor

3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Dec 2011, 09:06 AM
Hello,

 This stackoverflow question will shed some light about the error message. In a word parameters are not send as JSON by default. To do so you can try using the parameterMap setting:

transport: {
      read: { ... },
      update: { ... }
      parameterMap: function(data) {
            return JSON.stringify(data);
      }
}

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Igor
Top achievements
Rank 1
answered on 23 Dec 2011, 08:23 PM
Hi Atanas,

thank you. Your answer is a solution for the update method, but now the read operation sends wrong querystring:
/services/?{%22take%22:15,%22skip%22:0,%22page%22:1,%22pageSize%22:15,%22group%22:[]}

Is it possible to check the operation type in "parameterMap" function or maybe there is another solution?


Thanks for your help,

Igor
0
Accepted
Atanas Korchev
Telerik team
answered on 26 Dec 2011, 09:58 AM
Hello,

You can use the second argument of the parameterMap function to determine the type of request ("create", "read", "update", "destroy"):

parameterMap: function(data, type) {
     if (type == "read") {
              ...
     }

Greetings,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Igor
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Igor
Top achievements
Rank 1
Share this question
or