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

TypeScript interface DataSourceTransportParameterMapData

6 Answers 90 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 06 Jul 2015, 06:59 PM

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

Sort by
0
Xavier
Top achievements
Rank 1
answered on 06 Jul 2015, 07:28 PM

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;
}

0
T. Tsonev
Telerik team
answered on 08 Jul 2015, 12:09 PM
Hello,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Xavier
Top achievements
Rank 1
answered on 14 Jul 2015, 07:39 PM

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.

 

0
T. Tsonev
Telerik team
answered on 17 Jul 2015, 08:11 AM
Hello,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Xavier
Top achievements
Rank 1
answered on 17 Jul 2015, 11:33 PM

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

 

 

 

 

0
Accepted
Rosen
Telerik team
answered on 22 Jul 2015, 08:46 AM

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"]
};

Regards,
Rosen
Telerik
 
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
Xavier
Top achievements
Rank 1
Answers by
Xavier
Top achievements
Rank 1
T. Tsonev
Telerik team
Rosen
Telerik team
Share this question
or