You are here

jQuery Tablesorter

Submitted by Peter on Thu, 2012-06-28 23:42

The jQuery Tablesorter library and the jQuery Tablesorter module for Drupal 7 simplify the sorting of tables in the Web browser.

The Tablesorter is documented at tablesorter.com/docs/. Visit the site for help with Tablesorter problems.

There is a demonstration of Tablesorter, as applied by the module, in RAL colour. The only modification to the content of the page is to add the class tablesorter to the HTML <table> element:
<table class="tablesorter">

You can access the module through Git at drupal.org/sandbox/peter/1664238. Read the Drupal.org documentation on how to use their Git.

There is temporarily a version Zipped at jquery_tablesorter.zip.

Most of the files in the module are straight from the Tablesorter download. The Tablesorter is offered with both a MIT and a GPL2 license. The MIT license lets you alter Tablesorter to fit your requirements and include it in a larger package.

The jquery_tablesorter.info file tells Drupal how to handle the module.

jquery_tablesorter.module

The jquery_tablesorter.module file is required by Drupal and contains a function to add the CSS because a setting in the .info file works only for themes, not modules.

jquery_tablesorter_init()

There is one tiny bit of PHP code that you do not have to know anything about. The code adds the CSS file through Drupal.

function jquery_tablesorter_init() {
  drupal_add_css(drupal_get_path('module', 'jquery_tablesorter') . '/jquery_tablesorter.css');
}

jquery.tablesorter_add.js

The jquery.tablesorter_add.js file is my bit of code to add the Tablesorter based on a class.

jQuery(document).ready(function () {
  jQuery(".tablesorter").tablesorter();
});

jquery_tablesorter.css

The jquery_tablesorter.css file is my modified version of the Tablesorter CSS file because one part did not work with one browser and some other parts made the table too hard to read. I had to rename the file from style.css because of some silly conflict in Drupal. Remove any CSS elements that already have better definitions in your theme.