Login Register

How do you keep dnd items in order?

I have a page with several dojo.dnd.Sources that are defined as follows in my HTML:

<div class="groupMembers" id='team1Members' dojoType="dojo.dnd.Source" accept="staff">
  <script type="dojo/method" event="creator" args="item,hint">return node_creator(item,hint);

Note that the dojoDndItems are in alphabetical order by innerHTML.  When a user drags and drops items, I need the items in each source to remain in alphabetical order.  I can't figure out how to do this.  I've considered overriding Source's onDndDrop event handler or Selector's (or Container's) insertNodes method, but I don't see where the decision is made where to insert the source.  I'm beginning to think maybe what I want to do is override Source's onDndDrop, call Source's onDndDrop, and then scan the nodes in the Target and rearrange them myself, but I suspect there are complications to doing that (I mean, can I just rearrange the DOM nodes and have DnD continue to work properly?).

Can anyone suggest the best/simplest way to maintain the order of items in a Source?

I think your idea is good

I think your idea is good — rearranging nodes after onDndDrop should work. BTW, instead of overriding onDndDrop, you can dojo.connect() to it. Clearly the choice is up to you.