This JSPWikiStyle allows you to make tables sortable by enclosing them inside a %%sortable block. Just click the column header and your table is sorted without round-trip to the server.
See also Filtered Tables
Enclose your tables in %%sortable tags. Make sure your table starts with a row of header cells ( wikisyntax: || ).
<td sortdata="Fri, 5 Oct 2007 08:16:23">05-Oct-2007 20:16</td>
%%zebra-table %%sortable || Title || Author || Published || Edition || Some IP@ || Expenses || Disk Memory | book1 | zappy | 25 Feb 2005 | 5 | 100.100.100.100 | €500 | 2Gb | book2 | happy | 25 Jan 2005 | 19 | 256.100.100.100 | €1500 | 4Kb | book3 | pappy | 23 Mar 2005 | 06 | 10.100.100.100 | €50 | 1.23TB | book4 | dappy | 21 Apr 2005 | 199 | 1.100.100.100 | €0.500 | 2.73kb | book5 | rappy | 25 Jul 2005 | 017 | 1.100.25.100 | €5500 | 0.4Tb /% /%
Reality check:
Title | Author | Published | Edition | Some IP@ | Expenses | Disk Memory |
---|---|---|---|---|---|---|
book1 | zappy | 25 Feb 2005 | 5 | 100.100.100.100 | €500 | 2Gb |
book2 | happy | 25 Jan 2005 | 19 | 256.100.100.100 | €1500 | 4Kb |
book3 | pappy | 23 Mar 2005 | 06 | 10.100.100.100 | €50 | 1.23TB |
book4 | dappy | 21 Apr 2005 | 199 | 1.100.100.100 | €0.500 | 2.73kb |
book5 | rappy | 25 Jul 2005 | 017 | 1.100.25.100 | €5500 | 0.4Tb |
Title | Author | Published | Edition | Some IP@ | Expenses | Disk Memory |
---|---|---|---|---|---|---|
book1 | zappy | 25 Feb 2005 | 5 | 100.100.100.100 | €500 | 2Gb |
book2 | happy | 25 Jan 2005 | 19 | 256.100.100.100 | €1500 | 4Kb |
book3 | pappy | 23 Mar 2005 | 06 | 10.100.100.100 | €50 | 1.23TB |
book4 | dappy | 21 Apr 2005 | 199 | 1.100.100.100 | €0.500 | 2.73kb |
book5 | rappy | 25 Jul 2005 | 017 | 1.100.25.100 | €5500 | 0.4Tb |
However, the javascript was refactored completely to better fit with JSPWiki. JSPWiki tables dont use thead or tbody tags; more flexibility was needed to change the appearance of the sortAscending/sortDescending controls through css; allowing fine control in different skins; and auto-recognition of data-types has been added.
Check out the Sortable object in scripts/jspwiki-common.js file for the actual implementation.
The onPageLoad does the initialisation after the page is loaded. It will track all %%sortable elements and process its first TABLE element. An onclick() handler is added to each column header which points to the heart of the javascript: the Sortable.sort() function.
The sort function has four major steps :
The Sortable.convert() and Sortable.createCompare() are helper functions for data-type conversion and for creation of appropriate comparsion routines used by the javascript sort engine.
Following CSS selectors can be changed if needed: