DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:sortablejs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
plugin:sortablejs [2016-05-26 21:18] vaxquisplugin:sortablejs [2017-10-27 22:32] Aleksandr
Line 3: Line 3:
 ---- plugin ---- ---- plugin ----
 description: JavaScript for sortable tables description: JavaScript for sortable tables
-author     : vaxquis+author     : vaxquis (AKA FyiurAmron)
 email      : spamove@gmail.com email      : spamove@gmail.com
 type       : syntax type       : syntax
-compatible : anteaterangua, Rincewind, adora belle, Weatherwax, Binky, 2014-05-05 "Ponder Stibbons", 2014-09-29 "Hrun" +compatible : AnteaterAngua, Rincewind, Adora Belle, Weatherwax, Binky, 2014-05-05 "Ponder Stibbons", 2014-09-29 "Hrun", 2016-06-26 
 depends    : depends    :
 conflicts  : cellbg conflicts  : cellbg
 similar    : similar    :
 tags       : javascript, tables, sort, listing tags       : javascript, tables, sort, listing
-downloadurl: https://github.com/oiv/sortablejs/zipball/master +downloadurl: https://github.com/FyiurAmron/sortablejs/zipball/master 
-sourcerepo : https://github.com/oiv/sortablejs +sourcerepo : https://github.com/FyiurAmron/sortablejs 
-bugtracker : https://github.com/oiv/sortablejs/issues+bugtracker : https://github.com/FyiurAmron/sortablejs/issues 
 +----
  
 ===== Description ===== ===== Description =====
  
-This plugin adds a JavaScript, which can be used to create sortable tables in other plugins. It is optional for [[linkmanager]] plugin.+JavaScript-based (client-side) plugin, which can be used to create sortable tables. It is optional for [[linkmanager]] plugin.  
 + 
 +For server-side sorting or more robust sort facilities use Sam Wilson's sorter, based on https://github.com/Mottie/tablesorter (supports server-side sorting): https://github.com/samwilson/dokuwiki_sortablejs 
 + 
 +Previously maintained by oiv (Otto Vainio at otto@valjakko.net)
  
 ===== Usage ===== ===== Usage =====
Line 56: Line 61:
  
 <code> <code>
-<sortable [[r]column] [sumrow[=2]] [column=alpha|numeric|ddmm|mmdd|nosort] [3phase]>+<sortable [[r]column] [sumrow[=2]] [column=alpha|numeric|date|nosort] [3phase]>
  
   <sortable r1 sumrow=2 3phase 1=numeric 2=alpha 3=nosort>   <sortable r1 sumrow=2 3phase 1=numeric 2=alpha 3=nosort>
Line 69: Line 74:
 </code> </code>
  
