I would like to order a friend list by status (online firsts, offline lasts) and by alphabetical order. All I manage to get is:
Here is plunker to expose my problem
After the ORDER BY keyword, add the name of the column by which you'd like to sort records first (in our example, salary). Then, after a comma, add the second column (in our example, last_name ). You can modify the sorting order (ascending or descending) separately for each column.
By using ORDER BY clause, we can sort the result in ascending or descending order. This clause can be used with multiple columns as well.
To sort by multiple columns, simply specify the column names separated by commas (just as you do when you are selecting multiple columns). The following code retrieves three columns and sorts the results by two of them—first by price and then by name.
Change the orderBy
filter to this:
orderBy:['-status','name']
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With