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
January 5,
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)
January 5,
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
January 30,
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
May 10,