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

Load different data for different nodes level.

1 Answer 62 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jose Mejia
Top achievements
Rank 1
Jose Mejia asked on 13 Feb 2014, 02:07 PM
Hi.

Suppose I have following hierarchy

project1:
     -- entity1
     -- entity2
     -- entity3

project2:
     -- entity1
     -- entity2
     -- entity3

...

Project and  "entities" are basically different and I use different url to get them, say /serv/prj  for project and /serv/entities for entities.
When page is loaded there are only projects. When I expand project items should be loaded (refreshed) from server. Items for selected project
should be refreshed each time I expand the project.

Now it working ok in a static manner,  I have following:


var nodeZ = kendo.data.Node.define({
           hasChildren: "Entities",
           id: "EntityNamespaceID",
           children: "Entities"
 
       });
 
 var dataSource = new kendo.data.HierarchicalDataSource(
           {
               transport: {
                   read: {
                       url: "ns",
                       dataType: "json"
                   }
               },
               schema: { model: nodeZ},
               filter: {
                   logic: "or",
                   filters: [
                       { field: "EntityName", operator: "neq", value: "null" },
                       { field: "Namespace", operator: "neq", value: "null" }
                   ]
               }
 
           });

and have

dataTextField: ['Namespace', 'EntityName']   for tv.

But it is static. It loads everything one time and if I need to refresh data I have to reload page...

Is it possible to accomplish for within a single HierarchicalDataSource? As I mentioned project and entities are different, and to get
them I use two different urls, because in documentation it is stated for homogeneous data that it supply parent node id for request.
In my case data are heterogeneous.

What I'm currently unsuccessfully tried to do is to  load separately projects, and on expansion refrehs items:
expand: function(e)
 {

      var entityNodeZ = kendo.data.Node.define({
            hasChildren: "Children",
            id: "EntityId",
            children: "Children"

        });
              
    var nodeData = this.dataItem(e.node); //project node
             
     var entityDataSource = new kendo.data.HierarchicalDataSource(
       {
         transport: {
               read: {
                     url: "entity",
                     dataType: "json"
                      },
                      parameterMap: function ()
                       {
                           return { ns: nodeData.PrjId};
                       }
 
                   },
                   schema: { model: entityNodeZ},
                   filter: { field: "EntityName", operator: "neq", value: "null" }
 
               });
 
               entityDataSource.fetch();
              
               var tv= $('#userprjtreeview').data('kendoTreeView');
               tv.append(entityDataSource.view().slice(0), nodeData);
  
           }


But on tv.append  I get following exception:

Uncaught TypeError: Property 'children' of object [object Object] is not a function.

So please help with any approach.

Thanks in advance.


1 Answer, 1 is accepted

Sort by
0
Jose Mejia
Top achievements
Rank 1
answered on 17 Feb 2014, 09:33 AM
Ok, solved in following way:

-- on fir
var projectNode = this.dataItem(this.current());
 
 if (projectNode.EntityNamespaceID)
 {
     var nsId = projectNode.EntityNamespaceID;
 
         var EntityResource = $resource('entity/?ns=:nsId', {nsId: nsId});
 
         var nodeC = kendo.data.Node.define({
 
        hasChildren: function (item)
         {
             return item.Children !== undefined && item.Children.length > 0;
         },
 
       id: "EntityId",
      children: "Children"
 
    });
 
 
 EntityResource.query(function (entities)
  {
    var dataSource = new kendo.data.HierarchicalDataSource(
    {
      data: entities,
      schema: { model: nodeC},
      filter: {field: "EntityName", operator: "neq", value: null}
     });
 
dataSource.fetch();

projectNode.children.data(dataSource.view().slice(0));
 
    });
 }

Note there is also AngularJs code...
Tags
TreeView
Asked by
Jose Mejia
Top achievements
Rank 1
Answers by
Jose Mejia
Top achievements
Rank 1
Share this question
or