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

How to do user-defined callback when using odata?

1 Answer 208 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nicky
Top achievements
Rank 1
Nicky asked on 21 Nov 2012, 11:23 AM
I'm new to kendoUI.
I found the odata definition in kendo.data.odata.js, here's the code snippet:
........
$.extend(true, kendo.data, {
        schemas: {
            odata: {
                type: "json",
                data: "d.results",
                total: "d.__count"
            }
        },
        transports: {
            odata: {
                read: {
                    cache: true, // to prevent jQuery from adding cache buster
                    dataType: "jsonp",
                    jsonpCallback: "callback", //required by OData
                    jsonp: false // to prevent jQuery from adding the jsonpCallback in the query string - we will add it ourselves
                },
.......
The common way to use odata I see in this forum is like this:
var data = new kendo.data.DataSource({
    type: "odata",
    transport: {
    }
});
The pre-defined callback funtion will be invoked by kendo framework automatically, but I want to do some extra things in this pre-defined callback. When I try to use it another way(as follows), it seems it does NOT work, perhaps kendo framework don't allow user to use $.ajax() manually.
......
type:
"odata",
serverFiltering: true,
transport:{
            read: function(options){
                $.ajax({  //!!won't work when type is odata
                    url:"http://my_test_url",
                    dataType:"json",
                    data:options.data,
                    success:function (result) {
                        options.success(result);
                        doUserDefinedCallback(); //do my callback
                    }
                });
            }
        }
......
But I use a tricky way, it will take another server call and looks ugly somehow, here's the code snippet:
.......    
type: "odata"//using odata
serverFiltering: true,
transport: {
    read: {   //can NOT using $.ajax() manually here
url:"http://my_test_url"
    }
},
schema:{
    data: function(response){
        doServerCallFirst_Then_DoUserDefinedCallback(); //actually I do another server call here, then do my callback when the call returns.
        return response.d.results;
    }
}
.......
I need to use odata type, is there some better solution? Any help will be with great appreciation.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 26 Nov 2012, 09:13 AM
Hello Nicky,

You can use the requestEnd event to execute your logic when a request is completed successfully. Performing the request with custom code is supported but you will have to convert the parameters to the needed format.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
ComboBox
Asked by
Nicky
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or