MooTools Array sort by name + Fx.Sort

1. Defines Fx.Sort, a class that reorders lists with a transition. http://mootools.net/docs/more/Fx/Fx.Sort

2. Array.sortBy is a prototype function that allows sorting arrays ofobjects by a given key, whether it is a root key or a child key of theobject. https://github.com/eneko/Array.sortBy

var dataArray = [];$(cont1).getElements(li).each(function(el,i){var dataArray_new =[{name:el.get(text),row:i}];dataArray.append(dataArray_new);});

var ArrSort1 = dataArray.sortBy(name).map(function(item){return item.row});var ArrSort2 = dataArray.sortBy(-name).map(function(item){return item.row});var ArrSort3 = dataArray.sortBy(row).map(function(item){return item.row});
var sorter = new Fx.Sort($$('#cont1 li'),{duration: 500,transition: Fx.Transitions[Quartic.easeIn]});

$(sort1).addEvent(click, function(event){sorter.sort(ArrSort1);});$(sort2).addEvent(click, function(event){sorter.sort(ArrSort2);});$(sort3).addEvent(click, function(event){sorter.sort(ArrSort3);});

Related Posts

MooTools - JSON Sort php array