redrom
redrom

Reputation: 11642

Kendo UI - Datagrid, how to add additional params to request?

I have editable datagrid. I would like to change read transport to POST and add some additional data to json request (for example access_token).

Example below produce GET request instead of the POST and without additional data.

Question is: How can i do that?

dataSource = new kendo.data.DataSource({
              transport: {
                  read:  {
                      type: "POST",
                      url: crudServiceBaseUrl + "/Products",
                      contentType: "application/json; charset=utf-8",
                      dataType: "jsonp",
                      data: { "my_param": 1}
                  },
                  update: {
                      type: "PUT",
                      url: crudServiceBaseUrl + "/Products/Update",
                      dataType: "jsonp",
                      data: { "my_param": 1}
                  },
                  destroy: {
                      type: "DELETE",
                      url: crudServiceBaseUrl + "/Products/Destroy",
                      dataType: "jsonp",
                      data: { "my_param": 1}
                  },
                  create: {
                      url: crudServiceBaseUrl + "/Products/Create",
                      dataType: "json",
                      type: "PUT",
                      data: { "my_param": 1}
                  },
                  parameterMap: function(options, operation) {
                          console.log(options);
                          console.log(operation);
                          return {data: kendo.stringify(options.models)};
                  }

              },

Upvotes: 1

Views: 1667

Answers (1)

OnaBai
OnaBai

Reputation: 40887

Several options:

Option 1. Use transport.read.data

read:  {
    type: "POST",
    url: crudServiceBaseUrl + "/Products",
    contentType: "application/json; charset=utf-8",
    dataType: "jsonp",
    data: { "my_param": 1, access_token : "my_token" }  // send parameter "access_token" with value "my_token" with the `read` request
}

Option 2. Add them into transport.paremeterMap function

parameterMap: function(options, operation) {
    console.log(options);
    console.log(operation);
    if (operation.type === "read") {
        // send parameter "access_token" with value "my_token" with the `read` request
        return {
            data: kendo.stringify(options.models),
            access_token: "my_token"
        };
    } else
        return {data: kendo.stringify(options.models)};
}

Upvotes: 1

Related Questions