@@ -, +, @@ DataTables sorting --- .../prog/en/includes/datatables-strings.inc | 1 + koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 46 +++++++++++++++++++++- .../prog/en/modules/members/readingrec.tt | 15 ++++++- 3 files changed, 60 insertions(+), 2 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc @@ -13,5 +13,6 @@ var MSG_DT_PROCESSING = _("Processing..."); var MSG_DT_SEARCH = _("Search:"); var MSG_DT_ZERO_RECORDS = _("No matching records found"); + var CONFIG_EXCLUDE_ARTICLES_FROM_SORT = _("a an the"); //]]> --- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js +++ a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js @@ -493,4 +493,48 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { "title-string-desc": function ( a, b ) { return ((a < b) ? 1 : ((a > b) ? -1 : 0)); } -} ); +} ); + +(function() { + + /* Plugin to allow text sorting to ignore articles + * + * In DataTables config: + * "aoColumns": [ + * { "sType": "anti-the" }, + * ] + * Based on the plugin found here: + * http://datatables.net/plug-ins/sorting#anti_the + * Modified to exclude HTML tags from sorting + * Extended to accept a string of space-separated articles + * from a configuration file (in English, "a," "an," and "the") + */ + + if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){ + var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" "); + var rpattern = ""; + for(i=0;i/g, "" ); + var y = x.trim(); + var z = y.replace(re, "").toLowerCase(); + return z; + }, + + "anti-the-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "anti-the-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } + }); + +}()); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -8,13 +8,26 @@