From 1c150f5e73ee02ccd7a52d79f1ab5a655afeb811 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 --- 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 4c048424ceb..3c3c14aac0d 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.25.1