infragistics igtree on hierarchy data

1.5k views Asked by At

I have a data structure like this:

Node Parent     Name
1    -1         Level1
2     1         Level2 - 1
3     1         Level2 - 2
4     2         Level3 - 1
5     2         Level3 - 2
6     3         Level3 - 3
....

This could lead to unlimited levels of data. and I want to use infragistics igtre to build a treeview like that. I checked a few basic examples but not very helpful. for example: http://help.infragistics.com/jQuery/2013.1/ui.igtree it is limited to the pre-defined hierarchy structure. I want to build a tree and furthermore I want to be able to add any node at any level, and move any node around. I'm using asp.net JQUERY AJAX, infragistics control is preferred. never done mvc model. can anyone experienced on this please send me some sample code? many thanks.

1

There are 1 answers

0
Damyan Petev On

The igTree is a dynamic control and it isn't limited to a pre-defined hierarchy - granted, your model has to conform to some base schema - there's no way the control can figure out bindings on it's own, however you can share a single binding throughout the entire tree. Basically you have to look at the right place - for example I've taken this Add Remove Node API sample and with similar binding created this sample:

http://jsfiddle.net/damyanpetev/x4eAB/

What this is meant to demonstrate:

  • The initial Hierarchy is random (some items have additional levels) - so you are not limited to a fixed levels for everything at start.
  • Adding extra nodes can be done at any level, new nodes themselves can have multiples levels as well, so this gives you the unlimited hierarchy you need.
  • When you define a single binding it is used for subsequent levers, so all items have 'Text' property and have 'Nodes' with more items with Text and Nodes inside and so on.

    $("#tree").igTree({
        bindings: {
           textKey: 'Text',
           valueKey: 'Text',
           childDataProperty: 'Nodes'
        }
    });
    
  • Due to the shared binding any node can be a parent for any other, which means that you can enable Drag and Drop with a single property and move nodes around as you please.

I'm assuming since you want to have unlimited hierarchy your model items are similar and will easily match this case, if not you could use some LINQ to fix them up. That data structure you gave doesn't describe your model too well, so I would need some more info if this doesn't help you.