From 3772e6f210f55ced4a26bff08f942f21429b4de1 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 13 Nov 2009 13:31:30 +0000 Subject: [PATCH] two new classes for sorting --- plekit/php/table.php | 1 + plekit/table/table.css | 2 + plekit/tablesort/plc_customsort.js | 68 ++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 plekit/tablesort/plc_customsort.js diff --git a/plekit/php/table.php b/plekit/php/table.php index e5e74ea..480bd8b 100644 --- a/plekit/php/table.php +++ b/plekit/php/table.php @@ -7,6 +7,7 @@ require_once 'prototype.php'; drupal_set_html_head(' + diff --git a/plekit/table/table.css b/plekit/table/table.css index 1ba1fe6..cb38819 100644 --- a/plekit/table/table.css +++ b/plekit/table/table.css @@ -64,6 +64,8 @@ th.sortable-sortFileSize, th.sortable-sortBandwidth, th.sortable-sortLastContact, th.sortable-sortAlphaNumeric, +th.sortable-sortAlphaNumericTop, +th.sortable-sortAlphaNumericBottom, th.sortable-sortEnglishDateTime { cursor:pointer; background: #CAE8EA url(/plekit/icons/tablesort-header-sortable.jpg) no-repeat; diff --git a/plekit/tablesort/plc_customsort.js b/plekit/tablesort/plc_customsort.js new file mode 100644 index 0000000..62ba8bb --- /dev/null +++ b/plekit/tablesort/plc_customsort.js @@ -0,0 +1,68 @@ +/* $Id$ */ +/* + sortAlphaNumeric{Top,Bottom} + ----------------------- + + These functions are derived from sortAlphaNumeric + inputs are expected to be alphaNumeric values e.g. 1, e, 1a, -23c, 54z + + when comparing two values, the following happens + (*) if both have a numeric part, then they are compared; if equal the non-numeric part is used + (*) if only one has a numeric part, then + . with sortAlphaNumericTop, the non-numeric value (typically n/a) happens first + . with sortAlphaNumericBottom, the non-numeric value (typically n/a) happens second +*/ +function _sortAlphaNumericPrepareData(tdNode, innerText){ + var aa = innerText.toLowerCase().replace(" ", ""); + var reg = /((\-|\+)?(\s+)?[0-9]+\.([0-9]+)?|(\-|\+)?(\s+)?(\.)?[0-9]+)([a-z]+)/; + + if(reg.test(aa)) { + var aaP = aa.match(reg); + return [aaP[1], aaP[8]]; + }; + + // Return an array + return isNaN(aa) ? ["",aa] : [aa,""]; +} + +/* non_numeric_first : + when comparing, say, '12' with 'n/a': + if non_numeric_first is true, we return 1 (n/a greater than 12) + otherwise we return -1 +*/ +function _sortAlphaNumeric(a, b, non_numeric_first) { + // Get the previously prepared array + var aa = a[fdTableSort.pos]; + var bb = b[fdTableSort.pos]; + + // Check numeric parts if not equal + if(aa[0] != bb[0]) { + // both are numeric and have different numeric parts : usual comparison + if(aa[0] != "" && bb[0] != "") { return aa[0] - bb[0]; }; + // one numeric value is missing + if(aa[0] == "" && bb[0] != "") + return non_numeric_first ? -1 : 1 ; + else + return non_numeric_first ? 1 : -1 ; + // from here and on, aa[0] == bb[0] + } else if (aa[1] == bb[1]) { + return 0; + // the alpha part differ + } else { + return (aa[1]