Custom Kendo UI Treeview construction

569 Views Asked by At

I want to build out a hybrid tree that shows a global view of my entire system. The system is a content management system but it also has other functions that can be managed from within the "collection of OData contexts" that make up my global API.

So I'm trying to figure out how I can make a hierarchical datasource of sorts that would work with varying URL's based on node type and a sprinkling of dynamic model metadata.

for example ...

I have API functions in my framework that allow me to do ...

my.api.get("Context/Type", function(odataCollectionResult) {
     ...
});

I also know Kendo UI supports doing something like ...

var viewModel = new kendo.data.HierarchicalDataSource({ 
   type:'odata-v4',
   ...
});

$("#tree").kendoTreeview({ dataSource: viewModel ... });

... but my question is ...

How can I setup a kendo treeview so that I bind to custom datasource that calls my custom expand and collapse functions so that I can make decisions based on more complex things I know about what my nodes represent?

I need to do this because depending on the node type it's children will come from different endpoints so I can't just use an OData datasource.

I'm trying to do something like this but I can't seem to get it to work ...

var viewModel = {
     data: [],
     expand: function(node) {
          var myParams = { endpoint: "Context/Type", childNodeType: "Foo/Bar" };
          my.api.get(myParams.endpoint, function(data) {
              node.data.children = buildNodes(myParams.childNodetype, data);
          });
     },
     collapse: function(node) {
         ...
     }
   }
}

$("#myTree").kendoTreeview({ 
    dataSource: viewModel, 
    events: { onExpand: viewModel.expand, onCollapse: viewModel.collapse } 
});

Has anyone done this or has some suggestions on how I might get this working?

1

There are 1 best solutions below

0
On BEST ANSWER

Ok I now realise the stupidity of this question as I somehow managed to not find this ...

http://demos.telerik.com/kendo-ui/treeview/events

... I think I now have all the pieces I need to do this.