From f980f54225a42a8ff814c86c1af315faa7e71638 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 24 Jul 2023 11:14:31 +0100 Subject: [PATCH] Bug 34226: WIP Using 'type' at the datatable config level What about using 'type' definitions at the datatables settings level and binding that to a flatpickr instance? --- .../prog/en/includes/patron-search.inc | 3 +++ koha-tmpl/intranet-tmpl/prog/js/datatables.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) 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 3c1ce6fe2c..34502bcce7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc @@ -242,6 +242,7 @@ [% INCLUDE 'datatables.inc' %] + [% INCLUDE 'calendar.inc' %] [% INCLUDE 'js-patron-get-age.inc' %] [% INCLUDE 'js-patron-format.inc' %] [% INCLUDE 'js-patron-format-address.inc' %] @@ -430,6 +431,7 @@ [% CASE 'dateofbirth' %] { "data": "date_of_birth", + "type": "date", "searchable": true, "orderable": true, "render": function( data, type, row, meta ) { @@ -551,6 +553,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 9ee051d282..49fe7a5dd4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/datatables.js +++ b/koha-tmpl/intranet-tmpl/prog/js/datatables.js @@ -564,6 +564,10 @@ function _dt_default_ajax (params){ let built_value; let is_date_field; + if ( col.type == 'date' ) { + is_date_field = true; + } + if ( col.datatype !== undefined ) { if ( col.datatype == 'date' ) { is_date_field = true; @@ -893,6 +897,14 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { o.appendTo(select); }); $(this).html( select ); + } else if (table_dt.settings()[0].aoColumns[i].sType == 'date' ) { + let existing_search = table_dt.column(i).search(); + let input = $(''); + if (existing_search) { + input.prop("value", existing_search); + } + + $(this).html( input ); } else { var title = $(this).text(); var existing_search = table_dt.column(i).search(); @@ -923,6 +935,10 @@ function _dt_add_filters(table_node, table_dt, filters_options = {}) { $(this).html(''); } } ); + + $(".flatpickr").each(function(){ + apply_flatpickr(this); + }); } -- 2.41.0