:: Forum >>

Can a checkbox be included as a tree item

HI,
I need to have a tree where nodes have checkboxes in front(besides text) such that things can be checked or not checked per node.

thanks for any comments,
Ivan
Friday, January 5, 2007
Yes, this is possible but you have to make a new tree checkbox template class, which is derived from both AW.Tree.Item template and AW.Templates.Checkbox -

var MyTreeCheckbox = AW.Tree.Item.subclass();

MyTreeCheckbox.create = function(){
    AW.Templates.Checkbox.create.call(this);
}

var treeValue = ["", true, false, "mixed", false, true, false];
var treeText = ["", "Home", "Favorites", "Font size", "Search", "Child1", "Child2"];
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.UI.Tree;
tree.setItemTemplate(new MyTreeCheckbox);
tree.setItemValue(treeValue);
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);


Checkbox template is linked to the item value property. You can also try CheckedItem template which works with selections (item selected property).
Alex (ActiveWidgets)
Friday, January 5, 2007
Hi Alex,

Thanks for your comments...

Using the above suggestion how would we get the click events on the tree nodes?

Normally i would use this:
tree.onItemClicked = function(event, index){
alert("you clicked on the " + index + " leaf");
}

However,
the above code stops working the moment we include this line: "tree.setItemTemplate(new MyTreeCheckbox);"

What event shoud we look for to know that the user clicked on a tree node?..

Thanks a lot!
Ivan
Tuesday, January 30, 2007
I've implemented the example shown above and it all seems to work nicely from the user's (cosmetic) perspenctive, but how do I determine which boxes are check (or not)?
Evan Ross
Thursday, May 10, 2007
True/False
"JEB"
Wednesday, September 12, 2007

This topic is archived.


Back to support forum

Forum search