Telerik Forums
Kendo UI for jQuery Forum
1 answer
74 views
Hello,

I have a Hierarchical Data Source and work fine for display in ListView.

I can also CRUD the root level without problem. However, I could not update the second level (node.children).

No mater tried node.children.sync(), or even the top <Hierarchical Data Source>.sync(), the update function of transport had not been triggered. 

I tried modify a child record: node.children.at(0).set('newKey', 'newValue'). node.children.hasChanges() retuned True. After node.children.sync(), node.children.hasChanges() retuned False. But Transport.update had not been triggered so that nothing was written into datasource.

Any idea?

Alex Gyoshev
Telerik team
 answered on 14 Feb 2014
8 answers
1.2K+ views
Hello!


I have following data strucure: there are proejcts which has some items, these items can have other items as childs and as parents
accordingly.
--project1:
    --item1
            --item3
                  --item4
    --item2
--project2:
     //...      
EntityResource.query(function (entities)
 {
     //Entities are loaded dynamically when project selected.
  
//form data and append to tree
  treeview.append(..., projectNode);
}
Entities is a simple array of Resource objects (I use REST functionality from AngularJS), and some of them has circular references to each other,
say  I  have some EntityDto which has Children property which is array of child entities, and there is also Parent property which points to parent entity.

EntityDto has following properties:
$id: "1"
Children: Array[2]
DtoKey: "EntityId=77"
EntityId: 77
Name: "file10.2"
Parent: null

So I decided to use existing functionality like hierarchical data source:
EntityResource.query(function (entities)
 {
   var localDataSource = new kendo.data.HierarchicalDataSource({ data: entities});
     localDataSource .fetch();  
    treeview.append(localDataSource ,projectNode);
}
And of course it doesn't work... I guess I have to specify schema and model,  but I didn't find any example that is similiar to my case.
I need to get somethin like this:
  var hierarchialEntities = [ {
      EntityName: "Parent1",
      items: [
        { EntityName: "Entity1", class: '.entity-node', isEntity: true },
        { EntityName: "Entity2", class: '.entity-node', isEntity: true },
        { EntityName: "Entity3", class: '.entity-node', isEntity: true,
          items: [{ EntityName: "Entity7", class: '.entity-node', isEntity: true }]
             }
      ]
  }, {
      EntityName: "Parent2",
      items: [
        { EntityName: "Entity4", class: '.entity-node', isEntity: true},
        { EntityName: "Entity5", class: '.entity-node', isEntity: true},
        { EntityName: "Entity6", class: '.entity-node', isEntity: true }
      ]
  }
];
 
 treeview.append(hierarchialEntities,projectNode); //works as expected!!!

Can anybody explain, what I'm doing wrong? Or point to useful example or source code.

Thanks in advance.

UPDATE.
I will a little bit reformulate the question: is there a way in kendo-ui to get hierarchialEntities  (see above) from array of EntitiesDto (see above)?
I supposed that HierarchicalDataSource can do that automatically, provide array of EntitiesDto and retrive hierarchialEntities...


Daniel
Telerik team
 answered on 07 Oct 2013
8 answers
290 views
Does HeirarchicalDataSource support heterogeneous objects?
If my transport receives something like:
[{"id": 1, "name": "smith", "groups": [{"id": 1, "typeId": 1, "valueId": 1}]}]

How would the model be defined? Could you do something like:
groupModel = {
    id: "id",
    fields: {
        id: { editable: false, nullable: false, type: "number" },
        typeId: { editable: true, nullable: false, type: "number" },
valueId { editable: true, nullable: false, type: "number" },
    },
    hasChildren: false,
};

personModel = {
id: "id",
fields: {
        id: { editable: false, nullable: false, type: "number" },
name: {editable: true, nullable: false, type: "string" },
groups: groupModel,
},
hasChildren: function(item) {
return item.groups.length > 0;
}

I then use the person object in the model field of the schema in my data source. 
I know the above doesn't work. If I move groups out side of the fields like it doesn't work either. It doesn't seem to know I want to define nested node objects. Do I explicitly need to new Node objects? 
Alex Gyoshev
Telerik team
 answered on 01 Aug 2013
1 answer
177 views
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...
Richard
Top achievements
Rank 1
 answered on 31 Jul 2013
3 answers
236 views
Would it be possible to create a hierarchical datasource not from two endpoints, as the example shows below, but from two functions returning json.  Could the two transport sections below be replaced with data (as in data: getProductData()) functions which return data that the dataSource then "combines" the way it  does with remote endpoints?  If this is possible, how would the function returning the second level data (like products below) look?

var Categories = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "http://demos.kendoui.com/service/Categories"
        }
    },
    schema: {
        model: {
            hasChildren: "Products",
            id: "CategoryID",
            children: {
                transport: {
                    read: {
                        url: "http://demos.kendoui.com/service/Products"
                    }
                },
                schema: {
                    model: {
                        id: "ProductID",
                        hasChildren: false
                    }
                }
            }
        }
    }
});
Butter
Top achievements
Rank 1
 answered on 19 Jul 2013
