In general , which you want to sort in the database is easier, less code and more efficient.
However, there are some boundary conditions where client-based sorting makes sense.
One dataset, several varieties, in-memory dataset
Let's say you have a javascript gui that looks at a table with 500 rows, if you want to give your users the flexibility to sort by any column that they want, it might make sense to do sorting in javascript so that you reduce the trip to the server.
The main advantage for sorting on the client side is the reduction in network traffic and the use of db (when using several varieties). You must be very careful with your sorting characteristics and memory limitations. Large datasets, the client side, are often virtualized, so not all data actually arrives at the client.
Sam saffron
source share