简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM