transport.parameterMap Function

The function which converts the request parameters to a format suitable for the remote service. By default, the data source sends the parameters using jQuery conventions.

  • The parameterMap method is often used to encode the parameters in JSON format.
  • The parameterMap function will not be called when using custom functions for the read, update, create, and destroy operations.

If a transport.read.data function is used together with parameterMap, remember to preserve the result from the data function that will be received in the parameterMap arguments. An example is provided below. Generally, the parameterMap function is designed to transform the request payload, not to add new parameters to it.

transport: {
  read: {
    url: "my-data-service-url",
    data: function () {
      return {
        foo: 1
      };
    }
  },
  parameterMap: function (data, type) {
    // if type is "read", then data is { foo: 1 }, we also want to add { "bar": 2 }
    return kendo.stringify($.extend({ "bar": 2 }, data));
  }
}

Parameters

data Object

The parameters which will be sent to the remote service. The value specified in the data field of the transport settings (create, read, update or destroy) is included as well. If batch is set to false, the fields of the changed data items are also included.

data.aggregate Array

The current aggregate configuration as set via the aggregate option. Available if the serverAggregates option is set to true and the data source makes a "read" request.

data.group Array

The current grouping configuration as set via the group option. Available if the serverGrouping option is set to true and the data source makes a "read" request.

data.filter Object

The current filter configuration as set via the filter option. Available if the serverFiltering option is set to true and the data source makes a "read" request.

data.models Array

All changed data items. Available if there are any data item changes and the batch option is set to true.

data.page Number

The current page. Available if the serverPaging option is set to true and the data source makes a "read" request.

data.pageSize Number

The current page size as set via the pageSize option. Available if the serverPaging option is set to true and the data source makes a "read" request.

data.skip Number

The number of data items to skip. Available if the serverPaging option is set to true and the data source makes a "read" request.

data.sort Array

The current sort configuration as set via the sort option. Available if the serverSorting option is set to true and the data source makes a "read" request.

data.take Number

The number of data items to return (the same as data.pageSize). Available if the serverPaging option is set to true and the data source makes a "read" request.

type String

The type of the request which the data source makes.

The supported values are:

  • "create"
  • "read"
  • "update"
  • "destroy"

Returns

Object—The request parameters converted to a format required by the remote service.

Example - convert data source request parameters

<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      url: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders?$format=json",
      dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
      jsonp: "$callback",
      cache: true
    },
    parameterMap: function(data, type) {
      if (type == "read") {
        // send take as "$top" and skip as "$skip"
        return {
          $top: data.take,
          $skip: data.skip
        }
      }
    }
  },
  schema: {
    data: "d"
  },
  pageSize: 20,
  serverPaging: true // enable serverPaging so take and skip are sent as request parameters
});
dataSource.fetch(function() {
/* The result can be observed in the DevTools(F12) console of the browser. */
  console.log(dataSource.view().length); // displays "20"
});
</script>

Example - send request parameters as JSON

<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    create: {
      url: "https://demos.telerik.com/kendo-ui/service/products/create",
      dataType: "jsonp" // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
    },
    parameterMap: function(data, type) {
      return kendo.stringify(data);
    }
  },
  batch: true,
  schema: {
    model: { id: "ProductID" }
  }
});
dataSource.add( { ProductName: "New Product" });
dataSource.sync();
</script>
In this article