If you’re asked to build a PHP script that pumps out some data from the database and presents in an HTML table to the users. And on the first row of the table, shows the titles of each field (As pictured above). Once the user clicks on each title the data in the column need to be sorted. If you implement this in a server-side scripting such as PHP, it’ll then need to send the request back to the server to get the server-side PHP script to sort the data by changing the “ORDER BY” in an SQL statement.
This sounds little complex and some more whenever the user clicks on the title simply for getting the data to sort, it’ll need to be sent back to server and wait for the server to send back the result. And it’s less efficient and slow, if users access the page over the Internet.
Then mark the table that you need it to be sortable with the CSS class name “sortable” and DOM ID “sort”.
And then mark the row of the titles with CSS class name “nosort”. This row is where user clicks on each title of the column to get the respective column sorted.