Ticket #5719 (closed enhancement: fixed)
[patch] Tree: factory for nodes
| Reported by: | guest | Owned by: | rcoup |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2 |
| Component: | Dijit | Version: | 1.0 |
| Severity: | minor | Keywords: | dijit tree create custom node style |
| Cc: |
Description (last modified by bill) (diff)
This relates to bug #4817. I have a problem where I need to change the style of the text in the tree nodes. I can't use CSS classes because the style is interpreted from remote data. Specifically, I need to be able to make the background and font color of the tree nodes to be anything my server tells it to. I can't realistically make 256*256*256 CSS classes--one for each color I want to accommodate, so I really need to access the style object for the labelNode in dijit._TreeNode directly.
The fix for this is very simple and I have tested it thoroughly. In dijit/Tree.js, add this method in the dijit.Tree class (I added it after getItemChildren):
createChildNode: function(params){
return new dijit._TreeNode(params);
},
In the _setChildren(childrenArray) method in dijit._TreeNode, replace the line
var child = new dijit._TreeNode(dojo.mixin({
with
var child = this.tree.createChildNode(dojo.mixin({
and in dijit._TreeNode._addChildren, replace
var child = new dijit._TreeNode(
with
var child = this.tree.createChildNode(
This fix changes no functionality in the default implementation, but it allows custom extensions of dijit.Tree to override createChildNode and supply custom dijit._TreeNodes such as a custom implementation as I have. It just allows a programmer easy access to the tree nodes without adding any burden on users who don't require this access.