Opened 10 years ago

Closed 3 years ago

#9413 closed defect (patchwelcome)

Tree: nodes initially show + expando icon even when no children

Reported by: bill Owned by: bill
Priority: low Milestone: 2.0
Component: Dijit Version: 1.3.0
Keywords: Cc:
Blocked By: Blocking:

Description

When a tree folder is initially displayed, it has the + expando icon even if there are no children. The expando icon is corrected if the user tries to open the node.

Sometimes this is desired behavior, because it's an expensive operation to query if the node actually has children.

However, for the typical dojo.store where the list of children (or a list of references to children) are stored in a attribute, checking if the children attribute exists and contains one or more elements is fast.

The root problem is that dijit.tree.model has a method called mayHaveChildren(), which dijit.Tree is unfortunately using for two separate (conflicting) purposes:

  • test if the item is a folder
  • test if the item either has children, or may have children but we don't know

The name of the method is also confusing as it could be interpreted to mean that the node may have children in the future (i.e. it's an empty folder, rather than a plain document).

So, mayHaveChildren() in TreeStoreModel could be changed to:

return dojo.some(this.childrenAttrs, function(attr){
	return this.store.hasAttribute(item, attr) &&
                           this.store.getValues(item, attr).length > 0;
}, this);

However, that would break Tree.getIconClass(), causing empty folders to show up as the leaf (piece of paper) icon.

Maybe the solution is to not have any icons in the tree by default, and make users specify a custom getIconClass() method? The alternative is to add another method to the model called isFolder(), but I'm not sure if that should be the responsibility of the model.

(this ticket was split off from #9379)

Change History (5)

comment:1 Changed 10 years ago by bill

Summary: Tree: we need public functions to access a node from an itemTree: nodes initially show + expando icon even when no children

Woops, somehow the title got copied from #9339, fixing it.

comment:2 Changed 6 years ago by bill

Priority: highlow

comment:3 Changed 6 years ago by bill

See also related ticket #17465, about nodes that originally have no children but then they get children later on.

comment:4 Changed 3 years ago by dylan

Owner: set to bill
Status: newpending

Bill, is this worth keeping open at this point? Or close as patchwelcome?

comment:5 Changed 3 years ago by bill

Resolution: patchwelcome
Status: pendingclosed
Note: See TracTickets for help on using tickets.