From f9a94c160f8bc9dfaca32c014f0567054e94afc9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 3 Jan 2023 18:00:13 +0100 Subject: [PATCH] Bug 32559: Add support for formatted date when filtering on a column When dates are displayed formatted (following the dateformat syspref) in a DataTable table and that there is a filter for the column, we should filter correctly the data. Test plan: Assuming dateformat is set to metric Go to the main patron search, search for all patrons (don't provide a search term) In the "date of birth" column filter, enter "1958", notice that you see Henry Search using an iso formatted date 1958-05-30 Search using a metric formatted date 30/05/1958 Note that: - it's also working for "Expires on" on the same table. We may want to adjust other tables that are using the DT REST API wrapper and the column filters - You need to search for the full formatted date to make it work. "30/05" won't work. Signed-off-by: Lucas Gass --- .../prog/en/includes/patron-search.inc | 4 +-- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 25 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc index b5794d02e66..7350fdbce46 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -150,14 +150,14 @@ [% SWITCH column %] [% CASE 'checkbox' %] [% CASE 'cardnumber' %]Card - [% CASE 'dateofbirth' %]Date of birth + [% CASE 'dateofbirth' %]Date of birth [% CASE 'name' %]Name [% CASE 'name-address' %]Name [% CASE 'address' %]Address [% CASE 'address-library' %]Address [% CASE 'branch' %]Library [% CASE 'category' %]Category - [% CASE 'dateexpiry' %]Expires on + [% CASE 'dateexpiry' %]Expires on [% CASE 'borrowernotes' %]Notes [% CASE 'phone' %]Phone [% CASE 'checkouts' %]Checkouts diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 0fbb9b625cb..2a6e45144a4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -597,9 +597,28 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { // escape SQL LIKE special characters % and _ value = value.replace(/(\%|\\)/g, "\\$1"); } - part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact' - ? value - : {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; + + let built_value; + if ( col.datatype !== undefined ) { + if ( col.datatype == 'date' ) { + let rfc3339 = $date_to_rfc3339(value); + if ( rfc3339 != 'Invalid Date' ) { + built_value = rfc3339; + } + } else { + console.log("datatype %s not supported yet".format(col.datatype)); + } + } + + let value_part; + if ( criteria === 'exact' ) { + value_part = built_value ? [value, built_value] : value + } else { + let like = {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')}; + value_part = built_value ? [like, built_value] : like; + } + + part[!attr.includes('.')?'me.'+attr:attr] = value_part; parts.push(part); } return parts; -- 2.30.2