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

[Solved] Kendo UI Grid - Auto initialiize model object

1 Answer 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
None
Top achievements
Rank 1
None asked on 02 Feb 2015, 04:47 PM
I have a web api controller as follows:

// PUT: api/VHFMasterLists
 [ResponseType(typeof(void))]
 public IHttpActionResult PutVHFMasterList(VHFMasterList vHFMasterList)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
 
 
     return StatusCode(HttpStatusCode.NoContent);
 }

I then have a datasource as follows:

var tmpdataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    url: crudServiceBaseUrl + "api/VHFMasterLists",
                    dataType: "json"
                },
                update: {
                    url: crudServiceBaseUrl + "api/VHFMasterLists",
                    dataType: "json",
                    data: { Frequency:"GGGG", Id: 1 },
                    type: "PUT",
                    contentType: "application/json; charset=utf-8",
 
                },
                parameterMap: function (model, operation) {
                    if (operation !== "read" && model) {
                        return kendo.stringify(model);
                    }
                }
            },
            batch: true,
            pageSize: 20,
            schema: {
                model: {
                    id: "Id",
                    fields: {
                        Id: { editable: false,
                            nullable: false,
                            type: "number"
                        },
                        Frequency: { type: "string"}
                    }
                }
            }
        });



As you can see with the line " data: { Frequency:"GGGG", Id: 1 }," I am setting the data so that the VHFMasterList object that is sent to my controller is initialized properly. My question is how do I make it so that I can skip this step? Is it possible to have kendo know how to initialize this object based on the data in the grid?And as a side note if anyone knows, if this is not possible, how would I read this data from the kendo grid so that I can set my object with the actual data of the row? Thanks.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 04 Feb 2015, 10:46 AM
Hi,

You should disable the batch option. When the option is enabled, the item(s) will be passed as array with name "models" in the paremeterMap data. If you wish to use batch updates then you should change the parameter type on the server and serialize the "models" field.

Regards,
Daniel
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
None
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or