@@ -, +, @@
page
- In the DataTables config:
{ "sType": "title-numeric" },
- In the table data
[% formatted currency %]
on the amount, ordered, spent, or avail columns results in incorrect
sorting that is either ASCII-betical or which ignores any component
of large numbers that occur after the thousands separator.
errors appear in the JS debug console of your choice.
---
acqui/acqui-home.pl | 2 +-
koha-tmpl/intranet-tmpl/prog/en/js/datatables.js | 30 +++++++++++++++++++-
.../prog/en/modules/acqui/acqui-home.tt | 16 +++++------
3 files changed, 38 insertions(+), 10 deletions(-)
--- a/acqui/acqui-home.pl
+++ a/acqui/acqui-home.pl
@@ -135,7 +135,7 @@ foreach my $budget ( @{$budget_arr} ) {
}
for my $field (qw( budget_amount budget_spent budget_ordered budget_avail ) ) {
- $budget->{$field} = $num_formatter->format_price( $budget->{$field} );
+ $budget->{"formatted_$field"} = $num_formatter->format_price( $budget->{$field} );
}
push @budget_loop, $budget;
--- a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
+++ a/koha-tmpl/intranet-tmpl/prog/en/js/datatables.js
@@ -495,6 +495,34 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
}
} );
+
+/* Plugin to allow sorting on numeric data stored in a span's title attribute
+ *
+ * Ex:
+ * [% formatted currency %]
+ * |
+ *
+ * In DataTables config:
+ * "aoColumns": [
+ * { "sType": "title-numeric" },
+ * ]
+ * http://datatables.net/plug-ins/sorting#hidden_title
+ */
+jQuery.extend( jQuery.fn.dataTableExt.oSort, {
+ "title-numeric-pre": function ( 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
@@ -537,4 +565,4 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
}
});
-}());
+}());
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/acqui-home.tt
@@ -32,10 +32,10 @@ $(document).ready(function() {
null,
null,
null,
- null,
- { "sType": "num-html" },
- { "sType": "num-html" },
- null
+ { "sType": "title-numeric" },
+ { "sType": "title-numeric" },
+ { "sType": "title-numeric" },
+ { "sType": "title-numeric" }
],
'sDom': 't',
'bPaginate': false,
@@ -154,10 +154,10 @@ $(document).ready(function() {
[% END %]
[% loop_budge.budget_branchname %] |
- [% loop_budge.budget_amount %] |
- [% loop_budge.budget_ordered %] |
- [% loop_budge.budget_spent %] |
- [% loop_budge.budget_avail %] |
+ [% loop_budge.formatted_budget_amount %] |
+ [% loop_budge.formatted_budget_ordered %] |
+ [% loop_budge.formatted_budget_spent %] |
+ [% loop_budge.formatted_budget_avail %] |
[% ELSE %]
--