From d2ce611bf60b919347de69bd3f9cb43f3bb1caab Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 2 Oct 2015 09:25:18 +0200 Subject: [PATCH] Bug 14940: Fix sorting in opac-topissues.pl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There is hidden text in "Checkouts" cells that prevent DataTables to sort numerically. This patch adds the 'title-numeric' sort plugin and use it in opac-topissues.pl Column 'Checkouts' in Home > Most popular items sorts as expected Signed-off-by: Marc Véron Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 2f0e409f471fe4527defee41798a80b1e354ce3e) Signed-off-by: Chris Cormack (cherry picked from commit e14557ecd97aa46adb4739b0a5cc3e70b5023616) Signed-off-by: Liz Rea --- .../bootstrap/en/modules/opac-topissues.tt | 4 +-- .../opac-tmpl/bootstrap/js/datatables.js | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt index d7050548f3..9e48ed472d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-topissues.tt @@ -86,7 +86,7 @@ [% results_loo.description %] [% END %] - Checkouts: [% results_loo.tot %] + Checkouts: [% results_loo.tot %] [% IF Koha.Preference( 'opacuserlogin' ) == 1 %][% IF Koha.Preference( 'RequestOnOpac' ) == 1 %][% UNLESS ( results_loo.norequests ) %]Place hold[% END %][% END %][% END %] [% END %] @@ -172,7 +172,7 @@ "aoColumns": [ { "sType": "anti-the" }, null, - null, + { "sType": "title-numeric" }, [% IF ( opacuserlogin ) %]null,[% END %] ] })); diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js index 5f0892d05c..a4c64a2993 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/datatables.js @@ -55,6 +55,32 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, { } } ); +/* Plugin to allow sorting numerically on data stored in a span's title attribute + * + * Ex: Total: [% total %] + * + * In DataTables config: + * "aoColumns": [ + * { "sType": "title-numeric" } + * ] + * http://legacy.datatables.net/plug-ins/sorting#hidden_title + */ +jQuery.extend( jQuery.fn.dataTableExt.oSort, { + "title-numeric-pre": function ( a ) { + console.log(a); + var x = a.match(/title="*(-?[0-9\.]+)/)[1]; + return parseFloat( x ); + }, + + "title-numeric-asc": function ( a, b ) { + return ((a < b) ? -1 : ((a > b) ? 1 : 0)); + }, + + "title-numeric-desc": function ( a, b ) { + return ((a < b) ? 1 : ((a > b) ? -1 : 0)); + } +} ); + (function() { /* Plugin to allow text sorting to ignore articles -- 2.39.5