dojostoredijit.tree

Updating the rootLabel of a dijit.Tree


I'm trying to update the model.rootLabel of a dijit.Tree using javascript. I set the model like this :

<div data-dojo-id="brandsModel" data-dojo-type="dijit.tree.ForestStoreModel"
     rootId="0"
     rootLabel="Brands (15)"
     data-dojo-props="store:myStore, query:{}">

For updating the tree I have extended it like this (this code also works with DND in the tree):

dojo.extend(dijit.Tree, { refreshModel:function() {
  this._itemNodesMap = {};
  // Collapse root node and set model children to null, so the model
  // will fetch again from the datastore when _expandNode() is called
  this._collapseNode(this.tree.rootNode);
  this.model.root.children = null;
  // Set root NODE to unchecked so that Tree will fetch from the model again
  this.rootNode.state = "UNCHECKED";
 //Set _loadFinished to false, so a new fetch is possible
 this.model.store._loadFinished = false;
 this._expandNode(this.tree.rootNode);
}
});

After adding or removing items from the tree I try to also update the counter. I've tried :

tree.model.rootLabel = 'Brands (16)';
tree.model.root.label = 'Brands (16)';

The changes show when debugging with console.debug(tree) but I don't know what to use to actually display the changed label.


Solution

  • the rootnode is not an actual item in the store - and only stuff in the '_itemNodesMap' gets refreshed. you will need to set the rootnode's-labelnode's innerHTML.

    tree.rowNode.set("label", "Brands ( " + tree._itemNodesMap.lenght + " )");