2 answers
177 views
Hi,

I have an array of folder names and I'm trying to figure out how to walk the treeview to select the nested folder. How can I do that? I do not have ID set in the model of the Hierarchical Datasource - I'm just trying to do it by the text of the nodes. The tricky part is that some nodes can have the same name, like "ppt > _rels > slideMaster > _rels"
Alex Gyoshev
Telerik team
 answered on 19 Jul 2013
3 answers
146 views
Assuming your data only has two levels of depth, in which case would you favor an array of (objects containing a) DataSource versus a HierarchicalDataSource and vice versa?

In such a case, we are tempted to use option 1 because the DataSource is much better documented and easy to grasp than the HierarchicalDataSource but the HierachicalDataSource might have hidden benefits worth the learning curve.
Alexander Valchev
Telerik team
 answered on 26 Jun 2013
1 answer
275 views
Hi,
I have a static HierarchicalDataSource defined in a file. I use it as source for a TreeView. TreeView has an 'expand' event fired before expand actually occurs. In that event I can get dataItem related to the node that is being expanded. I need to get children of that dataItem but I cannot see any method/property on dataItem that would allow me to get them. Is there any way to get/load child items?

I would be most grateful for any help :)
Daniel
Telerik team
 answered on 24 Jun 2013
1 answer
401 views
i'm trying to bind a grid with hireachical data from server
i read the by  entityframework and the output on the client is the follow:
{"GetDocumentsResult":[{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1366236000000+0200)\/","FileExtension":".jpg","FollowUp":{"Fk_ID_ressol":11,"FollowUp1":"\/Date(1367877600000+0200)\/","FollowUp2":null,"FollowUp3":null,"Id":4,"Note":null},"Frequenza":"MENSILE","Id":4,"Nota":null,"ObjectID":"1","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1358463600000+0100)\/","Stato":"OK"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1361142000000+0100)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"MENSILE","Id":5,"Nota":null,"ObjectID":"2","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"OK"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1363561200000+0100)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"MENSILE","Id":6,"Nota":null,"ObjectID":"3","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"OK"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1366236000000+0200)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"MENSILE","Id":7,"Nota":null,"ObjectID":"4","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"DA VERIFICARE"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1357081200000+0100)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"TRIMESTRALE","Id":11,"Nota":null,"ObjectID":"6","PathBuildingRuleID":9,"Piva":"12345678901","RagioneSociale":"Alessio","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"OK"}]}



there is a child collection (named "FollowUp" and has got an only one row) in this json output
the field "FollowUp" contains several properties:   FollowUp":{"Fk_ID_ressol":11,"FollowUp1":"\/Date(1367877600000+0200)\/","FollowUp2":null,"FollowUp3":null,"Id":4,"Note":null}

in my javascript i've tried to do the following:

---hirearchicaldatasource-----
Master._resSolDataSource = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                beforeSend: function (xhr, s) {
                    s.data = JSON.stringify(Master._filter);
                },
                type: "POST",
                url: _rootUrl + 'wcf/ResponsabilitaSolidaleService.svc/getdocuments',
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            }
        },
        schema: {
            data: "GetDocumentsResult",
            model: {
                id: "Id",
                fields: {
                    Id: { type: "number" },
                    Piva: { type: "string" },
                    RagioneSociale: { type: "string" },
                    Data: { type: "date" },
                    AnnoEsercizio: { type: "number" },
                    Frequenza: { type: "string" },
                    Stato: { type: "string" }
                },
                children: "FollowUp"
            }
        },
        group: { field: "RagioneSociale", dir: "asc" }
 
    });
 
