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

schema: { total: function(data) { ... } } Not Working?

2 Answers 551 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Kevin Kembel
Top achievements
Rank 1
Kevin Kembel asked on 05 Jul 2014, 11:04 PM
I feel like I'm taking crazy pills.  I've seen this odata workaround in many places, but I can't for the life of me get it to work.  I have a simple data source that loads from an odata Web Api v2 endpoint.  The endpoint seems to be returning the JSON data appropriately, here's what I'm seeing as a response with only 2 items being returned:

{
  "odata.metadata":"http://localhost:40946/odata/$metadata#AlbumThumbnail","odata.count":"2","value":[
    {
      "ImageId":29,"Title":null
    },
    {
      "ImageId":30,"Title":null
    }
  ]
}

And here's how my data source is defined:
var thumbnailSource = new kendo.data.DataSource({
    type: "odata",
    transport: {
        read: {
            url: "/odata/AlbumThumbnail/",
            dataType: "json",
            data: {
                    id: 31
            }
        },
        schema: {
            data: function (data) {
                return data.value;
            },
            total: function (data) {
                return data["odata.count"];
            },
            model: {
                fields: {
                    ImageId: { type: "number" }
                }
            }
        }
    }
});
 
$(window).load(function () {
    thumbnailSource.read();
});

And any time it fetches data I get the usual odata error:
Unable to get property '__count' of undefined or null reference

I've tried setting breakpoints on my data() and total() functions and they're never reached.  I can't figure out why the usual internal total function is being called instead of mine.  The error occurs in:
function anonymous(d) {
    return d.d.__count
}

I can't figure out what I'm missing here?

2 Answers, 1 is accepted

Sort by
0
Kevin Kembel
Top achievements
Rank 1
answered on 05 Jul 2014, 11:30 PM
I should mention that I was using 2013.3.1119 initially and upgraded to 2014.1.528 with the same result.
0
Kevin Kembel
Top achievements
Rank 1
answered on 06 Jul 2014, 05:01 PM
Wow, came back today and feel pretty silly.  I guess the crazy pills wore off, and I moved my 'schema' object outside of the 'transport' where it should be:
var thumbnailSource = new kendo.data.DataSource({
    type: "odata",
    transport: {
        read: {
            url: "/odata/AlbumThumbnail/",
            dataType: "json",
            data: {
                    id: 31
            }
        }
    },
    schema: {
        data: function (data) {
            return data.value;
        },
        total: function (data) {
            return data["odata.count"];
        },
        model: {
            fields: {
                ImageId: { type: "number" }
            }
        }
    }
});

I thought it was something silly like that, and can't believe I never noticed it.
Tags
Data Source
Asked by
Kevin Kembel
Top achievements
Rank 1
Answers by
Kevin Kembel
Top achievements
Rank 1
Share this question
or