Pending Review
Last Updated: 11 May 2016 15:49 by ADMIN
Stephen
Created on: 07 Sep 2013 22:18
Category: TreeView
Type: Feature Request
1
Add a utility to convert user defined hierarchy to homogenous hierarchy for your tree control
I need homogenous data items for multilevels in your tree control.
Most data structures coming from our services are not homogenous.
We use the following to create a homogenous structure for the tree.
Maybe you could incorporate something like this - note that we use angular, and I use their $parse service in my implementation:

// CALLER:

          var levelDescriptors = [
            { item: "functionGroup", items: "functions" },
            { item: "this", items: null }];
          itemHierarchy = Portal.buildItemHierarchy(
            functionGroups,
            levelDescriptors,
            $parse);

// UTIL CODE:

    buildItemHierarchy: function(hierarchicalItems, levelDescriptors, $parse) {
      var hierarchicalDataItems = [];
      if(Portal.isDefined(hierarchicalItems)) {
        hierarchicalDataItems = Portal.createHierarchicalDataItems(0, hierarchicalItems, levelDescriptors, $parse);
      }
      return hierarchicalDataItems;
    },

    createHierarchicalDataItems: function(level, levelItems, levelDescriptors, $parse) {
      var levelDataItems = [];
      if(Portal.isDefined(levelItems)) {
        if(Portal.isDefined(levelDescriptors)) {
          if(level < levelDescriptors.length) {
            for(var i=0; i<levelItems.length; i++) {
              // extract datasource for current level.
              // create an associated node data item.
              var levelItem = levelItems[i];
              var levelDescriptor = levelDescriptors[level];
              var item = levelItem;
              if(levelDescriptor.item !== "this") {
                item = $parse(levelDescriptor.item)(levelItem);
              }
              if(Portal.isDefined(item)) {
                var levelDataItem = Portal.createNodeDataItem(item);
                levelDataItems.push(levelDataItem);
                // extract children for current level.
                // create associated (child) node data items.
                var items = $parse(levelDescriptor.items)(levelItem);
                if(Portal.isDefined(items)) {
                  var itemsLevel = level + 1;
                  levelDataItem.items = Portal.createHierarchicalDataItems(
                    itemsLevel,
                    items,
                    levelDescriptors,
                    $parse);
                }
              }
            }
          }
        }
      }
      return levelDataItems;
    },

    createNodeDataItem: function(item) {
      return {
        id: item.id,
        text: item.name,
        dataSource: item,
        expanded: false,
        items: []
      };
    },
0 comments