Search code examples
ajaxkendo-uikendo-gridkendo-datasource

Kendo UI, Grid, modify Data before send


Is it possible to access and modify data in Kendo UI grid before updating?

Below is an example to illustrate what I need. The options.data contains the sent data but it is already formatted in string "models=%B7%22Id22%.... etc" not really convenient form.

dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    ...
                },
                update: {
                    url: baseURL + "update",
                    beforeSend: function(xhr, options){
                        xhr.setRequestHeader('API-KEY', apikey );
                        var modifiedData = doSomething(options.data);
                        return modifiedData;
                    },
                    dataType: "json",
                    method: "POST",
                    dataFilter: function(data){
                        ... some data recieved modification
                        return JSON.stringify(somedata);
                    },
                    complete: function(e) {
                        ....
                    }
                },

Solution

  • You should be able to use the parameterMap function, check the type for "update" and change the options.data anyway you want.

    parameterMap: function(options, type) {
         if(type === "update") {
            options.someProperty = "somenewvalue";
         }
         return kendo.data.transports.odata.parameterMap(options, type);
    }