/*** |''Name:''|TableSortingPlugin| |''Description:''|Dynamically sort tables by clicking on column headers| |''Author:''|Saq Imtiaz ( lewcid@gmail.com )| |''Source:''|http://tw.lewcid.org/#TableSortingPlugin| |''Code Repository:''|http://tw.lewcid.org/svn/plugins| |''Version:''|2.02| |''Date:''|25-01-2008| |''License:''|[[Creative Commons Attribution-ShareAlike 3.0 License|http://creativecommons.org/licenses/by-sa/3.0/]]| |''~CoreVersion:''|2.2.3| !!Usage: * Make sure your table has a header row ** {{{|Name|Phone Number|Address|h}}}
Note the /h/ that denote a header row * Give the table a class of 'sortable' ** {{{ |sortable|k |Name|Phone Number|Address|h }}}
Note the /k/ that denotes a class name being assigned to the table. * To disallow sorting by a column, place {{{<>}}} in it's header * To automatically sort a table by a column, place {{{<>}}} in the header for that column ** Or to sort automatically but in reverse order, use {{{<>}}} !!Example: |sortable|k |Name |Salary |Extension |Performance |File Size |Start date |h |ZBloggs, Fred |$12000.00 |1353 |+1.2 |74.2Kb |Aug 19, 2003 21:34:00 | |ABloggs, Fred |$12000.00 |1353 |1.2 |3350b |09/18/2003 | |CBloggs, Fred |$12000 |1353 |1.200 |55.2Kb |August 18, 2003 | |DBloggs, Fred |$12000.00 |1353 |1.2 |2100b |07/18/2003 | |Bloggs, Fred |$12000.00 |1353 |01.20 |6.156Mb |08/17/2003 05:43 | |Turvey, Kevin |$191200.00 |2342 |-33 |1b |02/05/1979 | |Mbogo, Arnold |$32010.12 |2755 |-21.673 |1.2Gb |09/08/1998 | |Shakespeare, Bill |£122000.00|3211 |6 |33.22Gb |12/11/1961 | |Shakespeare, Hamlet |£9000 |9005 |-8 |3Gb |01/01/2002 | |Fitz, Marvin |€3300.30 |5554 |+5 |4Kb |05/22/1995 | ***/ // /% //!BEGIN-PLUGIN-CODE config.tableSorting = { darrow: "\u2193", uarrow: "\u2191", getText : function (o) { var p = o.cells[SORT_INDEX]; return p.innerText || p.textContent || ''; }, sortTable : function (o,rev) { SORT_INDEX = o.getAttribute("index"); var c = config.tableSorting; var T = findRelated(o.parentNode,"TABLE"); if(T.tBodies[0].rows.length<=1) return; var itm = ""; var i = 0; while (itm == "" && i < T.tBodies[0].rows.length) { itm = c.getText(T.tBodies[0].rows[i]).trim(); i++; } if (itm == "") return; var r = []; var S = o.getElementsByTagName("span")[0]; c.fn = c.sortAlpha; if(!isNaN(Date.parse(itm))) c.fn = c.sortDate; else if(itm.match(/^[$|£|€|\+|\-]{0,1}\d*\.{0,1}\d+$/)) c.fn = c.sortNumber; else if(itm.match(/^\d*\.{0,1}\d+[K|M|G]{0,1}b$/)) c.fn = c.sortFile; for(i=0; i