Bugzilla – Attachment 19463 Details for
Bug 5766
Add configuration for excluding articles from jQuery table sorter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 5766 - Add configuration for excluding articles from DataTables sorting
PASSED-QA-Bug-5766---Add-configuration-for-excludi.patch (text/plain), 4.73 KB, created by
Katrin Fischer
on 2013-07-08 05:59:51 UTC
(
hide
)
Description:
[PASSED QA] Bug 5766 - Add configuration for excluding articles from DataTables sorting
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2013-07-08 05:59:51 UTC
Size:
4.73 KB
patch
obsolete
>From e105d8a0d675877bd1fb2c6f0e6fe45139325429 Mon Sep 17 00:00:00 2001 >From: Owen Leonard <oleonard@myacpl.org> >Date: Fri, 26 Apr 2013 16:18:05 -0400 >Subject: [PATCH] [PASSED QA] Bug 5766 - Add configuration for excluding > articles from DataTables sorting > >Client-side table sorting should exclude articles like "a," "an," and >"the" when sorting by title. This patch adds a custom sorting plugin for >use by DataTables and a configuration line to the DataTables string >configuration file which can be translated for any language. > >As an example, this patch modifies the patron checkout history template >to use the new sort on the title column. > >To test, apply the patch and clear your browser cache to ensure the >revised JavaScript file is loaded. Sort the table by title. Titles >should be sorted regardless of the presences of "a," "an", or "the" at >the beginning of the title. > >Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz> >Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> >Passes all tests and is a good improvement. >I have added German articles to the list for testing purposes >and it worked nicely. >--- > .../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(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc >index 183f511..7e939fc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/datatables-strings.inc >+++ b/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"); > //]]> > </script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js >index 703944e..fc24036 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js >+++ b/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)); > } >-} ); >\ No newline at end of file >+} ); >+ >+(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<articles.length;i++){ >+ rpattern += "^" + articles[i] + " "; >+ if(i < articles.length - 1){ rpattern += "|"; } >+ } >+ var re = new RegExp(rpattern, "i"); >+ } >+ >+ jQuery.extend( jQuery.fn.dataTableExt.oSort, { >+ "anti-the-pre": function ( a ) { >+ var x = String(a).replace( /<[\s\S]*?>/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)); >+ } >+ }); >+ >+}()); >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt >index 6084357..f488234 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt >@@ -8,13 +8,26 @@ > <script type="text/javascript" src="[% interface %]/[% theme %]/en/js/datatables.js"></script> > <script type="text/javascript" id="js"> > //<![CDATA[ >+ > $(document).ready(function() { > [% IF (dateformat == 'metric') %] > dt_add_type_uk_date(); > [% END %] > $("#table_readingrec").dataTable($.extend(true, {}, dataTablesDefaults, { > "sPaginationType": "four_button", >- "aaSorting": [] >+ "aaSorting": [], >+ "aoColumns": [ >+ null, >+ { "sType": "anti-the" }, >+ null, >+ null, >+ null, >+ null, >+ null, >+ null, >+ null, >+ null >+ ] > })); > }); > //]]> >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 5766
:
19380
|
19438
| 19463