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

Datasource, odata and asp webapi

1 Answer 80 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
pete
Top achievements
Rank 1
pete asked on 03 Mar 2014, 09:44 AM
I've got odata to work with a webapi call to a listview and I'm struggling with what appears to be a quirk in mvc.

If I return a pageresult from my webapi controller I just get the data as a json array i.e. no Count value.

To overcome this tiny issue I copy the Count value to the response header so I can pick it up in the client.

I can easily access the Count value in the transport complete event:

        var datasource = new kendo.data.DataSource({
            type: "odata",
            transport: {
                read: {
                    beforeSend: function (req) {
                        //req.setRequestHeader('Accept', 'application/json;odata=verbose');
                    },
                    url: "/api/products",
                    dataType: "json",
                    complete: function (jqXHR, textStatus) {
                        debugger;
                        count = jqXHR.getResponseHeader("Last-Count");

                    }
                },

But this fires after the "Total" is processed so my Count is always one event behind.

How can I examine do something like count = jqXHR.getResponseHeader("Last-Count"); in the "Total" as I can't see where jqXHR is exposed in this part?


1 Answer, 1 is accepted

Sort by
0
pete
Top achievements
Rank 1
answered on 04 Mar 2014, 02:45 PM
While I've been waiting for a reply I've modified kendo.mobile.all.js to return the response headers. It isn't an ideal solution as I'll need to do this each update of Kendo Mobile but it has the desired result.

navigate to e.ajax(n) and replace rhe read section accordingly:

                read: function (n) {
                    var i, r, o, a = this,
                        s = a.cache;
                    n = a.setup(n, pt), i = n.success || st, r = n.error || st, o = s.find(n.data), o !== t ? i(o) : (n.success = function (e, p1, p2) {
                        p3 = Object;
                        p3.rows = e;
                        p3.xhr = p2;
                        s.add(n.data, p3), i(p3)
                    }, e.ajax(n))
                },

I put the data returned from the ajax call in "data.rows" and the jqXHR object in "data.xhr".

It's a quick fix, it's not ideal but it does appear to work.

Pete
Tags
General Discussion
Asked by
pete
Top achievements
Rank 1
Answers by
pete
Top achievements
Rank 1
Share this question
or