Hello,
I am trying to update data from a kendo grid and the datasource transport is defined as.
var transport: kendo.data.DataSourceTransport = {
read: {
url: "/alert/get",
},
update: {
url: "/alert/put",
type: "POST"
},
parameterMap: function (options, type) {
if (type === "read") {
var model: any = {
id: vm.responderSelected.id,
};
return model;
}
else if (options) {
var model: any = {
id: options.models["id"],
adHow: options.models["adHow"]
};
return model;
}
}
};
The problem is there is not models property on the options object as defined by interface DataSourceTransportParameterMapData. It is supposed to be just
var model: any = {
id: options.id,
adHow: options.adHow,
};
which works in plain JavaScript but in Typescript fails to compile.
Am I using it incorrectly or is the definition of DataSourceTransportParameterMapData wrong in kendo.all.d.ts ?
Thanks,
Xavier
6 Answers, 1 is accepted

The hack I am using to workaround the problem is.
else if (options) {
var optionHack: any = options;
var model: any = {
id: optionHack.id,
adHow: optionHack.adHow
return model;
}
You need to specify the type of the parameterMap arguments:
var transport: kendo.data.DataSourceTransport = {
parameterMap: function (options: kendo.data.DataSourceTransportParameterMapData, type: string) {
...
The first snippet will then compile as expected. I hope this helps.
Regards,
T. Tsonev
Telerik

It compiles fine even as
parameterMap: function (options, type) {
but how do you access the properties in options?
If you try
options.id
it gives compiler error.
if you try
options.models["id"]
you get a runtime error.
Please accept my apologies for the delayed response.
The options.models field is an array and you need to use the following syntax or similar:
var model: any = {
id: options.models[0].id,
...
}
I hope this helps.
Regards,
T. Tsonev
Telerik

Hi,
As I mentioned in my first post, options does not have a property called models. It only has the fields specified in the datasource schema.
Your code about results in runtime error.
"Cannot read property 'id' of undefined"
Regards,
Xavier
Hello Xavier,
Actually, the models field will be populate only if the batch option of the DataSource is set to true. Otherwise, the changed record's values will be available directly on the options instance. Therefore, you should be able to access them using similar to the following approach:
var
model: any = {
id: options[
"id"
],
adHow: options[
"adHow"
]
};
Rosen
Telerik