Search code examples
javascriptajaxgwtsortingarchitecture

Should data sorting be done on the client or on the server?


I get data from a server and want to display it using GWT on the client.

GWT is not the problem here, you can replace GWT by Ajax calls or you can transpose it to a real application instead of a web app.

Should the sorting be done on the server or on the client using JavaScript after receiving the data and before displaying them?


Solution

  • Each approach has its pros and cons:

    • If you need pagination, and don't want to download the entire data to the client, then you must perform the sorting on the server (otherwise the client can only sort the rows it currently has, which will lead to wrong results, if you re-sort by a different column)
    • Sorting on the server is faster (as in: you can sort more rows/second), but if you have to serve 10000 clients at once, this may easily invert.
    • When sorting on the client, you can re-sort without downloading the data again.