-===== Older versions ===== +===== Misc links =====
-historical: https://github.com/FyiurAmron/sortablejs/wiki/older-versions +
-GitHub revision history: https://github.com/FyiurAmron/sortablejs/commits/master +
- +
-===== Known bugs ===== +
-  * When having multiple tables in one page, the up/down arrow is not displayed correctly on all tables. Only on the last table sorted. +
-  * The arrow is not displayed by default, so impossible to make the difference between sortable and normal table +
-Please feel free to report more found bugs or suggestions.  --- //[[otto@valjakko.net|Otto Vainio]] 2009/01/14 10:16// +
-  * With merged rows it acts erratically so you can't really have a caption or title row for the table. +
-  * There is a formatting problem when exporting code blocks with the [[plugin:odt|ODT plugin]] that contain sortable tags. For example, this<code><sortable> +
-^Last Name  ^First Name  ^Height in inches +
-|Smith  |Joe  |100  | +
-|Doe  |Jane  |80  | +
-|Thompson  |Hunter  |110  | +
-|Dylan  |Robert  |105  | +
-|Takemitsu  |Toru  |130  | +
-|Barrueco  |Manuel  |95  | +
-</sortable></code>will not be exported with proper code block formatting in an ODT document. It is unclear whether this is an bug the the ODT plugin or with the sortablejs plugin. +
- +
-  * Initially sorting by column 10 (or greater) doesn't work. For example: This table should be initially reverse sorted by column 12, but it's sorted by col.1. <code><sortable r12> +
-^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^ +
-|1 |1 |1 |1 |1 |1 |1 |1 |1 |3 |3 |3 | +
-|1 |1 |1 |1 |1 |1 |1 |1 |1 |1 |1 |1 | +
-|1 |1 |1 |1 |1 |1 |1 |1 |1 |2 |2 |2 | +
-</sortable></code>--- //Chris// +
- +
-== Changelog == +
- +
-[[https://github.com/FyiurAmron/sortablejs/wiki/old-changelog|old changelog]] +
-[[https://github.com/FyiurAmron/sortablejs/commits/master|recent commits]] +
-===== Discussion ===== +
- +
-  * <del>When the <sortable> tag is added, **all** tables on the page are made sortable. When two sortable tags are defined, ascending sorting will not occur anymore. Both are caused by an error in the JavaScript: The ''makeSortablediv'' function gets all table elements from the //document// instead of from the //DIV//.</del> +
-    * <del>Solution: Change line 77 ''document.getElementsByTagName('table')'' to ''div.getElementsByTagName('table')''  --- //[[splitbrain@sampiemon.xs4all.nl|Hans Sampiemon]] 2008/11/27 12:26//</del> +
-  * Thanks for the report. This is now fixed in the new (2.1) version.  --- //[[otto@valjakko.net|Otto Vainio]] 2008/11/27 13:10// +
-  * <del>I got this working and it is very nice.  I would like to have the ability to sort tables a certain way by default.  I tried to hack something in there by putting some JavaScript in when the table header was created, but I don't think I was getting the timing right.  If you are working on this any more, it would be a handy addition. </del>  +
-  * <del>I am also looking for the ability to sort tables a certain way by default. Would be nice if you could add this.</del> +
-  * <del>I will also put in my 2 cents and say it would be fantastic if there was a default sort.</del> +
----- +
- +
-  * The [[plugin:pagelist]] plugin can generate tables with a creation date or a modification date. Typically this date will be in format "DD-MM-YYYY HH:MM". The script doesn't recognize this as a date field. For universal usage, using ''$conf['dformat']'' as the format recognized would be the perfect solution. --- //[[splitbrain@sampiemon.xs4all.nl|Hans Sampiemon]] 2008/11/27 14:26//  +
-Actually I think the script has a even better solution. It tries to guess the date format. The current version only understands following dates +
- +
-|dd/mm/yyyy|dd.mm.yyyy|dd-mm-yyyy| +
-|mm/dd/yyyy|mm.dd.yyyy|mm-dd-yyyy| +
-|dd/mm/yy|dd.mm.yy|dd-mm-yy| +
-|mm/dd/yy|mm.dd.yy|mm-dd-yy| +
- +
-If the date is something, where it is impossible to guess the format (dd-mm or mm-dd) like 3-3-2003, then it assumes dd-mm. +
- +
- +
-I have a new version (not yet released), which understands  hh:mm after the date... should probably add . (comma) as a time separator also.  +
- --- //[[otto@valjakko.net|Otto Vainio]] 2008/11/27 17:59// +
-> Although I understand why you would like the ultimate flexibility, I wonder if it is really needed. Whereas dates are quite common, timestamps are very rarely entered by humans. Generally they will be computer generated and if the are, you would expect them in the format defined by ''$conf['dformat']''. --- //[[splitbrain@sampiemon.xs4all.nl|Hans Sampiemon]] 2008/12/01 15:06// +
- +
->> This script is originally built by  Stuart Langridge, [[http://www.kryogenix.org/code/browser/sorttable/]] I have only changed it to work with DokuWiki.(and some small changes). It had these date formats build in. I think it would require more changes to make it to recognize a PHP variable in JavaScript. It __can__ be done, but...  --- //[[otto@valjakko.net|Otto Vainio]] 2008/12/01 17:03// +
->>> And one more thing. Handling ''$conf['dformat']'' would require to code a parser to handle strftime format  --- //[[otto@valjakko.net|Otto Vainio]] 2008/12/01 17:25// +
- +
-  * If a cell is empty, the column that contains that cell will not allow sorting. --- //[[josef.var@gmail.com|Josef Rovira]] 2008/12/12//  +
-    * I had a complete line with empty cells. Sorting works only with row1, even if I used <code><sortable 3 1=alpha 2=alpha 3=alpha></code>. By deleting the empty line, sortablejs-plugin works fine. ---//[[frie.sen@pet.er|friesenpeter]] 2012/02/23// +
- +
- +
- +
----- +
- +
-I test the sortable.js, and found some errors. +
- +
-Mixing of Types don't work. +
- +
-<code> +
-^Test1 +
-|BB    | +
-|      | +
-|10    | +
-|      | +
-|AA    | +
-|      | +
-|DD    | +
-</code> +
- +
- +
-After this, no table can by sorted anymore. +
- +
-<code> +
-^Test2  ^Test2 +
-|BB    |BB    | +
-|AA    || +
-</code> +
- +
- +
-(If possible, could by useful to sort, sort-down > sort-up > no-sort ...) +
- +
-> This can be found in version 2.9  +
- +
- +
->> I've done some tests and this is what I found out: If you have numbers and words in the column you want to sort, you should set the type of the column to 'alpha'. Otherwise it won't work properly. Another thing I realized is that the sorting algorithm is case sensitive. Lower case words are sorted separately at the end. It would be great to have a choice here.  --- [[user>mja|Moni]] //2012/10/23 14:45// +
- +
- +
-**Quick and dirty fix for mixed Formats in Columns:** The Problem is, that the plugin will use a numeric sort if there is //only one cell// that has only numers in it. The following code will cause the plugin to only use the numeric sorting if all columns are numeric. Additionally, this code will enable the sorting of dates, which use a point as delimiter instead of a / +
-<code> +
-guessType: function(table, column) { +
-    // guess the type of a column based on its first non-blank row +
-    sortfn = sorttable.sort_alpha; +
-    for (var i=0; i<table.tBodies[0].rows.length; i++) { +
-      text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); +
-      if (text !== '') { +
-        // check for a date: dd/mm/yyyy or dd/mm/yy  +
-        // can have / or . or - as separator +
-        // can be mm/dd as well +
-        possdate = text.match(sorttable.DATE_RE); +
-        if (possdate) { +
-          // looks like a date +
-          first = parseInt(possdate[1]); +
-          second = parseInt(possdate[2]); +
-          if (first > 12) { +
-            // definitely dd/mm +
-            return sorttable.sort_ddmm; +
-          } else if (second > 12) { +
-            return sorttable.sort_mmdd; +
-          } else { +
-            // looks like a date, but we can't tell which, so assume +
-            // that it's dd/mm (English imperialism!) and keep looking +
-            sortfn = sorttable.sort_ddmm; +
-          } +
-        } +
-      } +
-    } +
-    if ( sortfn == sorttable.sort_alpha ) +
-    { +
-     for (var i=0; i<table.tBodies[0].rows.length; i++) { +
-       text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); +
-       if (text !== '') { +
-         if (text.match(/^-?[£$€]?[\d,.]+%?$/)) { +
-         sortfn = sorttable.sort_numeric; +
-         } +
-         else +
-         return sorttable.sort_alpha +
-       } +
-        } +
-    } +
-    return sortfn; +
-  }, +
-</code> +
- +
----- +
- +
-  * It would be great if the plug-in could sort links using their description and not their ''href''. I tried something like ''.replace(/<a .*?href=".*?".*?>(.*?)<\/a>/,'$1')'' in ''getInnerText'' function but failed in finding the right place for it.  --- //djib 2009/02/19 14:36//   +
- +
----- +
-The following table doesn't seem to work as I would expect: +
-<code> +
-^Hostname^IP^ +
-|foo1|192.168.1.251| +
-|foo2|192.168.1.250| +
-|foo3|192.168.1.249| +
-|foo4|192.168.1.248| +
-|foo5|192.168.1.247| +
-|foo6|192.168.1.246| +
-|foo7|192.168.1.245| +
-|foo8|192.168.1.244| +
-|foo9|192.168.1.243| +
-|foo10|192.168.1.242| +
-|foo11|192.168.1.241| +
-|foo12|192.168.1.240| +
-</code> +
-I can't figure out what the sorting method is used if you sort by the "IP" column  --- //JonV 2009/03/11 10:23// (fixed sig) +
-> Almost 2 years later and this problem still exists. Anyone have any insight before I plug away at fixing this myself? -Mike +
->> What is the problem? I tried and the table above sorts correctly. And the question being "what the sorting method is used". Did you notice that you can now force a sorting method (alpha|numeric|ddmm|mmdd|nosort). If you have a patch for sorting IP address I would be glad if you can send it. I can add it to the plugin.  --- [[user>oiv]] //2011/02/07 08:37// +
->>> Ah, yes, it works now.  I hadn't updated the plugin in a while, but works as expected.  Thank you, oiv!   --- [[user>erple2|JonV]] //2011/10/14 18:38// +
->>>>Sorting IP Addresses is still not working for me. I've been trying to create a new function but have been unsuccessful. Is there a patch for sorting IPs? --Josh //2012/01/25 20:55// +
->>>>>I seem to have fixed the sorting for IP Addresses. Big thanks to Old Pedant at codingforums dot com for the help on the last part. ---Josh //2012/01/25 21:40// +
-==== Sorting by IP Address ==== +
-**Altered this section to check if text was an IP address before checking for numeric ** +
-<code javascript> +
-guessType: function(table, column) { +
-    // guess the type of a column based on its first non-blank row +
-    sortfn = sorttable.sort_alpha; +
-    for (var i=0; i<table.tBodies[0].rows.length; i++) { +
-      text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); +
-      if (text !== '') { +
-        // check for a date: dd/mm/yyyy or dd/mm/yy  +
-        // can have / or . or - as separator +
-        // can be mm/dd as well +
-        possdate = text.match(sorttable.DATE_RE);  // first check for date +
-        if (possdate) { +
-          // looks like a date +
-          first = parseInt(possdate[1]); +
-          second = parseInt(possdate[2]); +
-          if (first > 12) { +
-            // definitely dd/mm +
-            return sorttable.sort_ddmm; +
-          } else if (second > 12) { +
-            return sorttable.sort_mmdd; +
-          } else { +
-            // looks like a date, but we can't tell which, so assume +
-            // that it's dd/mm (English imperialism!) and keep looking +
-            sortfn = sorttable.sort_ddmm; +
-          } +
-        } else if (text.match(/^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/)) {  // now for ip-addresses +
-          return sorttable.sort_ipaddr; +
-        } else if (text.match(/^-?[£$¤]?[\d,.]+%?$/)) {  // now for numeric +
-          return sorttable.sort_numeric; +
-        } +
-      } +
-    } +
-    return sortfn; +
-  }, +
-</code> +
-**Added this section at line 471. This created the sort_ipaddr function which turns the string into an array by splitting at the '.' then it compares each octet.** <sub>Thank You Old Pedant @ codingforums for the help with this last part.</sub> +
-<code javascript> +
-sort_ipaddr: function(a,b){ +
- aa = a[0].split(".",4); +
- bb = b[0].split(".",4); +
-  +
- var resulta = aa[0]*0x1000000 + aa[1]*0x10000 + aa[2]*0x100 + aa[3]*1; +
-        var resultb = bb[0]*0x1000000 + bb[1]*0x10000 + bb[2]*0x100 + bb[3]*1; +
-  +
- return resulta-resultb; +
-  }, +
-</code> +
- +
- +
- +
- +
- +
----- +
- +
-I use  the [[plugin:csv]] plugin to create basic tables on some pages, but wrapping them with sortable tags doesn't work.  No errors appear, but no sortability either. Some kind of plugin interaction maybe?  Using basic DokuWiki table tags does work, so the plugin is correctly installed.  Anyone have experience in making these two play together nicely?  --- //RobV 2009/05/30 22:24// +
- +
->For me "csv" and "sortable" work fine together - it needs some time before the effect is shown. "Sortable" works with "csv" hold in "Media-Collection" as well as in page-stored csv. But I considered a different behavior of searchengine: If I store my csv-file in mediacenter, the content isn't searchable! If I store the csv in the page, the search engine finds the content!\\ //utaf 2009/06/11// +
- +
->It also worked for me with the "csv" plugin.  Gimili17 2009/11/19.  What a great plugin! +
- +
----- +
- +
-Even though its supposed to work for all tables – “just add <sortable> before and </sortable> after…”, if there are headings in between the tables, these don’t show up in the TOC (or at least it seems that only the first heading shows up). +
- +
-> %%<sortable>%% +
-> heading +
-> table 1 +
-> heading +
-> table 2 +
-> %%</sortable>%% +
- +
--- UA 2009-07-10 +
- +
- +
----- +
- +
-For me the sorting with dates that have a point as delimiter didn't work. The problem is that these dates are recognized by the guessType-function as numeric. A quick and dirty fix would be to first check if it's a date and only afterwards check for numeric: +
-<code javascript> +
-  guessType: function(table, column) { +
-    // guess the type of a column based on its first non-blank row +
-    sortfn = sorttable.sort_alpha; +
-    for (var i=0; i<table.tBodies[0].rows.length; i++) { +
-      text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); +
-      if (text !== '') { +
-        // check for a date: dd/mm/yyyy or dd/mm/yy  +
-        // can have / or . or - as separator +
-        // can be mm/dd as well +
-        possdate = text.match(sorttable.DATE_RE);  // first check for date +
-        if (possdate) { +
-          // looks like a date +
-          first = parseInt(possdate[1]); +
-          second = parseInt(possdate[2]); +
-          if (first > 12) { +
-            // definitely dd/mm +
-            return sorttable.sort_ddmm; +
-          } else if (second > 12) { +
-            return sorttable.sort_mmdd; +
-          } else { +
-            // looks like a date, but we can't tell which, so assume +
-            // that it's dd/mm (English imperialism!) and keep looking +
-            sortfn = sorttable.sort_ddmm; +
-          } +
-        } else if (text.match(/^-?[£$¤]?[\d,.]+%?$/)) {  // now for numeric +
-          return sorttable.sort_numeric; +
-        } +
-      } +
-    } +
-    return sortfn; +
-  }, +
-</code> +
- +
--- garee 2009-09-18 +
----- +
- +
-==== Ignore case option ==== +
-  * I have a question: is there any way to sort a table with **"ignore case"** option? for example:  +
- +
-| Auto  | +
-| casa  | +
-| Dato  | +
-| fin   | +
--- Damian 2009-10-07 +
- +
-> Not with the current version. Sorry  --- //[[otto@valjakko.net|oiv]] 2009/11/05 07:22// +
- +
->> After almost three years I found the answer of my question above, two lines of the script must be changed, see: +
->> http://www.kryogenix.org/code/browser/sorttable/#insensitive  +
->> --- [[user>damgut|damgut]] //2012/06/20 09:50// +
- +
->>> Hi there, I just started using sortable and I actually have the same issue. Let's say I want to make a table consisting of things I own, the //iPad// would come after my //Zebra// instead of being grouped with my //Intercom// (strange set of things, I know..). Considering the simple change it takes in the js file, I think it would be great, Otto, if you would consider updating sortable to offer an option to ignore case. ---//Viktor 2015/08/19// +
- +
----- +
-For some reason the plugin isn't working for me at all. You can see what I mean [[http://neuroanalysis.org/wiki/doku.php/installation:platforms|here]]. The syntax <sortable> is clearly recognized, since it's not output as text, but the table isn't sorted, nor sortable. This is dokuwiki version 2009-02-14b, with the additional [[plugin:indexmenu]], [[plugin:wrap]], and [[plugin:swiftmail]] plugins. Any suggestions? --- Michael Repucci 2009-11-04 +
- +
-> Seems to work perfectly  --- //[[otto@valjakko.net|oiv]] 2009/11/05 07:22// +
- +
->> Thank you for checking! Perhaps this is a fault in my expectations. I cleared my local cache, and touch'ed conf/local.php, and sortable doesn't seem to respect the initial sort parameter (e.g., <sortable r1>). Did I misunderstand how to use this parameter? Also, I'd expected that the arrow would show up upon refresh (or the first visit to a page) to indicate this initial sorting, and to cue the user that the column headers may be clicked on to sort the table, but it isn't there. It took me a while to realize, without the arrow, that I could click on the headers to sort them. But you're right, it does actually work. --- //[[michael@repucci.org|Michael Repucci]] 2009/11/05 14:05// +
- +
----- +
-I see a problem when clicking on a non-existing link in the table, then creating the page: the (now existing) link is not displayed as such... probably a problem of meta-data not being built. +
- +
-Removing the "sortable" tag and updating the page fixes it... but I don't want to do it each time I create a page. You may want to try by changing the name of the links below to some non existing page in the playground... --- //[[berteh@hotmail.com|berteh]] 2009/11/27// +
-<code> +
-<sortable> +
-^ T1 ^ T2 ^ +
-| [[playground:non existing page1]] | [[playground:non existing page 2]] | +
-</sortable> +
-</code> +
- +
----- +
- +
-I believe I may have found a bug in the way sortablejs changes how footnotes work. Normally, the notes within a sortable table are collected and shown at the bottom of the sortable table, and all other notes are shown at the bottom of the page. While the notes are appearing correctly at both places, the pop-up text and links in-document repeat the info from the sortable table footnotes. +
- +
-This is sort of hard to explain, so I'll just show some sample code and you can take a look. +
- +
-  <sortable> +
-  ^  Sortable Table  ^ +
-  |  contents((footer for the sortable table)) +
-  </sortable> +
-   +
-  Normal Text((footer for the normal text)) +
- +
-For me, both hovers will show the "footer for the sortable table" text, because they both have the #fnt__1 id I think. Can anyone confirm this? --- //kououken 2010/01/21 07:41// +
- +
-> //notes within a sortable table are collected and shown at the bottom of the sortable table// looks similar to a phenomenon that seems to be rather a **BUG**: if there is a blank line between the table and the closing ''</sortable>'' then any footnote up to that point is printed, followed by page content with "regular" footnotes for the whole page at the page's end (including that one already printed out by sortablejs as described) - maybe that rose from a former feature, but that way sortablejs is unusable with the current [[plugin:editTable]] plugin that often leaves blank lines at the end of tables (not investigated editTable's code for that yet, but you surely cannot blame editTable here) --- [[user>hh lohmann|hh lohmann]] //2014/03/11 14:08// +
- +
------ +
- +
-It's not possible to sort tables with joined cells. Try the following code to see what i mean: +
- +
-<code> +
-<sortable> +
-^ XXX ^ YYY ^ +
-| AAA | 111 | +
-| ::: | 222 | +
-| CCC | 333 | +
-</sortable> +
-</code> +
- +
---- //winky 2010/09/07 12:47// +
- +
------ +
- +
-There is a problem with default order at first visit if you use a table with align. +
- +
-For example +
-<code> +
- <sortable r1> +
-^  center  ^left algin  ^ +
-| AAA | 111 | +
-| BBB | 222 | +
-| CCC | 333 | +
- </sortable> +
-</code> +
- +
-The reason is a change of class. Script search just for "row[0]" but with table align the class is "col0 centeralign" or something else. +
- +
-To fix this problem just a small change is wanted: +
- +
-<code> +
-  defaultSort: function(table, colid, revs) { +
-    theadrow = table.tHead.rows[0].cells; +
-    colid--; +
-    colname ="col"+colid; +
-     // remove sorttable_sorted classes +
-     var thiscell=false; +
-     forEach(theadrow, function(cell) { +
-       if (cell.className==colname) //  <-------------------------- this line is the problem +
-       { +
-         thiscell=cell; +
-       } +
-</code> +
- +
-Better use this: +
- +
-<code> +
-  defaultSort: function(table, colid, revs) { +
-    theadrow = table.tHead.rows[0].cells; +
-    colid--; +
-    colname ="col"+colid; +
-     // remove sorttable_sorted classes +
-     var thiscell=false; +
-     forEach(theadrow, function(cell) { +
-       colclass=cell.className;                +
-       classname = colclass.split(" ");        +
-       if (classname[0]==colname)              +
-       { +
-         thiscell=cell; +
-       } +
-</code> +
- +
-After change this you can use a table with alignment at head and default sortable function. +
- +
---- //knutistgut 2010/09/22 // +
- +
-> Thanks. Applied you patch. v 2.3a --- [[user>oiv]] //2010/11/19 14:37// +
->> Thanks for including my created&sent patch that fast --- [[user>rauschen]] //2010/11/21 18:16// +
- +
- +
-==== IE8 problem with multiple tables==== +
- +
-I’m using your excellent sortablejs plugin and I’ve run into a problem with multiple tables on one page in ie8/windows7. Not sure if it is only related to ie8, but your script works on my w7 machine in chrome/firefox and on linux in chrome/firefox. +
- +
-The error message I get is this: +
- +
-  Object doesn't support this property or method +
-  Line 1 character64845 +
- +
-The code it refers to is compressed so it’s hard to get at the line numbers properly, but M$ developer tools puts the cursor at this spot: +
- +
-<code> +
-if(colid.search(/\bsort/)!=-1){ +
- colid=colid.replace('sortable',''); +
- colid=colid.replace(' sort',''); #Error spot is at end of this line according to MS dev tools +
- colid=colid.trim(); +
- revs=false; +
-</code> +
- +
-Wrapping the colid.trim() call in an if statement seems to help: +
-<code> +
-if(colid != '') { +
- colid=colid.trim(); +
-+
-</code> +
---- [[aages@imr.no|Åge Strand]] //2011/01/26 14:19// +
- +
-> Applied you patch to the latest release (2.5). I don't have IE8 or Windows 7 so cannot test. Hope it works. +
- +
-==== Firefox 7 Problem ==== +
-For me with Firefox7 (Beta) the plugin dont work: http://1wiki.de/doku.php/medien:musik +
- +
-In the Error Log of Firefox i only found this: +
-Fehler: event is undefined +
-Quelldatei: http://1wiki.de/lib/exe/js.php?tseed=1316953764 +
-Zeile: 213 +
- +
-With IE there is no problem.  +
- +
-==== Update ==== +
- +
-I delete some of you "features" and add some real ones, and maybe some new "features"/bugs too..(?) ;-) +
- +
-<file javascript sortablejs.js> +
-/* +
-        SortTable +
- +
-  version 2.1 +
-  2007.04.07 +
-  Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/ +
- +
-  2008.02.19 +
-  Fixed some jslint errors to support DokuWiki (http://www.splitbrain.org) js compression +
- +
-  function reinitsort() +
-  sorttable.reinit +
-  added by Otto Vainio to allow sort tables updated with javascript. +
-  Otto Vainio (otto@valjakko.net) +
- +
-  2008.11.27 +
-  Changed line 77 document.getElementsByTagName('table') to div.getElementsByTagName('table'+
-  To allow multiple sortable tables in same page +
-  (Thanks to Hans Sampiemon) +
- +
-  2009.01.14 +
-  Added option for default sorting. +
-  Use dokuwiki event registration. +
- +
-  2009.01.27 +
-  Cleaned some jlint errors to make this workable, when css+js compress is set in dokuwiki +
- +
-  2011.05.10 +
- * version 2.5 Fixed problems with secionediting, footnotes and edittable +
- +
-  2012.05.04 +
- * version 3.0 +
-   sortmode (down->up->no->...) (need class="row<num>"+
-   IP sorting +
-   sort method improvement +
-   some corrections +
- +
-  Instructions: +
-  Used from dokuwiki +
-  Click on the headers to sort +
- +
-  Thanks to many, many people for contributions and suggestions. +
-  Licenced as X11: http://www.kryogenix.org/code/browser/licence.html +
-  This basically means: do what you want with it. +
-*/ +
- +
-//var stIsIE = /*@cc_on!@*/false;   // Not needed (when we all stop to clean behind ie?!) +
-var sortchr_down = '&nbsp;&darr;'; //stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;'; +
-var sortchr_up = '&nbsp;&uarr;'; //stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;'; +
-var sortchr_no = '&nbsp;&minus;'; +
- +
-var tableid = 0; +
- +
-sorttable = { +
-  reinit: function() { +
-    sorttable.initial(); +
-  }, +
-  init: function() { +
-    sorttable.initial(); +
-  }, +
- +
-  initial: function() { +
- +
-    // quit if this function has already been called +
-    if (arguments.callee.done) {return;} +
-    // flag this function so we don't do the same thing twice +
-    arguments.callee.done = true; +
-    // kill the timer +
-    if (_timer) {clearInterval(_timer);+
- +
-    if (!document.createElement || !document.getElementsByTagName) {return;} +
- +
-    // 1900-2039 +
-    sorttable.DATE_YYMMDD = /^(19\d\d|20[0-3]\d|\d\d)[\/\.\-\\]([0]?[1-9]|[1][012])[\/\.\-\\]([0]?[1-9]|[12]\d|[3][01])( (\d\d?):?(\d\d?)(:?(\d\d?)?))?$/;  //Date YYYY-MM-DD, Like every number! Big->Smal !! (We call common stupidity tradition: MM-DD-YYYY, DD-MM-YYYY) +
-    sorttable.DATE_DDMMYY = /^([0]?[1-9]|[1][012])[\/\.\-\\]([0]?[1-9]|[12]\d|[3][01])[\/\.\-\\](19\d\d|20[0-3]\d|\d\d)( (\d\d?):?(\d\d?)(:?(\d\d?)?))?$/; +
-    sorttable.DATE_MMDDYY = /^([0]?[1-9]|[12]\d|[3][01])[\/\.\-\\]([0]?[1-9]|[1][012])[\/\.\-\\](19\d\d|20[0-3]\d|\d\d)( (\d\d?):?(\d\d?)(:?(\d\d?)?))?$/; +
-    //sorttable.DATE_RE = /^((\d\d)?\d\d)[\/\.\-\\](\d\d?)[\/\.\-\\](\d\d?)( (\d\d?):?(\d\d?)(:?(\d\d?)?))?$/; +
- +
-    forEach(document.getElementsByTagName('table'), function(table) { +
-      if (table.className.search(/\bsortable\b/) >= 0) { +
-        sorttable.makeSortable(table); +
-      } +
-    }); +
-    forEach(document.getElementsByTagName('div'), function(div) { +
-      if (div.className.search(/\bsortable\b/) >= 0) { +
-        sorttable.makeSortablediv(div); +
-      } +
-    }); +
-  }, +
- +
-  makeSortablediv: function(div) { +
-        if (div.getElementsByTagName('table').length === 0) { +
-        } else { +
-          forEach(div.getElementsByTagName('table'), function(table) { +
-            sorttable.makeSortable(table); +
-            if (colid.search(/\bsort/) >= 0) { +
-              colid = colid.replace('sortable',''); +
-              colid = colid.replace(' sort',''); +
-              if (!colid != '') { +
-                colid = colid.trim(); +
-              } +
-              revs=false; +
-              if (colid.search(/\br/) >= 0) { +
-                revs=true; +
-                colid = colid.replace('r',''); +
-              } +
-              sorttable.defaultSort(table,colid,revs); +
-            } +
-          }); +
- +
-        } +
-  }, +
- +
-  defaultSort: function(table, colid, revs) { +
-//    theadrow = table.tHead.rows[0].cells; +
-    theadrow = table.rows[0].cells; +
-    colid--; +
-    colname ="col"+colid; +
-     // remove sorttable_sorted classes +
-     var thiscell=false; +
-     forEach(theadrow, function(cell) { +
-       colclass=cell.className; +
-       classname = colclass.split(" "); +
-//       if (cell.className==colname) { +
-       if (classname[0]==colname) { +
-         thiscell=cell; +
-       } +
-     }); +
-     if (thiscell===false) {return;} +
- +
-     sorttable.sortit(thiscell, 0); +
-     if (revs) sorttable.sortit(thiscell, 2); +
-  }, +
- +
-  makeSortable: function(table) { +
-//    tableid++; +
-/* +
-    if (table.getElementsByTagName('thead').length === 0) { +
-      // table doesn't have a tHead. Since it should have, create one and +
-      // put the first table row in it. +
-      the = document.createElement('thead'); +
-      the.appendChild(table.rows[0]); +
-      table.insertBefore(the,table.firstChild); +
-    } +
- +
-    // Safari doesn't support table.tHead, sigh +
- +
-    if (table.tHead === null) {table.tHead = table.getElementsByTagName('thead')[0];+
- +
-    if (table.tHead.rows.length != 1) {return;} // can't cope with two header rows +
- +
-//    table.tHead.className += ' tableid'+tableid; +
- +
-    // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as +
-    // "total" rows, for example). This is B&R, since what you're supposed +
-    // to do is put them in a tfoot. So, if there are sortbottom rows, +
-    // for backwards compatibility, move them to tfoot (creating it if needed). +
-    sortbottomrows = []; +
-    for (var i=0; i<table.rows.length; i++) { +
-      if (table.rows[i].className.search(/\bsortbottom\b/) != -1) { +
-        sortbottomrows[sortbottomrows.length] = table.rows[i]; +
-      } +
-    } +
-    if (sortbottomrows) { +
-      if (table.tFoot === null) { +
-        // table doesn't have a tfoot. Create one. +
-        tfo = document.createElement('tfoot'); +
-        table.appendChild(tfo); +
-      } +
-      for (var ii=0; ii<sortbottomrows.length; ii++) { +
-        tfo.appendChild(sortbottomrows[ii]); +
-      } +
-      delete sortbottomrows; +
-    } +
-*/ +
- +
-    //colid=div.className; +
-    colid=table.className; +
- +
-    overrides = new Array(); +
-    var patt1=/\bcol_\d_[a-z]+/gi; +
-    var overrides = new Array(); +
- +
-    if (colid.search(patt1) != -1) { +
-      var overrides = new Array(); +
-      overrides = colid.match(patt1); +
-      var xo=""; +
-      for (xo in overrides) { +
-        if (xo == "") { +
-        } else { +
-          try { +
-            var tmp = overrides[xo].split("_"); +
-            var ind = tmp[1]; +
-            var val = tmp[2]; +
-            overrides[ind]=val; +
-          } catch (e) { +
-          } +
-        } +
-      } +
-      colid = colid.replace(patt1,''); +
-    } +
- +
- +
-    // work through each column and calculate its type +
-//    headrow = table.tHead.rows[0].cells; +
-    headrow = table.rows[0].cells; +
-//    for (var i=0; i<headrow.length; i++) { +
-    for (i=0; i<headrow.length; i++) { +
-      // manually override the type with a sorttable_type attribute +
-      var colOptions=""; +
-      if (overrides[i+1]) { +
-        colOptions=overrides[i+1]; +
-      } +
-      if (!colOptions.match(/\bnosort\b/)) { // skip this col +
-        mtch = colOptions.match(/\b[a-z0-9]+\b/); +
-        if (mtch) { override = mtch[0]; } +
-        if (mtch && typeof sorttable["sort_"+override] == 'function') { +
-          headrow[i].sorttable_sortfunction = sorttable["sort_"+override]; +
-        } else { +
-          headrow[i].sorttable_sortfunction = sorttable.guessType(table,i); +
-        } +
- +
-        // make it clickable to sort +
-        headrow[i].sorttable_columnindex = i; +
-        headrow[i].sorttable_tbody = table.tBodies[0]; +
-//        dean_addEvent(headrow[i],"click", function(e) { +
-        addEvent(headrow[i],"click", function(e) { +
-          var sorttyp; +
-          if (this.className.search(/\bsorttable_sorted_down\b/) >= 0) { +
-            sorttyp = 2; +
-          } else if (this.className.search(/\bsorttable_sorted_up\b/) >= 0) { +
-            sorttyp = 3; +
-          } else if (this.className.search(/\bsorttable_sorted_no\b/) >= 0) { +
-            sorttyp = 1; +
-          } else { +
-            sorttyp = 0; +
-          } +
-          sorttable.sortit(this, sorttyp); +
-        }); // function(e) +
- +
-      } +
-    } +
-  }, +
- +
- +
-  //sortit: function(sortthis, sorttyp) { +
-  sortit: function(element, sorttyp) { +
- +
-    element.className = element.className.replace(/ *\bsorttable_sorted_\w+\b/, ''); +
- +
-    switch (sorttyp) { +
-      case 1: +
-        element.className += ' sorttable_sorted_down'; +
-        element.getElementsByTagName("span")[0].innerHTML = sortchr_down; +
- +
-      break; case 2: +
-        element.className += ' sorttable_sorted_up'; +
-        element.getElementsByTagName("span")[0].innerHTML = sortchr_up; +
- +
-      break; case 3: +
-        element.className += ' sorttable_sorted_no'; +
-        element.getElementsByTagName("span")[0].innerHTML = sortchr_no; +
- +
-      // Never Sorted, prepare content +
-      break; default: +
-        sorttyp = 0; +
-        theadrow = element.parentNode; +
-        //table.rows[0]; +
-        // remove sorttable_sorted classes +
-        forEach(theadrow.childNodes, function(cell) { +
-          if (cell.nodeType == 1) { // an element +
-            cell.className = cell.className.replace(/\bsorttable_sorted_.*\b/,''); +
-            //cell.className = cell.className.replace(/\bsorttable_sorted\b/,''); +
-            sortfwdind = cell.getElementsByTagName("span")[0]; +
-            if (sortfwdind) sortfwdind.parentNode.removeChild(sortfwdind); +
-          } +
-        }); +
- +
-        // Create span Char +
-        sortfwdind = document.createElement('span'); +
-        //sortfwdind.id = "sorttable_sortfwdind"; +
-        sortfwdind.innerHTML = sortchr_down; +
-        element.appendChild(sortfwdind); +
- +
-        // delete rowodd|roweven format-class, if present +
-        table = theadrow.parentNode; +
-        forEach(table.childNodes, function(row) { +
-          if (row.nodeType == 1) { // an element +
-            row.className = row.className.replace(/ *\b(rowodd|roweven)\b/, ''); +
-          } +
-        }); +
- +
-        element.className += ' sorttable_sorted_down'; +
-        //element.getElementsByTagName("span")[0].innerHTML = sortchr_down; +
-    } +
- +
- +
-    // Never sorted or sort_down, content to array +
-    if (sorttyp == 0 || sorttyp == 1) { +
-      /* build an array to sort. This is a Schwartzian transform thing, +
-         i.e., we "decorate" each row with the actual sort key, +
-         sort based on the sort keys, and then put the rows back in order +
-         which is a lot faster because you only do getInnerText once per row +
-      */ +
-      row_array = []; +
-      col = element.sorttable_columnindex; +
-      rows = element.sorttable_tbody.rows; +
-      for (var j=1; j<rows.length; j++) { +
-        if (col < rows[j].cells.length) { +
-          row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]]; +
-        } else { +
-          row_array[row_array.length] = ''; +
-        } +
-      } +
- +
-      // If you want a stable sort, use sorttable.shaker_sort, or unstable row_array.sort and comment out this one +
-      sorttable.shaker_sort(row_array, element.sorttable_sortfunction); // stable +
-      //row_array.sort(element.sorttable_sortfunction); // Not stable +
-    } +
- +
-    // inverse from Sorted down +
-    if (sorttyp == 2) { +
-      // if we're already sorted by this column, just reverse the table, which is quicker +
-      sorttable.reverse(element.sorttable_tbody); +
-    } +
- +
-    // No-Sort, restore order by row number +
-    if (sorttyp == 3) { +
-      /* build an array to sort. This is a Schwartzian transform thing, +
-         i.e., we "decorate" each row with the actual sort key, +
-         sort based on the sort keys, and then put the rows back in order +
-         which is a lot faster because you only do data once per row +
-      */ +
-      row_array = []; +
-      rows = element.sorttable_tbody.rows; +
-      for (var j=1; j<rows.length; j++) { +
-        row_array[row_array.length] = [rows[j].className.replace(/^.*?\brow(\d+)\b.*?$/g, '$1'), rows[j]]; +
-      } +
- +
-      // If you want a stable sort, use sorttable.shaker_sort, or unstable row_array.sort and comment out this one +
-      //sorttable.shaker_sort(row_array, element.sorttable_sortfunction); // stable +
-      row_array.sort(sorttable.sort_numeric); // Not stable +
-    } +
- +
-    if (sorttyp != 2) { +
-      tb = element.sorttable_tbody; +
-      for (var j3=0; j3<row_array.length; j3++) { +
-        tb.appendChild(row_array[j3][1]); +
-      } +
- +
-      delete row_array; +
-    } +
- +
-  }, +
- +
- +
-  guessType: function(table, column) { +
-    // guess the type of a column +
-    sortfn = sorttable.sort_alpha; +
- +
-    for (var i=1; i<table.tBodies[0].rows.length; i++) { // Strat at 2. row, 1. is title +
-      //if (i==0) {continue;} //BUGFIX for non equal col amount +
-      if (column >= table.tBodies[0].rows[i].cells.length) {continue;} //BUGFIX for non equal col amount +
-      text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]); +
-      text = text.replace(/^\s*(.*?)\s*$/g, '$1'); +
- +
-      if (text !== '') { +
-        if (text.match(/^[\+\-]?[£$¤%€ÿ]?([\d]+|[\d]*[\.,][\d]+|[\d]+[\.,][\d]*)E[\+\-]?\d+[£$¤%€ÿ]?$/)) { +
-          return sorttable.sort_numericexp; +
-        } else if (text.match(/^[\+\-]?[£$¤%€ÿ]?([\d]+|[\d]*[\.,][\d]+|[\d]+[\.,][\d]*)[£$¤%€ÿ]?$/)) { +
-          return sorttable.sort_numeric; +
-        } else if (text.match(/^\d{1,5}\.\d{1,5}\.\d{1,5}\.\d{1,5}$/)) { +
-          return sorttable.sort_ip; +
-        } +
-        /* check for a date: dd/mm/yyyy or dd/mm/yy +
-           can have / or . or - as separator +
-           can be mm/dd as well +
-        */ +
- +
-        possdate = text.match(sorttable.DATE_YYMMDD); +
-        if (possdate) return sorttable.sort_date; +
-        possdate = text.match(sorttable.DATE_DDMMYY); +
-        if (possdate) return sorttable.sort_date; +
-        possdate = text.match(sorttable.DATE_MMDDYY); +
-        if (possdate) return sorttable.sort_date; +
- +
-/* +
-        possdate = text.match(sorttable.DATE_RE); +
-        if (possdate) { +
-          // looks like a date +
-          first = parseInt(possdate[1]); +
-          second = parseInt(possdate[2]); +
-          if (first > 12) { +
-            // definitely dd/mm +
-            return sorttable.sort_date; +
-          } else if (second > 12) { +
-            return sorttable.sort_mmdd; +
-          } else { +
-            // looks like a date, but we can't tell which, so assume +
-            // that it's dd/mm (English imperialism!) and keep looking +
-            sortfn = sorttable.sort_date; +
-          } +
-        } else { +
-          return sorttable.sort_alpha; +
-        } +
-*/ +
- +
-      } +
-    } +
- +
-    return sortfn; +
-  }, +
- +
- +
-  getInnerText: function(node) { +
- +
-    // is a normal data, not a node +
-    if (typeof node == 'string') return node; +
-    if (typeof node == 'number') return node; +
-    if (typeof node == 'undefined') return ''; +
- +
-    /* gets the text we want to use for sorting for a cell. +
-       strips leading and trailing whitespace. +
-       this is *not* a generic getInnerText function; it's special to sorttable. +
-       for example, you can override the cell text with a customkey attribute. +
-       it also gets .value for <input> fields. +
-    */ +
-    hasInputs = (typeof node.getElementsByTagName == 'function') && node.getElementsByTagName('input').length; +
- +
-    if (node.getAttribute("sorttable_customkey") !== null) { +
-      return node.getAttribute("sorttable_customkey"); +
-    } else if (typeof node.textContent != 'undefined' && !hasInputs) { +
-      return node.textContent.replace(/^\s+|\s+$/g, ''); +
-    } else if (typeof node.innerText != 'undefined' && !hasInputs) { +
-      return node.innerText.replace(/^\s+|\s+$/g, ''); +
-    } else if (typeof node.text != 'undefined' && !hasInputs) { +
-      return node.text.replace(/^\s+|\s+$/g, ''); +
-    } else { +
-      switch (node.nodeType) { +
-        case 3: //text-node +
-          if (node.nodeName.toLowerCase() == 'input') { +
-            return node.value.replace(/^\s+|\s+$/g, ''); +
-          } +
-        case 4: //cdata-node +
-          return node.nodeValue.replace(/^\s+|\s+$/g, ''); +
-          break; +
-        case 1: //element-node +
-        case 11: //fragment-node +
-          var innerText = ''; +
-          for (var i = 0; i < node.childNodes.length; i++) { +
-            innerText += sorttable.getInnerText(node.childNodes[i]); +
-          } +
-          return innerText.replace(/^\s+|\s+$/g, ''); +
-          break; +
-        default: +
-          return ''; +
-      } +
-    } +
-  }, +
- +
- +
-  reverse: function(tbody) { +
-    // reverse the rows in a tbody +
-    newrows = []; +
-    for (var i=0; i<tbody.rows.length; i++) { +
-      newrows[newrows.length] = tbody.rows[i]; +
-    } +
-    for (var i=newrows.length-1; i>=1; i--) { +
-       tbody.appendChild(newrows[i]); +
-    } +
-    delete newrows; +
-  }, +
- +
- +
-  /* sort functions +
-     each sort function takes two parameters, a and b +
-     you are comparing a[0] and b[0] +
-  */ +
-  sort_alpha: function(a,b) { +
-    if (typeof a[0] == 'undefined' && typeof b[0] == 'undefined') { return 0; } +
-    if (typeof a[0] == 'undefined') { return 1; } +
-    if (typeof b[0] == 'undefined') { return -1; } +
- +
-    if (a[0]=='' && b[0]=='') { return 0; } +
-    if (a[0]=='') { return 1; } +
-    if (b[0]=='') { return -1; } +
- +
-    if (a[0]>b[0]) { return 1; } +
-    if (a[0]<b[0]) { return -1; } +
-    return 0; +
-  }, +
- +
- +
-  sort_numeric: function(a,b) { +
-    aa = parseFloat(a[0].replace(/[^0-9.\-]/g, '')); +
-    bb = parseFloat(b[0].replace(/[^0-9.\-]/g, '')); +
- +
-    if (isNaN(aa) && isNaN(bb)) { return sorttable.sort_alpha(a,b);+
-    if (isNaN(aa)) { return 1; } +
-    if (isNaN(bb)) { return -1; } +
- +
-    return aa-bb; +
-  }, +
- +
- +
-  sort_numericexp: function(a,b) { +
-    aa = Number(a[0].replace(/[^0-9E.\-]/g, '')); +
-    bb = Number(b[0].replace(/[^0-9E.\-]/g, '')); +
- +
-    if (isNaN(aa) && isNaN(bb)) { return sorttable.sort_alpha(a,b);+
-    if (isNaN(aa)) {return 1;} +
-    if (isNaN(bb)) {return -1;} +
- +
-    return aa-bb; +
-  }, +
- +
- +
-  sort_ip: function(a,b) { +
-    if (typeof a[0] == 'undefined' && typeof b[0] == 'undefined') { return sorttable.sort_alpha(a,b);+
-    if (typeof a[0] == 'undefined') {return 1;} +
-    if (typeof b[0] == 'undefined') {return -1;} +
- +
-    aa = a[0].replace(/\b(\d{2})\b/g, '0$1'); +
-    aa = aa.replace(/\b(\d{1})\b/g, '00$1'); +
-    bb = b[0].replace(/\b(\d{2})\b/g, '0$1'); +
-    bb = bb.replace(/\b(\d{1})\b/g, '00$1'); +
- +
-    if (aa>bb) {return 1;} +
-    if (aa<bb) {return -1;} +
-    return 0; +
-  }, +
- +
- +
-  sort_date: function(a,b) { +
-    if (typeof a[0] == 'undefined' && typeof b[0] == 'undefined') { return sorttable.sort_alpha(a,b);+
-    if (typeof a[0] == 'undefined') { return 1; } +
-    if (typeof b[0] == 'undefined') { return -1; } +
- +
-    dt1 = sorttable.date_format(a[0]); +
-    dt2 = sorttable.date_format(b[0]); +
- +
-    if (dt1>dt2) { return 1; } +
-    if (dt1<dt2) { return -1; } +
-    return 0; +
-  }, +
- +
- +
-  date_format: function(frm) { +
-    mtch = frm.match(sorttable.DATE_YYMMDD); +
-    if (mtch) { +
-      y = mtch[1]; m = mtch[2]; d = mtch[3]; +
- +
-    } else { +
-      mtch = frm.match(sorttable.DATE_DDMMYY); +
-      if (mtch) { +
-        y = mtch[3]; m = mtch[2]; d = mtch[1]; +
- +
-      } else { +
-        mtch = frm.match(sorttable.DATE_MMDDYY); +
-        if (mtch) { +
-          y = mtch[3]; m = mtch[1]; d = mtch[2]; +
- +
-        } else { +
-          return frm; +
-        } +
-      } +
-    } +
- +
-    if (y.length < 4 ) {y = '19'+y;+
-    if (m.length == 1) {m = '0'+m;+
-    if (d.length == 1) {d = '0'+d;+
- +
-    if (typeof mtch[4] != 'undefined') { t =  mtch[4]; } else { t = '';+
- +
-    return y+m+d+t; +
-  }, +
- +
- +
-  shaker_sort: function(list, comp_func) { +
-    /* A stable sort function to allow multi-level sorting of data +
-       see: http://en.wikipedia.org/wiki/Cocktail_sort +
-       thanks to Joseph Nahmias +
-    */ +
-    var b = 0; +
-    var t = list.length - 1; +
-    var swap = true; +
- +
-    while(swap) { +
-        swap = false; +
-        for(var i = b; i < t; ++i) { +
-            if ( comp_func(list[i], list[i+1]) > 0 ) { +
-                var q = list[i]; list[i] = list[i+1]; list[i+1] = q; +
-                swap = true; +
-            } +
-        } // for +
-        t--; +
- +
-        if (!swap) {break;} +
- +
-        for(var i = t; i > b; --i) { +
-            if ( comp_func(list[i], list[i-1]) < 0 ) { +
-                var q = list[i]; list[i] = list[i-1]; list[i-1] = q; +
-                swap = true; +
-            } +
-        } // for +
-        b++; +
- +
-    } // while(swap) +
-  } +
- +
- +
-}; +
- +
- +
-/* ****************************************************************** +
-   Supporting functions: bundled here to avoid depending on a library +
-   ****************************************************************** */ +
- +
-// Dean Edwards/Matthias Miller/John Resig +
- +
- +
-// Dean's forEach: http://dean.edwards.name/base/forEach.js +
-/* +
-  forEach, version 1.0 +
-  Copyright 2006, Dean Edwards +
-  License: http://www.opensource.org/licenses/mit-license.php +
-*/ +
- +
-// array-like enumeration +
-if (!Array.forEach) { // mozilla already supports this +
-  Array.forEach = function(array, block, context) { +
-    for (var i = 0; i < array.length; i++) { +
-      block.call(context, array[i], i, array); +
-    } +
-  }; +
-+
- +
-// generic enumeration +
-Function.prototype.forEach = function(object, block, context) { +
-  for (var key in object) { +
-    if (typeof this.prototype[key] == "undefined") { +
-      block.call(context, object[key], key, object); +
-    } +
-  } +
-}; +
- +
-// character enumeration +
-String.forEach = function(string, block, context) { +
-  Array.forEach(string.split(""), function(chr, index) { +
-    block.call(context, chr, index, string); +
-  }); +
-}; +
- +
-// globally resolve forEach enumeration +
-var forEach = function(object, block, context) { +
-  if (object) { +
-    var resolve = Object; // default +
-    if (object instanceof Function) { +
-      // functions have a "length" property +
-      resolve = Function; +
-    } else if (object.forEach instanceof Function) { +
-      // the object implements a custom forEach method so use that +
-      object.forEach(block, context); +
-      return; +
-    } else if (typeof object == "string") { +
-      // the object is a string +
-      resolve = String; +
-    } else if (typeof object.length == "number") { +
-      // the object is array-like +
-      resolve = Array; +
-    } +
-    resolve.forEach(object, block, context); +
-  } +
-}; +
- +
- +
-if ('undefined' != typeof(window.addEvent)) { +
-    window.addEvent(window, 'load', sorttable.init); +
-}; +
- +
-//sorttable.init; +
- +
-function reinitsort() { +
-  sorttable.reinit(); +
-}; +
-</file> +
- +
-==== Fork: a switch to Tablesorter ==== +
- +
-I have rejigged this to use Christian Bach's Tablesorter jQuery plugin instead of Stuart Langridge's sorttable script.  I have not yet made it compatible with the sortablejs options, but it is functioning and installable for basic functionality.  See https://github.com/samwilson/dokuwiki_sortablejs for details, or [[https://github.com/samwilson/dokuwiki_sortablejs/zipball/master|isntall it]] via the plugin manager.  If this is of any use/interest to anyone, let me know and I'll improve the backwards compatibility.  Thanks!  --- [[user>samwilson|Sam Wilson]] //2013/01/31 09:02// +
- +
-> Great. I looked that option some time ago, but never got the time for it. It would be great if you can add the compatible options.  --- [[user>oiv|oiv]] //2013/01/31 10:19// +
-> Nothing to add other than Thank you! Your work is appreciated. I hope this isn't removed as I believe it won't hurt to acknowledge great work. - Dexter //2013/05/29 10:59// +
- +
->> Ok, I've had a go at adding options.  See what you think.  I've only added the basic initial-sort options, because it seems that Tablesorter automatically detects datatypes and sorts accordingly (I'm not sure how robust this is in terms of dates though; we may want to look closer).  Also, Tablesorter defaults to 100% wide tables, so I've overridden this to ''width:auto'', but there may be other bits of the default style that should be changed. I have added (a widely used but non-official fork of) [[http://mottie.github.com/tablesorter/docs/|tablesorter]] as a submodule, for ease of updating. +
->> Still to do: Permit changing themes (perhaps ''theme=blue'' etc.)... but really, should this be left up to the template? +
->> --- [[user>samwilson|Sam Wilson]] //2013-02-08 00:31 UTC// +
->> Update: here's a tarball, including the submodule (because Github doesn't do that): http://wiki.samwilson.id.au/_media/dokuwiki/sortablejs_2013-02-08.tgz +
->> --- [[user>samwilson|Sam Wilson]] //2013-02-08 02:44 UTC// +
->> Works with Weatherwax. Thanks for the fork. Michael //2013-06-27// +
- +
-=== Date sort? === +
- +
-Hi Sam, thanks for this version which works under Release 2013-03-06 "Weatherwax RC1".\\  +
-The original version is not working.\\  +
-Does it support sort of dates in format dd.mm.yyyy hh:mm ? I tried but seems not to work. <sub>//Joe, 08.05.2013//</sub> +
-==== AlphaNumeric sort? ==== +
- +
-First, thanks for the plugin -- it works great so far ;) +
- +
-One problem I have: I need to sort a table which has entries like ['doc.1', 'doc.2', ...] -- 'alpha' and 'numeric' both don't work, not surprisingly -- but there is no 'alphanumeric' option either.  Any suggestion?  One option would be to allow the 'numeric' case to ignore leading non-numeric characters, I guess.. +
- +
-Thanks! :-) +
- +
---- Andre //2013-03-11 22:27 CEST// +
- +
-====Weatherwax==== +
- +
-Don't works with 2013-05-10 "Weatherwax", or? +
- +
-> The [[https://www.dokuwiki.org/plugin:sortablejs#forka_switch_to_tablesorter|fork ]] mentioned above works for me <sub>//Joe, 2013-05-26//</sub> +
- +
->> New version 2.6 should work with WeatherWax now +
- +
-=== Possible JavaScript issue? === +
- +
- +
-Unfortunatelly, the 2.6 doesn't work with my Weatherwax :( - any chances to debug the problem? /filips/ \\ +
-UPDATE: On the error console I get: \\  +
-''ReferenceError: addInitEvent is not defined'' \\ +
-''...lib/exe/js.php?tseed=...'' \\  +
-please also see this forum thread: https://forum.dokuwiki.org/post/40284 /filips/ +
-> Just tried a fresh install of Weatherwax + sortablejs 2.6 and works for me. The error you are getting is exactly the one I fixed for this to work in Weatherwax. Are you sure you have the latest sortablejs? If you look the script.js file it should have the following lines near the end. +
-  if ('undefined' != typeof(window.addEvent)) { +
-  window.addEvent(window, 'load', sorttable.init); +
-  } else { +
-  jQuery(function() { +
-  sorttable.init(); +
-  }); +
-  }  +
- +
->> Yes, I have the newest sortablejs - I've tried withe manual update as well as update from control panel. The end of ''script.js'' looks exactly as above. Any idea how to debug? md5 hashes of my files: +
-  d17afd8e5222e610464ac1fe8051cd63  script.js +
-  88ba7f72338ef8786e82ef91ae917b2f  syntax.php +
->>> Set css and js comperssion to off. Then you chould see the exact line where the error hits. It may be another plugin.  --- [[user>oiv|oiv]] //2013/09/09 13:14// +
->>>> YES! it was an **"INCLUDE" and "INDEXMENU" plugisn** which caused this error. After upgrading this plugin, all works fine. Thanks! /filips/ +
- +
-=== Exclude line from sorting === +
- +
-Is there a possiblity to avoid single lines from beeing sorted (i.e. a sum line a the end of the table)? --- Mark Buss //2014/04/23 6:12// +
-> I would also love to see this --- Markus Napp //2014/05/28// +
->> in 2.9  --- [[user>oiv|oiv]] //2014-08-14 18:10// +
- +
->>>The sumrow limiter only accepts one digit. Could you fix it, so that larger amounts of sum rows than 9 can be excluded from being sorted? Thanks --- Rob //2015-05-16 16:49// +
- +
-=== Exclude multiple lines from sorting === +
-In some of my tables I have several rows (using tablecalc) like averages, sums and rounded values. Is it possible to specify the number of rows that are excluded? e.g. ''sumrow=3'' (last three lines ommitted?) \\ +
---- Markus Napp //2014/06/03// +
-> Done in 2.9  --- [[user>oiv|oiv]] //2014-08-14 18:10// +
- +
-=== Have a third "return to default" state === +
-Once you have sorted a table the only way to get it back to the original order (as coded in the wiki syntax) is to reload the page as far as I can tell. It would be preferrable to have the table revert to it's default state on the third click. \\ +
---- Markus Napp //2014/06/03// +
-> Please update to 2.9  --- [[user>oiv|oiv]] //2014-08-14 18:10//+
  
-=== Have a third "return to default" state === +  * Historical versions: https://github.com/FyiurAmron/sortablejs/wiki/older-versions 
-Would it be possible have an option to make all tables sortable within the wiki without extra tagging? I could live without all the options, but overwriting the default sort by setting a tag with options for a special table would be an extra bonus --- [[user>konus|konus]] //2015-03-06 08:44// +  * GitHub revision history: https://github.com/FyiurAmron/sortablejs/commits/master 
-=== Not compatible with plugin todo === +  * Historical bugs/ehnancementshttps://github.com/FyiurAmron/sortablejs/wiki/old-issues-and-enhancement-requests 
-The plugin isn't compatible with "todo" entries as <code><todo@stefan start:2015-07-15 due:2016-06-16>TestTable</todo></code> in a table.\\ It seems that the plug-in misinterpret the </> signs. <sortable> isn't visible, but function don't sort. Plugin [[plugin:todo|]].+  * current issue tracker: https://github.com/FyiurAmron/sortablejs/issues
plugin/sortablejs.txt · Last modified: 2024-02-08 09:11 by LMS23

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki