From 4e3b209a0d6b6adecfd5ce3107f416bd581b8aaf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 7 Jul 2023 15:11:44 +0200 Subject: [PATCH] Bug 34226: DT wrapper - pre-processed date term when filtering If we have filters on top of column on a table that is using the DT REST API wrapper, we cannot filter on date using formatted dates. This was done for "date of birth" for bug 32505. Here we want to provide a generic approach. Note that we cannot use what has been done on bug 22440 in some cases (when we don't write the thead DOM directly but rely on DataTables constructor, for instance bug 33568). The data- attributes are not passed by DT. Test plan: On top of 33568, filter date columns using the full version of the formatted date Signed-off-by: Lucas Gass Signed-off-by: Kyle M Hall Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- koha-tmpl/intranet-tmpl/prog/js/datatables.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index 8d79a44253..9ee051d282 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -562,12 +562,11 @@ function _dt_default_ajax (params){ } let built_value; + let is_date_field; + if ( col.datatype !== undefined ) { if ( col.datatype == 'date' ) { - let rfc3339 = $date_to_rfc3339(value); - if ( rfc3339 != 'Invalid Date' ) { - built_value = rfc3339; - } + is_date_field = true; } else if (col.datatype == 'related-object') { let query_term = value; @@ -583,6 +582,15 @@ function _dt_default_ajax (params){ } else { console.log("datatype %s not supported yet".format(col.datatype)); } + } else if (col.data && ( col.data.endsWith('_on') || col.data.endsWith('_date') ) ) { + is_date_field = true; + } + + if ( is_date_field ) { + let rfc3339 = $date_to_rfc3339(value); + if ( rfc3339 != 'Invalid Date' ) { + built_value = rfc3339; + } } if (col.datatype != 'related-object') { -- 2.39.5