I'm trying to do the following. I would like to sort some baseball players with this in mind. Managers should be at the top (sorted by active then name), then I would like to sort the player or any other type - could be several other types by active and then name.
To top it off, I'm using a case insensitive naturalsort on the name.
This is an example list:
[
{type: 'manager', name: 'Michael A', active: true},
{type: 'player', name: 'Abraham B', active: true},
{type: 'player', name: 'Jason R', active: false},
{type: 'manager', name: 'John A', active: true},
{type: 'coach', name: 'Ron A', active: true},
{type: 'player', name: 'Bobby A', active: false},
{type: 'player', name: 'Bobby J', active: true}
]
sort on these should produce:
[
{type: 'manager', name: 'Michael A', active: true},
{type: 'manager', name: 'John A', active: true},
{type: 'player', name: 'Abraham B', active: true},
{type: 'player', name: 'Bobby J', active: true}
{type: 'coach', name: 'Ron A', active: true},
{type: 'player', name: 'Bobby A', active: false},
{type: 'player', name: 'Jason R', active: false},
]
One thing I've tried is a case statement, but I dont know how to do the next level sort (name and active)
comparator: function(person) {
switch (person.get('type')) {
case 'manager': return 1;
default: return 2;
}
}