JMaylin JMaylin - 1 year ago 107
AngularJS Question

orderBy two fields (one in reverse)

I would like to order a friend list by status (online firsts, offline lasts) and by alphabetical order. All I manage to get is:

  • Online firsts / Reversed alphabetical order

  • Or offline firsts / Alphabetical order

Here is plunker to expose my problem

Answer Source

Change the orderBy filter to this:


This will order by descending status (by prefixing the - character), then ascending name. Currently you're passing true to reverse the sort, which is causing the status to be correct (online first), but the names to be reversed (i.e., descending).

If you want to keep the reverse boolean, you could use orderBy:['status','-name']:true but that seems less clear than just making status descending as shown earlier.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download