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

Grid custom transport update function not firing

6 Answers 1432 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rudy
Top achievements
Rank 1
rudy asked on 07 Aug 2012, 05:17 AM
Update:

Digging through the code, it seems that the settings.transport is being ignored in the code.  I am looking at Kendo.web.js line 6171. Here the following is false:

transport.options.update == transport["update"] 

Where "transport.options.update" is my function and "transport["update"]" is the default RemoteTransport Update method.  So when the code below it fires, it calls the default and not mine.  Is this a bug, or am I doing something wrong?



Maybe I have a dirty eye, but I don't see why this is not working:

var settings =
{
dataSource:
{
transport:
{
read: apiUrl,
update: function (e)
{
// Nothing, happens, this is never called
console.log("Hello?");
debugger;
alert('update');
}
}
}
}

but this DOES work:

var settings =
{
dataSource:
{
transport:
{
read: apiUrl,
update:
{
url: editApiUrl,
type: "POST",
data: function (e)
{
debugger;
alert('works');
}
}
}
}



I am copying the first sample from here:

var dataSource = new kendo.data.DataSource({
    transport: {
        update: function(options) {
            // make AJAX request to the remote service

            $.ajax( {
                url: "/orders/update",
                data: options.data, // the "data" field contains paging, sorting, filtering and grouping data
                success: function(result) {
                    // notify the DataSource that the operation is complete

                    options.success(result);
                }
            });
        }
    }
});

6 Answers, 1 is accepted

Sort by
0
Lothar
Top achievements
Rank 1
answered on 07 Sep 2012, 08:35 AM
I have same problem. Copy over 100% what is in documentation and it doesn't work. No resolution found yet?
0
Remco
Top achievements
Rank 1
answered on 14 Sep 2012, 09:21 AM
I have the same problem too. I use the SharePoint 2010 list odata service which requires that I set a concurrency token in the If-Match request http header for updates and destroys. I need to set this request header in the beforeUpdate function in the options passed to $.ajax method. If I could do

       var dataSource = new kendo.data.DataSource({

            type: "odata",

            transport: {

                update: function (options) {

                    var beforeSendFunction = function (jqXHR, settings) {

                        jqXHR.setRequestHeader("If-Match", options.__metadata.etag);                       

                    }

                    $.ajax({

                        type: 'PUT',

                        url: options.__metadata.uri,

                        contentType: 'application/json',

                        processData: false,

                        beforeSend: beforeSendFunction,

                        data: kendo.stringify(options),

                        success: function (result) {

                            options.success(result);

                        }

                    });

                }

            }

       });



then I would be in business. But, because this update function does not fire, I have to do this instead.



       var dataSource = new kendo.data.DataSource({

            type: "odata",

            transport: {

                update: {

                    url: function (options) {

                        return options.__metadata.uri;

                    },

                    dataType: "json",

                    beforeSend: function (jqXHR, settings) {

                        var options = JSON.parse(settings.data);

                        jqXHR.setRequestHeader("If-Match", options.__metadata.etag);

                    }

                }

            }

       });



You see how the data that was already converted to a json string needs to be parsed again to be able to get at the concurrency token. That is a bit silly, but at least it works. For updates that is. For a destroy I also need to send the concurrency token in the If-Match http request header. But this time the beforeSend function cannot get at the json string as there is no request body for a destroy operation. It's all in the url. I could add the json string in a parameter map so that I can get at it in the beforeSend function, but then I would also be sending that json string in the request body of the destroy operation unnecessarily.

0
Fernanda
Top achievements
Rank 1
answered on 17 Sep 2012, 03:47 PM
I had the same problem and concluded that the transport element expected the read, create, destroy and update values to be of the same type (either functions or url values for all of them). Using different types for different elements caused only the elements of the same type as the read element to fire.

Try replacing the read by a function that executes a $.get({url : apiUrl, success: function(data) { options.success(data)  } );

Hope this helps!
0
Remco
Top achievements
Rank 1
answered on 18 Sep 2012, 01:12 PM
that helped. thank you very much!
0
Houssem
Top achievements
Rank 1
answered on 11 Sep 2015, 10:12 AM

Hello,

I'm working with local data so I don't need ajax calls.

In my case even with the same transport configuration type, the update event still does not fire.

I put up an example here: http://dojo.telerik.com/UhUse

0
rwb
Top achievements
Rank 2
answered on 19 Jan 2016, 02:12 PM

If you add this to the `dataSource` then it works!

```

,
      schema: {
        model: {id: "col1",
                fields: {col1: {required: true},
                         col2: {required: true}
                        }
               }
      }

```

Tags
Grid
Asked by
rudy
Top achievements
Rank 1
Answers by
Lothar
Top achievements
Rank 1
Remco
Top achievements
Rank 1
Fernanda
Top achievements
Rank 1
Houssem
Top achievements
Rank 1
rwb
Top achievements
Rank 2
Share this question
or