PDA

View Full Version : Sorting a MixedCollection of Model objects by their properties



cjauvin
24 Oct 2012, 7:26 PM
If I have a MixedCollection of basic JS objects:



var mc = new Ext.util.MixedCollection();
mc.add({s:'b', i:2});
mc.add({s:'b', i:1});
mc.add({s:'a', i:2});
mc.add({s:'a', i:1});


I can sort it by their properties:



mc.sort([{property:'s',direction:'ASC'}, {property:'i',direction:'DESC'}]);


whereas if it contains Model objects instead:



Ext.define('M', {
extend: 'Ext.data.Model',
fields: [
{name: 's', type: 'string'},
{name: 'i', type: 'int'}
]
});

var mc = new Ext.util.MixedCollection();
mc.add(Ext.create('M', {s:'b', i:2}));
mc.add(Ext.create('M', {s:'b', i:1}));
mc.add(Ext.create('M', {s:'a', i:2}));
mc.add(Ext.create('M', {s:'a', i:1}));


the same sort by their properties doesn't seem to work. Is it the expected behavior, or am I missing something?

evant
24 Oct 2012, 7:40 PM
See: http://docs.sencha.com/ext-js/4-1/#!/api/Ext.util.Sorter-cfg-root

cjauvin
24 Oct 2012, 7:49 PM
Ahh I see! It makes great sense, many thanks for the quick answer!