Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Uncaught TypeError: Cannot read property '__count' of undefined" in grid datasource

I recently updated my jQuery and Kendo UI version. Now using jQuery 1.12.13 and Kendo UI 2016.3.914 (unsure which version it corresponds to in their public website, but probably around R3 2016).

It seems either kendo or jQuery have gotten more strict about data formats. I had a kendo UI Grid with a datasource which had type: "json". This worked in earlier versions but not anymore - it gave a warning:

Unknown DataSource transport type 'json'. Verify that registration scripts for this type are included after Kendo UI on the page.

So I looked at the documentation and changed the type to be odata. This gave an error:

VM94003:3 Uncaught TypeError: Cannot read property '__count' of undefined

Typical to Kendo UI, this error message really doesn't tell you much. So what is wrong?

like image 689
Lauri Peltonen Avatar asked Oct 27 '16 07:10

Lauri Peltonen


2 Answers

I added the following code to schema of the dataSource and got this thing to work without removing type as odata.

schema: {
         data: function(data) {
              return data.value;
         },
         total: function(data) {
              return data['odata.count'];

         }

        }

The solution was found in this link

like image 108
Abdul Hameed Avatar answered Sep 22 '22 14:09

Abdul Hameed


It turned out that somehow defining the type as odata expects that the datasource data includes information about the size of the results. I tried adding a definition in the schema of the grid:

total: function (data) {
    return data.length;
}

But this didn't help.

Eventually, what did help was taking off the type definition completely. So now my grid's datasource has no explicit type definition but it seems to work just fine.

like image 27
Lauri Peltonen Avatar answered Sep 26 '22 14:09

Lauri Peltonen