Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 582
Jerome Cance Avatar asked May 23 '12 13:05

Jerome Cance


People also ask

Should sorting be done on front end or backend?

I agree with this answer. Unless there's some technical reason against it, sorting is usually best done at the source of data retrieval, but how the data needs to be sorted is up to the presentation layer. So, provide a way for the UI to indicate its sorting needs, and have the backend do the sorting.

What is server-side sorting?

Server-side Sorting. When Infinite Scroll is active, the grid does not have all the rows needed to sort on the client. As such, the server-side row model will request rows again each time the sort changes and expect the server to sort the rows.

Which is faster server-side or client-side?

Between the two options, server-side rendering is better for SEO than client-side rendering. This is because server-side rendering can speed up page load times, which not only improves the user experience, but can help your site rank better in Google search results.

Why should we apply sorting to a database?

Data sorting is any process that involves arranging the data into some meaningful order to make it easier to understand, analyze or visualize. When working with research data, sorting is a common method used for visualizing data in a form that makes it easier to comprehend the story the data is telling.


2 Answers

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.
like image 178
Chris Lercher Avatar answered Oct 14 '22 08:10

Chris Lercher


Ideally, the sort should be done on the server because:-

  1. It is best to assume that your client will be having low resources. For example, some people will launch the GWT app from a desktop but another may launch the GWT app from a iPad/phone which is having less CPU/RAM

  2. There are standard ways to do sorting on the server side, for example, by using SQL ORDER BY clause but you may have to implement your own routine/method to do the sorting on the client side.

like image 39
Anuroop Avatar answered Oct 14 '22 08:10

Anuroop