From ceb5948016772a5e31202055e26fe3a8b0bcbad9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 21 Oct 2021 18:00:57 +0100 Subject: [PATCH] Bug 32559: [ALT] Use column 'type' to pre-process search patterns This patch adds the option to pass 'type' at the 'column' definition level and then binds on that type to add date parsing to queries. --- .../prog/en/includes/patron-search.inc | 2 + koha-tmpl/intranet-tmpl/prog/js/datatables.js | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 16 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 4f24c88338..81665398c2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -430,6 +430,7 @@ [% CASE 'dateofbirth' %] { "data": "date_of_birth", + "type": "date", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { @@ -551,6 +552,7 @@ [% CASE 'dateexpiry' %] { "data": "expiry_date", + "type": "date", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { diff --git a/koha-tmpl/intranet-tmpl/prog/js/datatables.js b/koha-tmpl/intranet-tmpl/prog/js/datatables.js index f309e794bb..a741ffff5a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -562,14 +562,16 @@ function _dt_default_ajax (params){ } let built_value; - if ( col.datatype !== undefined ) { - if ( col.datatype == 'date' ) { - let rfc3339 = $date_to_rfc3339(value); - if ( rfc3339 != 'Invalid Date' ) { - built_value = rfc3339; - } + let type = col.type; + if ( type === 'date' ) { + let rfc3339 = $date_to_rfc3339(value); + if ( rfc3339 != 'Invalid Date' ) { + built_value = rfc3339; } - else if (col.datatype == 'related-object') { + } + + if ( col.datatype !== undefined ) { + if (col.datatype == 'related-object') { let query_term = value; if (criteria != 'exact') { @@ -926,15 +928,18 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { /** * Create a new dataTables instance that uses the Koha RESTful API's as a data source - * @param {Object} options Please see the dataTables documentation for further details - * We extend the options set with the `criteria` key which allows - * the developer to select the match type to be applied during searches - * Valid keys are: `contains`, `starts_with`, `ends_with` and `exact` - * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function available - * from the columns_settings template toolkit include - * @param {Boolean} add_filters Add a filters row as the top row of the table - * @param {Object} default_filters Add a set of default search filters to apply at table initialisation - * @return {Object} The dataTables instance + * @param {Object} options Please see the dataTables settings documentation for further + * details + * @param {string} [options.criteria=contains] A koha specific extension to the dataTables settings block that + * allows setting the 'comparison operator' used in searches + * Supports `contains`, `starts_with`, `ends_with` and `exact` match + * @param {string} [options.columns.*.type Data type the field is stored in so we may impose some additional + * manipulation to search strings. Supported types are currenlty 'date' + * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function + * available from the columns_settings template toolkit include + * @param {Boolean} add_filters Add a filters row as the top row of the table + * @param {Object} default_filters Add a set of default search filters to apply at table initialisation + * @return {Object} The dataTables instance */ $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) { var settings = null; -- 2.41.0