------and in the grid-----
 
$("#adminGrid").kendoGrid({
        ........,
    ...other code....,
    .....,
        columns: [{
            field: "Id",
            hidden: true  
        }, {
            field: "Piva",
            title: "Partiva IVA"
        }, {
            field: "RagioneSociale",
            title: "Ragione Sociale"
        }, {
            field: "Data",
            format: "{0:dd/MM/yyyy}"
        }, {
            field: "AnnoEsercizio",
            title: "Anno esercizio"
        }, {
            field: "Frequenza"
        }, {
            field: "Stato"
        }, {
            command: [
                {
                    name: "download",
                    click: Master.download
                },
                {
                    name: "followup",
                    click: Master.followup
                }
            ],
            title: " "
        }, {
            field: "FollowUp[0].FollowUp1",       //<--FollowUp seems to be null
            title: "fu1 child"
        }]
 
    });



give exception here because the parameter "data.FollowUp.FollowUp1" doesn't exist because data.FollowUp is null

(code generated by visuatudio debugger from kendo.web.min.js)
function anonymous(data) {
var o,e=kendo.htmlEncode;with(data){o='<tr data-uid="'+(data.uid)+'" role=\'row\'><td class="k-group-cell"> </td><td style="display:none" role=\'gridcell\'>'+e(data.Id==null?'':data.Id)+'</td><td  role=\'gridcell\'>'+e(data.Piva==null?'':data.Piva)+'</td><td  role=\'gridcell\'>'+e(data.RagioneSociale==null?'':data.RagioneSociale)+'</td><td  role=\'gridcell\'>'+e(kendo.format("{0:dd/MM/yyyy}",data.Data==null?'':data.Data))+'</td><td  role=\'gridcell\'>'+e(data.AnnoEsercizio==null?'':data.AnnoEsercizio)+'</td><td  role=\'gridcell\'>'+e(data.Frequenza==null?'':data.Frequenza)+'</td><td  role=\'gridcell\'>'+e(data.Stato==null?'':data.Stato)+'</td><td  role=\'gridcell\'><a class="k-button k-button-icontext k-grid-download"  href="#"><span class=" "></span>download</a><a class="k-button k-button-icontext k-grid-followup"  href="#"><span class=" "></span>followup</a></td><td  role=\'gridcell\'>'+e(data.FollowUp.FollowUp1==null?'':data.FollowUp.FollowUp1)+'</td></tr>';}return o;
}


it looks like that this datasource doesn't expose the property "FollowUp" at all!
could you help me to understand, please!
Alessio.
Alex Gyoshev
Telerik team
 answered on 10 May 2013
1 answer
247 views
Hi, I am having problems using an instance of a kendo.Data.Model in a HierarchicalDataSource.

I tried this simple model for a folder object:

var folderModel = kendo.data.Model.define({
    id: "Id",
    hasChildren: "HasChildren",
    children: "Children",
    fields: {
        Id: { editable: false, nullable: true },
        Name: { validation: { required: true} },
        ParentFolderId: { editable: false, nullable: true }
    }
});

Then created a simple data source using that as the model:

var folderStore = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "/Folders/",
            dataType: "json",
            type: "POST"
        },
    },
    schema: {
        model: folderModel
    }
});

The datasource is then used to bind a TreeView.

$(function () {
    $("#folderTreeView").kendoTreeView({
        dataSource: folderStore,
        dataTextField: ["Name"]
    });
});

This fails and the treeview is not bound.

However, it does work if I use an inline approach when defining the datasource:

var folderStore = new kendo.data.HierarchicalDataSource({
    transport: {
        read: {
            url: "/Folders/",
            dataType: "json",
            type: "POST"
        },
    },
    schema: {
        model: {
            id: "Id",
            children: "Children",
            hasChildren: "HasChildren"
        }
    }
});

Even if I simplify the model down to:

var folderModel = kendo.data.Model.define({
    id: "Id",
    children: "Children",
    hasChildren: "HasChildren"
});

I cannot use it in the datasource.

Must be missing something here, please advice. Would like to use the model for CRUD operations elsewhere and want to use the same model in the treeview.
Daniel
Telerik team
 answered on 15 Feb 2013
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?