HierarchicalDataSource with odata, $expand and __count

2 posts, 1 answers
  1. Answer
    Richard
    Richard avatar
    13 posts
    Member since:
    May 2013

    Posted 30 Jul 2013 Link to this post

    Hi All,

    I am getting this error.

    Cannot read property '__count' of undefined

    I have read up on this and the solution was to make sure that this statement is part of the model.

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

    Fiddler returns the correct information 

      "odata.metadata":"<url>/%24metadata#categories","odata.count":"1","value":[
        {
          "SubCategories":[
            {
              "Id":1,"Name":"Skateboards","CategoryId":1,"Tracking":{
                "CreatedBy":"tester","CreatedOn":"2013-07-29T14:48:25.987","ModifiedBy":"tester","ModifiedOn":"2013-07-29T14:48:25.987","Timestamp":"AAAAAAAACAk="
              }
            }
          ],"Id":1,"Name":"Sports","Tracking":{
            "CreatedBy":"tester","CreatedOn":"2013-07-29T14:48:25.987","ModifiedBy":"tester","ModifiedOn":"2013-07-29T14:48:25.987","Timestamp":"AAAAAAAACAY="
          }
        }

    Here is the data source configuration.  

    new kendo.data.HierarchicalDataSource({
                type: "odata",
                transport: {
                  read: {
                      url: resourceurl + "/categories",
                      data: {
                          $expand:"SubCategories"
                      },
                      dataType: "json"
                  }  
                },
                schema: {
                    model: {
                        id: "Id",
                        hasChildren: true,
                        children: "SubCategories",
                        data: function (data) {
                            if (data.value) {
                                return data.value;
                            }
                            delete data["odata.metadata"];
                            return [data];
                        },
                        total: function (data) {
                            return data["odata.count"];
                        },
                        errors: function (data) {
                        }                    
                    }
                }
            });

    Any ideas?

    Regards

    Richard...
  2. Richard
    Richard avatar
    13 posts
    Member since:
    May 2013

    Posted 31 Jul 2013 Link to this post

    Well what more can be said then me messing up the schema section and then it will not work!

    This is how it should be.  You will notice that the data, total and error properties need to be ad the schema level and I had them in the model level!

    schema: {
        model: {
              id: "CategoryId",
             hasChildren: true,
            children:"SubCategories"
       },
       data: function (data) {
             if (data.value) {
                 return data.value;
            }
            delete data["odata.metadata"];
           return [data];
      },
      total: function (data) {
         return data["odata.count"];
      },
      errors: function (data) {
      }
    }

    Regards

    Richard...
  3. Kendo UI is VS 2017 Ready
Back to Top