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

Post Issued with Empty Body

2 Answers 380 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 15 Dec 2015, 08:30 PM

I am trying to use a grid with a RESTful web service as a datasource. The read operation is working fine but the create operation is issuing a post with an empty body where I am expecting a JSON object.  Any suggestion on debugging this or what I am doping wrong. Code below:

   $(document).ready(function() 
  {
  var gridDataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "/saml-sp/secure-api/ecs/AccountDataService/v1/AccountData/19610505/OrganizationalUnit",
                type: "get",
                dataType: 'json'
            },
            create: {
                url: "/saml-sp/secure-api/ecs/AccountDataService/v1/AccountData/19610505/OrganizationalUnit",
                type: "post",
                contentType : 'application/json',
                dataType: 'json'
            },
            update: {
                url: "/saml-sp/secure-api/ecs/AccountDataService/v1/AccountData/19610505/OrganizationalUnit",
                type: "put",
                contentType : 'application/json',
                dataType: 'json'
            },
            parameterMap : function(options, operation) {
                if (operation !== "read" && options.models) {
                    return kendo.stringify(options.models);
                }
            }
        },            
        schema: {
            model: {
                id: "id",
                fields: {
                id: {
                editable : false,
                        nullable : false
                },
                    clientName: {type: "string"},
                    friendlyClientName: {type: "string"},
                    name: {type: "string"},
                    status: {type: "string"}
                }
            }
        }   
    });
    
    $("#ouGrid").kendoGrid({
        dataSource: gridDataSource, 
        toolbar: ["create"],
        messages: {
            commands: {
                create: "Add Organizational Unit"
            }
        },
        editable: "popup",
        columns: [
            { title: "Client", field: "clientName", width: 100 },
            { title: "Friendly Name", field: "friendlyClientName", width: 100 },
            { title: "Organizational Unit", field: "name", width: 100 },
            { title: "Status", field: "status", width: 100 }
        ],             
        groupable: true,
        selectable: "multiple row",
        sortable: true,
        filterable: true,
        allowCopy: true,
        height: 450,
    });  
  });

 

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 17 Dec 2015, 04:18 PM
Hi Bruce,

The parameterMap function is implemented as if batch editing is used:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-batch

Either enable the batch option, or do the following:

1) remove the options.models check from the IF statement
2) replace

return kendo.stringify(options.models);

with

return kendo.stringify(options);


More information is available at:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.parameterMap

Regards,
Dimo
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bruce
Top achievements
Rank 1
answered on 17 Dec 2015, 04:43 PM

Got it going.  

I used my own functions for read and create in the transport configuration. (I have taken out the update for now.)  The functions use jquery's ajax to send the JSON to the server which give me a bit more control over how the message is sent.

One trick seemed to be to having both the read and create using functions.  Specifying a function for just the create did not work.

Another notable was to specify the type of the id as number. When not specified it was sent as a string and the server was not able to de-serialize the JSON as it was expecting an int.   

 

Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Bruce
Top achievements
Rank 1
Share this question
or