Adding column-sort functionality to tables
Drupal tables, while they can be made sortable when declared, require a page load every time a column needs to be sorted. This recipe details the steps required to achieve JavaScript-based sorting for HTML table columns. We will be accomplishing this through the use of the dataTables plugin for jQuery.
Getting ready
While we can just as easily implement this recipe using the theme layer, we will be using the mysite module, created earlier in this book, to do so since we are making use of a plugin. It is assumed that this module has been created and is enabled.
The dataTables plugin can be downloaded from http://www.datatables.net. The version of dataTables available might not be compatible with the version of jQuery that ships with Drupal. As a result, we will very likely need to upgrade the version of jQuery using the jQuery Update module which can be downloaded and installed from http://drupal.org/project/jquery_update.
How to do it...
To see our recipe...