Refactored the table handler code

 * Improved the sorting.

 * Made the sorting respond to the location search so it can be linked and appears in the history.

 * Refactored the filtering and sorting into a new TableHandler class. This
   allows the table sorting to be re-used on the activities page.