[Dojo-interest] Sorting by name in a dijit.Tree?

Jette Derriche jni at nerdgirl.dk
Tue Aug 19 12:47:59 UTC 2008


Hi

I would like to know if there is a method for sorting children by name,
in a dijit.Tree. 

I have figured out how to programmatically add a new child. But I would
also like to sort the children after adding the new child, so that new
'child d' appears after 'child c'.

This is my json data:

{
  identifier : 'name',
  label : 'name',
  items : [
    {
      name: 'mother',
      children: [
        {name : 'child a'},
        {name : 'child b'},
        {name : 'child c'},
        {name : 'child e'},
        {name : 'child f'}
      ]
    }
  ]
}

This is how I add a new child... 

function addItem(itemName) {
   var newItem = dataStore.newItem({ name : itemName });
   var childParent;
   dataStore.fetchItemByIdentity({
     identity : 'mother',
       onItem : function (item,request) { childParent = item; }
   });
   var allChildren = dataStore.getValues(childParent,"children");
   dataStore.setValues(childParent,"children",
                       allChildren.concat(newItem));
}


Kind regards,
Jette



More information about the Dojo-interest mailing list