00388: Sortable columns in simple tables

Summary: Sortable columns in simple tables
Created: 2005-03-15 13:38
Status: Suspended
Category: Feature
From: Russ Fink
Assigned:
Priority: 555545
Version: 2
OS:

Description: Please provide an option in simple tables that enable sorting alphanumerically by column. The result would be a table with clickable headings, such that clicking on a column heading would order the table rows per the values in the selected column.

This might be represented by adding new parameters to the definition portion of a table: (a) sort=[initial_column|0] and (b) sortorder=[ascending|descending]. The semantics of "sort=x" means to do sorting, and to sort initially by column x. If x is 0, that means enable the sort header links but preserve initial as-wiki'd order. "sortorder" is optional, defaults to ascending. If "sort" is missing, give the current default table behavior, i.e, do not include sort links.

I know that PITS does this, but I don't want the entire PITS functionality, just ability to display static data in a (very large) table. I have traveled far and wide looking for this feature in various wiki's but have come up empty.

See (javascript) implementation as recipe Cookbook.SortableTables


It's not at all an easy feature to implement, and there hasn't been much demand for it. I'm suspending this issue for now, but additional votes/priority can unsuspend it. --Pm


It would be a really nifty feature. Either that, or some way of making pagelists which could sort on arbitrary fields -- but I suspect that having a "table" would make it easier, since the fields to sort on would be enclosed in the data.

Being able to fill in this table with data from includes/pagelists would be even better!

Kathryn Andersen August 04, 2006, at 07:37 PM

Thirding the request... it would be a very good feature.

Ramki Kazhiyur-Mannar?

Fourthing (is that a word) the request, this would be very very useful, instead of having to manually generate multiple pages. JesperDonnis?

There are some client-side JavaScripts for user-driven sorting of tables. These can be integrated http://www.j-berkemeier.de/TableSort.html and http://www.kryogenix.org/code/browser/sorttable --Manuel J. Schaffner 6.11.2006


Feel free to make this into a cookbook. I have tested it out, and it works great. Note that I have borrowed heavily from http://www.kryogenix.org/code/browser/sorttable

HowTo make a Sortable skin:

  1. Copy pub/skins/pmwiki/* to pub/skins/sortable/
  2. Download http://www.kryogenix.org/code/browser/sorttable/sorttable.js and place it in your pub/skins/sortable/ as pub/skins/sortable/sorttable.js
  3. Edit pmwiki.tmpl to include the text <script src="$SkinDirUrl/sorttable.js"></script> above <!--HTMLHeader-->

The rest comes from Cookbook/FormattingTables and Pmwiki/Tables:

  1. Add 'class=sortable' to the table attribute line (the first line, with opening ||, but no closing || )
  2. All of your table headings ( ||! heading || ) will now be sortable. Note that testing shows that the first row, heading or not has the feature that if you click on the entry, the table will sort on that column.
  3. ...
  4. All your sort are belong to us.

I'll try to make it more put-to-gether and post it as a skin / skin mod.


For me, the above instructions only work, if I don't copy pub/skins/pmwiki/* to pub/skins/sortable/ but edit the files inside the pmwiki skin... -- Leonard, 11.01.2008


Excellent "pre-recipe"! It works great! The sorting is a little squirrelly when dealing with upper/lower case, and numbers amidst strings, but c'est la vie. Thank you! - Wubbo, 2008-01-24


This works great for me! I'm using the triad skin, not the pmwiki (default) skin, so had to modify the pub/skins/triad/skin-triad.tmpl file instead. I downloaded the sorttable.js file to pub/skins/triad/. Thanks so much for the time and effort! -- Ly, 12.09.2008