Codebox Software

TableSorter Script

Published:

A GreaseMonkey script for making tables on web pages sortable, also available as a Bookmarklet.

When activated, TableSorter automatically detects any tables that are displayed as you surf the web, and adds some links near the top of each table allowing you to sort its contents. Links appear at the head of each column in the table, so you can choose which set of values to use to sort the data. You can also choose between alphabetic and numeric sort, as well as selecting the direction (ascending or descending), and it's easy to revert the table back to its original order at any time.

You can try TableSorter right now, without installing anything, by using the in-page demo to make the example table below sortable...

Country Capital City Population BitMeter Penetration
United Kingdom London 59000000 12.4%
Czech Republic Prague 10000000 23.9%
Vatican City 12 8%
Antractica None 0

Use the ⇕ABC link to make the table sortable alphabetically, or the ⇕123 link to sort the table using any numeric values that appear in the columns; when sorting numerically, any non-numeric values are sent to the bottom of the list out of the way. To restore the data in the table to its original order just click the Undo Sorting symbol .

TableSorter can cope with cells that span multiple columns of the table, and when sorting it will leave any column headers in place so that table remains legible.

If you are using Firefox, and have the Greasemonkey extension, you can install this script by clicking the Download link.