:: Forum >>

Tree within a combo?

Is it possible to have a tree control within a combo control?
Peter G.
Monday, July 31, 2006
Maybe - here is possible implementation (experimental, not tested and not supported :-)

AW.Tree.Combo = AW.UI.Tree.subclass();

AW.Tree.Combo.create = function(){

    AW.UI.ImageText.create.call(this);
    AW.UI.Input.create.call(this);
    AW.Templates.Combo.create.call(this);

    var obj = this.prototype;

    obj.setClass("ui", "combo");
    obj.setClass("input", "");

    obj.defineTemplate("popup", new AW.Templates.Frame);

    obj.onCurrentItemChanged = function(i){
        var text = this.getItemText(i);
        this.setControlText(text);

        this.hidePopup();

        var e = this.getContent("box/text").element();
        e.value = text;
        e.select();
        e = null;
    };

    obj.setController("selection", {
        onItemClicked: "selectClickedItem"
    });

};


and usage is the same as AW.UI.Tree -

var treeText = ["", "Home", "Favorites", "Font size", "Search", "Child node 1", "Child node 2"];
    var treeImage = ["", "home", "favorites", "fontsize", "search"];
    var treeView = {0:[1, 2, 3, 4], 1:[5, 6], 2:[7], 3:[8], 4:[9]};

    var tree = new AW.Tree.Combo;
    tree.setId("tree1");
    tree.setItemText(treeText);
    tree.setItemImage(treeImage);
    tree.setViewCount(function(i){return treeView[i] ? treeView[i].length : 0});
    tree.setViewIndices(function(i){return treeView[i]});

    document.write(tree);
Alex (ActiveWidgets)
Monday, July 31, 2006
Hey Alex,

Thanks. This works great! However, what do I have to do to populate the values from the database? What would be a good way to construct var treeView = {0:[1, 2, 3, 4], 1:[5, 6], 2:[7], 3:[8], 4:[9]}; ?

I have the parent, node and subnode information in the database.

Thanks,

Peter.
Peter G.
Wednesday, August 23, 2006

This topic is archived.


Back to support forum

Forum search