TypeScript interface DataSourceTransportParameterMapData

7 posts, 1 answers
  1. Xavier
    Xavier avatar
    29 posts
    Member since:
    Jun 2014

    Posted 06 Jul 2015 Link to this post

    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

  2. Xavier
    Xavier avatar
    29 posts
    Member since:
    Jun 2014

    Posted 06 Jul 2015 in reply to Xavier Link to this post

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

  3. Kendo UI is VS 2017 Ready
  4. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 08 Jul 2015 Link to this post

    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!
     
  5. Xavier
    Xavier avatar
    29 posts
    Member since:
    Jun 2014

    Posted 14 Jul 2015 in reply to T. Tsonev Link to this post

    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.

     

  6. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 17 Jul 2015 Link to this post

    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!
     
  7. Xavier
    Xavier avatar
    29 posts
    Member since:
    Jun 2014

    Posted 17 Jul 2015 in reply to T. Tsonev Link to this post

    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

     

     

     

     

  8. Answer
    Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 22 Jul 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready